Created
November 2, 2020 18:07
-
-
Save willy-r/260aefd1008f6cc741088dddea331851 to your computer and use it in GitHub Desktop.
You have a character who jumps forward n number of units at a time, and an array representing the road in front of them (where 0 is a flat piece of road, and 1 is an obstacle). Return true or false if your character can jump to the end without hitting an obstacle in front of them.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def character_jump(jump: int, road: list[int]) -> bool: | |
return 1 not in road[::jump] | |
if __name__ == '__main__': | |
CASES = ( | |
(3, [0, 1, 0, 0, 0, 1, 0], True), | |
(4, [0, 1, 1, 0, 1, 0, 0, 0, 0], False), | |
(4, [0, 0, 0, 0, 0, 0, 0, 1], True), | |
(1, [0, 1, 0, 1, 0, 1], False), | |
) | |
for jump, road, expected in CASES: | |
result = character_jump(jump, road) | |
assert result == expected, f'{result=} != {expected=}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment