Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Card Game by kurosawa4434
def cards(deck, hand):
def check(rest, d=[]):
if not rest:
return True
c, r = rest[0], rest[1:]
return (0 < c <= deck and (c-1, c) not in d and check(r, d+[(c-1, c)])
or
c < deck and (c, c+1) not in d and check(r, d+[(c, c+1)]))
return check(hand)
if __name__ == '__main__':
print("Example:")
print(cards(5, [2, 0, 1, 2]))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert cards(5, [2, 1, 2]) == True
assert cards(51,[29,36,30,42]) == True
assert cards(5, [2, 0, 1, 2]) == False
assert cards(10, [9, 9, 6, 6]) == True
assert cards(10, [11]) == False
print("Coding complete? Click 'Check' to earn cool rewards!")
Sept. 21, 2018