17
1
Introduction
Jonny wants to play Frogger. However, he's not very good. In fact, he will only try to move forward, and only after the platforms have moved.
Find out if Jonny's frog manages to reach the end of the path or if it dies on its way.
Challenge
The program will be receiving as input a Frogger grid composed by 0
s and 1
s, with the following format:
- The grid will be of a random width and length, and at least 3x3
1
represents platforms0
represents waterF
represents the starting position of the frog- Every first and last line of the grid will be composed by only
1
s, and will not move, and the frogF
will be placed at random on the last line - Every intermediate layer will always be moving, and will have a
<
or>
at the end of every line indicating if it moves left or right
Replacing these symbols with your own is allowed, as long as they're all distinct and you specify the replacements in your answer.
The input may be in any compatible format (string with line breaks, array of strings, array of characters, ...).
Challenge Rules
- Every turn, all platforms will move one square, based on the direction indicated by the
<
or>
sign - Platforms reappear on the other side of the grid if they get pushed off "screen"
- If the frog is on a moving platform, it will move along with it
- After that, the frog will jump one square towards the top row. The frog will move every turn.
- The frog dies if it jumps in water (
0
) or it touches the side of the grid along with a moving platform
Your program has to output a truthy value if the frog survives and a falsy value otherwise.
This is code-golf, so the shortest answer in bytes win. Standard loopholes apply.
Examples
Example 1
Input
11111
00111>
00101<
1F111
Output
1
Execution
Turn 1:
11111
10011
01010
1F111
11111
10011
0F010
11111
Turn 2:
11111
11001
F0100
11111
11111
F1001
10100
11111
Turn 3:
11111
1F100
01001
11111
1F111
11100
01001
11111
Example 2
Input
11111
00100<
00100<
1F111
Output
0
Execution
Turn 1:
11111
01000
01000
1F111
11111
01000
0F000
11111
Turn 2:
11111
10000
F0000
11111
11111
F0000
10000
11111
Turn 3:
11111
00001
00001
11111
Will intermediate lines always be moving? Can we take a list of lines as input? If a line is not moving can we assume it ends with a character other than
<
or>
so we can take rectangular arrays as input? By the way, nice challenge! – dylnan – 2018-06-18T15:20:32.230@dylnan I clarified it in the challenge text. Intermediate layers will always be moving and will always have a
<
or>
at the end. – BgrWorker – 2018-06-18T15:23:31.153Does the frog move forward every turn even when there is a
– Kevin Cruijssen – 2018-06-19T07:11:24.2030
in front of it, or will it wait for the next1
? If it can wait, will it go forward on every1
, or can it wait smartly? I.e. with the test case11111 00001< 00011< 11F11
, will it be falsey because it jumps in the water (pastebin of steps); will it be falsey because it moves out of frame (pastebin of steps); or will it be truthy because it waits smartly for the second platform before jumping forward (pastebin of steps)?@KevinCruijssen it moves every turn, and will happily suicide (as I said, Jonny is not a very good player) – BgrWorker – 2018-06-19T07:15:28.953
@BgrWorker Ok, that makes the challenge indeed more doable. :) Maybe edit it in the challenge description, that the frog will move forward every turn, even if it would jump into a
0
. – Kevin Cruijssen – 2018-06-19T07:19:14.907@KevinCruijssen I thought it was implicit with rules 4 and 5. I clarified it in rule 4, thanks. – BgrWorker – 2018-06-19T07:32:07.373
I constantly stalk this forum and this is a really impressive question. I can honestly say that I would have no chance of solving this and I think it's nuts that anyone could even answer it. – zfrisch – 2018-06-19T21:31:34.683