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 Answer

edited body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
 Cut : non-zero (falseytruthy)
Don't cut : zero (truthyfalsey)
 Cut : non-zero (falsey)
Don't cut : zero (truthy)
 Cut : non-zero (truthy)
Don't cut : zero (falsey)
added 2 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

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

ċṪ$Ƥżḅ3Ʋị"μỵƓṢ4ż]¶:ɼ’ḃ7¤&Tɼ’ḃ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 wire numbersindicators of whether to cut each wire.

Red 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! Try it online!

Here 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.

ċṪ$Ƥżḅ3Ʋị"...’ḃ7¤&T’ḃ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)
 & - (each of that) bitwise AND with (labels) T - truthy indices(vectorises)

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

ċṪ$Ƥżḅ3Ʋị"μỵƓṢ4ż]¶:ɼ’ḃ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.

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

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.

ċṪ$Ƥżḅ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, (削除) 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.

 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.

ċṪ$Ƥżḅ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)
added 2 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
ċṪ$Ƥżḅ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 indexindexes 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
ċṪ$Ƥżḅ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 index 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
ċṪ$Ƥżḅ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
added 352 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading
added 352 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading
added 25 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading
deleted 22 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293
Loading

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