Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
for-else solution in Clear category for Card Game by Sim0000
def cards(deck, hand):
all_card = set((n, n + 1) for n in range(deck))
for n in sorted(hand):
for card in [(n - 1, n), (n, n + 1)]:
if card in all_card:
all_card.remove(card)
break
else:
return False
return True
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, 0, 1, 2]) == False
assert cards(10, [9, 9, 6, 6]) == True
assert cards(10, [11]) == False
assert cards(3, [0, 1, 1]) == False
assert cards(10, [3, 3, 5, 6, 6, 7]) == True
assert cards(8, [4, 4, 5, 6, 7]) == True
assert cards(7, [4, 4, 5, 6, 7]) == False
assert cards(4, [0, 0]) == False
assert cards(4, [2, 2]) == True
assert cards(4, [4, 4]) == False
assert cards(4, [2, 2, 2]) == False
assert cards(4, [1, 1, 2, 2]) == False
assert cards(4, [2, 2, 3, 3]) == False
assert cards(4, [0, 1, 2, 3, 3]) == False
assert cards(4, [1, 1, 2, 3, 4]) == False
assert cards(4, [0, 1, 2, 3, 4]) == False
assert cards(4, [1, 1, 2, 3, 3]) == False
assert cards(10, [1, 1, 2, 3, 4, 5, 6, 7, 7]) == False
print("Coding complete? Click 'Check' to earn cool rewards!")
Sept. 26, 2018