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

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

On the Subject of Wire Sequences

This challenge is from a game, Keep Talking And Nobody Explodes.

It's hard to say how this mechanism works. The engineering is pretty impressive, but there must have been an easier way to manage nine wires. — from the manual

Input

Exactly 9 "wires", each which is labeled 'A', 'B', or 'C', and is colored red, blue, or black.

Input format and type doesn't matter, as long as they uniquely identify the wires. In particular, the alphabets can be encoded arbitrarily, so can the colors.

Objective and Output

Output the indices of the wires that needs to be cut. The output format and type doesn't matter either, as long as they uniquely identify the wires to be cut.

Which wire to cut?

If the wire has color \$X\$ and it's the \$N\$th wire of that color that you have seen so far, look at the entry of color \$X\$ on row \$N\$ of the table. If and only if the wire's label is listed on that entry, it is to be cut.

$$ \begin{array}{c|ccc} & \text{Red} & \text{Blue} & \text{Black} \\ \hline \text{1st} & \text{C} & \text{B} & \text{A, B, or C} \\ \text{2nd} & \text{B} & \text{A or C} & \text{A or C} \\ \text{3rd} & \text{A} & \text{B} & \text{B} \\ \text{4th} & \text{A or C} & \text{A} & \text{A or C} \\ \text{5th} & \text{B} & \text{B} & \text{B} \\ \text{6th} & \text{A or C} & \text{B or C} & \text{B or C} \\ \text{7th} & \text{A, B, or C} & \text{C} & \text{A or B} \\ \text{8th} & \text{A or B} & \text{A or C} & \text{C} \\ \text{9th} & \text{B} & \text{A} & \text{C} \end{array} $$

Example

Assuming the wires are 1-indexed, and given the following input:

Blue C
Blue C
Black C
Black B
Black A
Red C
Blue C
Black A
Black A

The 1st wire is the 1st blue wire, which is not connected to B, so leave it.
The 2nd wire is the 2nd blue wire, which is connected to A or C, so cut it.
The 3rd wire is the 1st black wire, so cut it.
The 4th wire is the 2nd black wire, which is not connected to A nor C, so leave it.
The 5th wire is the 3rd black wire, which is not connected to B, so leave it.
The 6th wire is the 1st red wire, which is connected to C, so cut it.
The 7th wire is the 3rd blue wire, which is not connected to B, so leave it.
The 8th wire is the 4th black wire, which is connected to A or C, so cut it.
The 9th wire is the 5th black wire, which in not connected to B, so leave it.

So the output is [2,3,6,8].

Answer*

Draft saved
Draft discarded
Cancel

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