Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Revisions

7 of 8
added 2 characters in body
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

Jelly, (削除) 27 (削除ここまで) 25 bytes

ċṪ$Ƥżḅ3Ʋị"μỵƓṢ4ż]¶:ɼ’ḃ7¤&

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 indicators of whether to cut each wire.

Inputs:

 Red : 1 A : 1
 Blue : 2 B : 2
Black : 3 C : 4

Outputs:

 Cut : non-zero (falsey)
Don't cut : zero (truthy)

Try it online!

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, which yields a list of wire numbers to cut.

How?

ċṪ$Ƥżḅ3Ʋị"...’ḃ7¤& - 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)
 & - (that) bitwise AND with (labels) (vectorises)
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

AltStyle によって変換されたページ (->オリジナル) /