Code Golf Asked by lightlyheld on October 27, 2021
Imagine a grid where the origin square $(0,0)$ is at the top left of the screen, and positive $x$ is rightwards whereas positive $y$ is downwards. Coloured squares are at various positions on the grid.
In a magical void separate from the grid are multiple snake-like strips of squares, each of a fixed length and a certain colour. Colours may or may not repeat across strips.
Each of our strips can move left, right or forward from the perspective of the head but can obstruct itself. The strips basically move by popping the tail and pushing a new head, as snakes do. They are necessary and sufficient to cover every correspondingly coloured position on the grid without strip overlap.
Sounds dreadful, doesn’t it? It’s as if you need to plan all your moves…!
What moves will solve the grid?
Input
You need only consider grids solvable by the method described in the introduction.
Output
Give the unique identifier of each strip you’re moving, and the sequence of moves it should make:
More than one solution is typically possible. Please choose one.
Possible output types are not limited to associative arrays.
In the sample test cases below, for the sake of example only, W, A, S, D represent up, left, down and right respectively. Also for the sake of example only, these rules are followed:
Input — grid
0010000
0000100
Input — strips
a 1 4
Possible output
a DDDS
Result (strip narrowed for clarity): image link
Input — grid
0010000
0200000
0030100
0002020
0000300
Input — strips
a 1 5
b 2 7
c 3 5
Possible output
a DDDDSS
b SDDDSSDD
c SSDDSSDD
Result (strips narrowed for clarity): image link
Input — grid
0000000
0010120
0030000
0102000
0000000
0000310
0000000
Input — strips
a 1 3
b 1 6
c 2 7
d 3 6
Possible output
b DDDDSSDSSS
c SSSSDDDWWWWDDS
d DDSSSSSDD
a DDSASS
Result (strips narrowed for clarity): image link
Input — grid
000000
010000
000020
030000
020040
040100
000300
000000
Input — strips
a 1 11
b 2 8
c 3 6
d 4 9
Possible output
c SSSDDSSSD
d SSSSSDSSDDDWWW
b DDDDSSAAAASSD
a SDDDDDSSAASS
Result (strips narrowed for clarity): image link
Samples credit: Color Strips on Armor Games
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP