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

clarified use of cyclic indexing of lookup table
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Charcoal, 33 bytes

⭆θ§")∧∨⦃↧dG↓◨h↓WK"⍘+NoE...θκ§λ0§ι0ι3

Try it online! Link is to verbose version of code. Takes input as list of digit + letter pairs where the digit is 2 for Red, 1 for Blue and 0 for Black. Output is a binary string of whether each wire should be cut. Explanation:

 θ Input list
⭆ Map over elements and join
 "..." Compressed binary lookup table
 § IndexedCyclically indexed by
 No Count of
 § 0 First character of
 ι Current entry in
 ... κ Prefix of
 θ Input list
 E Map over entries
 § 0 First character of
 λ Inner entry
 + Concatenated with
 ι Current entry
 ⍘ 3 Interpreted as base 3
 Implicitly print

As an example, the last wire from the example, 0A, is the fifth black wire, therefore there are four wires in the prefix, resulting in a string 40A. This converts as 4 * 9 + 0 * 3 + A, where the letters are decoded using a=10, ... z=35, A=36, ... Z=61, resulting in a final total of 72. The use of uppercase letters here just requires the entire lookup table to be rotated by 36 bits, so it's not necessary to encode the letters.

Charcoal, 33 bytes

⭆θ§")∧∨⦃↧dG↓◨h↓WK"⍘+NoE...θκ§λ0§ι0ι3

Try it online! Link is to verbose version of code. Takes input as list of digit + letter pairs where the digit is 2 for Red, 1 for Blue and 0 for Black. Output is a binary string of whether each wire should be cut. Explanation:

 θ Input list
⭆ Map over elements and join
 "..." Compressed binary lookup table
 § Indexed by
 No Count of
 § 0 First character of
 ι Current entry in
 ... κ Prefix of
 θ Input list
 E Map over entries
 § 0 First character of
 λ Inner entry
 + Concatenated with
 ι Current entry
 ⍘ 3 Interpreted as base 3
 Implicitly print

As an example, the last wire from the example, 0A, is the fifth black wire, therefore there are four wires in the prefix, resulting in a string 40A. This converts as 4 * 9 + 0 * 3 + A, where the letters are decoded using a=10, ... z=35, A=36, ... Z=61, resulting in a final total of 72. The use of uppercase letters here just requires the entire lookup table to be rotated by 36 bits, so it's not necessary to encode the letters.

Charcoal, 33 bytes

⭆θ§")∧∨⦃↧dG↓◨h↓WK"⍘+NoE...θκ§λ0§ι0ι3

Try it online! Link is to verbose version of code. Takes input as list of digit + letter pairs where the digit is 2 for Red, 1 for Blue and 0 for Black. Output is a binary string of whether each wire should be cut. Explanation:

 θ Input list
⭆ Map over elements and join
 "..." Compressed binary lookup table
 § Cyclically indexed by
 No Count of
 § 0 First character of
 ι Current entry in
 ... κ Prefix of
 θ Input list
 E Map over entries
 § 0 First character of
 λ Inner entry
 + Concatenated with
 ι Current entry
 ⍘ 3 Interpreted as base 3
 Implicitly print

As an example, the last wire from the example, 0A, is the fifth black wire, therefore there are four wires in the prefix, resulting in a string 40A. This converts as 4 * 9 + 0 * 3 + A, where the letters are decoded using a=10, ... z=35, A=36, ... Z=61, resulting in a final total of 72. The use of uppercase letters here just requires the entire lookup table to be rotated by 36 bits, so it's not necessary to encode the letters.

Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Charcoal, 33 bytes

⭆θ§")∧∨⦃↧dG↓◨h↓WK"⍘+NoE...θκ§λ0§ι0ι3

Try it online! Link is to verbose version of code. Takes input as list of digit + letter pairs where the digit is 2 for Red, 1 for Blue and 0 for Black. Output is a binary string of whether each wire should be cut. Explanation:

 θ Input list
⭆ Map over elements and join
 "..." Compressed binary lookup table
 § Indexed by
 No Count of
 § 0 First character of
 ι Current entry in
 ... κ Prefix of
 θ Input list
 E Map over entries
 § 0 First character of
 λ Inner entry
 + Concatenated with
 ι Current entry
 ⍘ 3 Interpreted as base 3
 Implicitly print

As an example, the last wire from the example, 0A, is the fifth black wire, therefore there are four wires in the prefix, resulting in a string 40A. This converts as 4 * 9 + 0 * 3 + A, where the letters are decoded using a=10, ... z=35, A=36, ... Z=61, resulting in a final total of 72. The use of uppercase letters here just requires the entire lookup table to be rotated by 36 bits, so it's not necessary to encode the letters.

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