Revision df135623-1d06-4ef1-bc18-c84e2f80318c - Code Golf Stack Exchange
# [Jelly], <s> 27 </s> 26 [bytes]
ċṪ$Ƥżḅ3Ʋị“µỵƓṢ⁴ż]¶:ɼ’ḃ7¤&T
A dyadic Link accepting a list of the wire colours on the left and a list of the wire labels on the right which yields a list of wire numbers to cut.
Inputs:
Red 1 A 1
Blue 2 B 2
Black 3 C 4
**[Try it online!][TIO-keh87s6n]**
[Here] is an easier to use version accepting the colours, `RBK` (red, blue, black), on the first line and the labels, `ABC` on the second line.
### How?
ċṪ$Ƥżḅ3Ʋị“...’ḃ7¤&T - Link: colours, labels
Ʋ - last four links as a monad - f(colours):
Ƥ - for prefixes:
$ - last two links as a monad - f(prefix):
Ṫ - tail -> current wire's colour
ċ - count -> number of such wires seen before
ż - zip with (colours)
3 - three
ḅ - convert (zip result items) from base (3)
X = the indexes to check in the flattened table
¤ - nilad followed by link(s) as a nilad:
“...’ - 41650313607423351764917
7 - seven
ḃ - bijective-base -> [4,2,7,2,5,5,1,2,2,5,1,5,2,2,2,5,6,6,7,4,3,3,5,4,2,1,4]
Y = the flattened table as bitmasks of labels to cut
ị - (each of X) index into (Y)
& - (each of that) bitwise AND with (labels)
T - truthy indices
[Jelly]: https://github.com/DennisMitchell/jelly
[bytes]: https://github.com/DennisMitchell/jelly/wiki/Code-page
[TIO-keh87s6n]: https://tio.run/##y0rNyan8//9I98Odq1SOLTm65@GOVuNjmx7u7n7UMOfQ1oe7tx6b/HDnokeNW47uiT20zerknkcNMx/uaDY/tEQt5P///9FGOgpAZAxDhnBu7P9oEx0FCDICS0DYQIZhLAA "Jelly – Try It Online"
[Here]: https://tio.run/##AWwAk/9qZWxsef//xIvhuaokxqTFvOG4hTPGsuG7i@KAnMK14bu1xpPhuaLigbTFvF3CtjrJvOKAmeG4gzfCpCZU/@G7tOKAnFJCS0PigJ1p4rGu4rGubzHDpy///0JCS0tLUkJLSwpDQ0NCQUNDQUE "Jelly – Try It Online"