searching piles where player 1 looses solution in Clear category for The Stones by Rapunzel85
def stones(pile, moves):
#holds all possible numbers of stones which you could take from
#we want to eliminate the numbers you win with
#and we want to push the numbers you loos with to loos_at
numbers = list(range(moves+2,pile+1))
#holds the numbers of stones you are loosing with
#this list will be changed in a way, that only the last 'interesting' ones are saved there
loos_at = list(range(1,moves+1))
#idea: You (player 1) win if you can get your opponent (player 2) on a loos number.
#The first loos numbers are every number less or equal to minimal number you are allowed to take.
#The numbers you are winning with are then the numbers, from which you can get to a loos number.
#These are loos numbers added to all the numbers you are allowed to take.
#We will eliminate this winning numbers from list 'numbers'.
#The next number you are loosing with is then the first number you are not able to reach from the old loos number.
#This is the first number in the list 'numbers'.
#You win the game, if the number of stones you can take from (limit) is a winning number. This means that you can take
#a number away to give your opponent a loosing number.
#Your opponent win, if the number you can take from ist a loos number. This means, that your opponent is able
#to take stones away in such a way, that you always have loosing numbers until you have to take the last stone(s).
for loos in loos_at:
for take in moves:
if take+loos > pile:
if loos+take in numbers:
if __name__ == '__main__':
print(stones(17, [1, 3, 4]))
#These "asserts" using only for self-checking and not necessary for auto-testing
assert stones(17, [1, 3, 4]) == 2
assert stones(17, [1, 3, 4, 6, 9]) == 1
assert stones(99, ) == 2
print("Coding complete? Click 'Check' to earn cool rewards!")
April 24, 2019