Skip to content

Instantly share code, notes, and snippets.

@danieldiekmeier

danieldiekmeier/311.py

Last active Jun 9, 2017
Embed
What would you like to do?
# from https://www.reddit.com/r/dailyprogrammer/comments/65vgkh/20170417_challenge_311_easy_jolly_jumper/
challenges = """4 1 4 2 3
5 1 4 2 -1 6
4 19 22 24 21
4 19 22 24 25
4 2 -1 0 2"""
def solve(challenge):
numbers = [int(x) for x in challenge.split(' ')]
count = numbers[0]
prev = numbers[1] # so we can skip setup later
numbers = numbers[2:]
possible_diffs = list(range(1, count))
for n in numbers:
diff = abs(prev - n)
prev = n
if diff in possible_diffs:
possible_diffs.remove(diff)
else:
return False
return True
def solve_all(challenges):
for challenge in challenges.split('\n'):
jolly = solve(challenge)
if jolly:
print(challenge + ' JOLLY')
else:
print(challenge + ' NOT JOLLY')
solve_all(challenges)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.