Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
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[0]+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[0]+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).
while numbers:
for loos in loos_at:
for take in moves:
if take+loos > pile:
continue
elif take+loos==pile:
return 1
else:
if loos+take in numbers:
numbers.pop(numbers.index(loos+take))
loos_at=numbers[0:moves[0]]
numbers[0:moves[0]]=[]
return 2
if __name__ == '__main__':
print("Example:")
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, [1]) == 2
print("Coding complete? Click 'Check' to earn cool rewards!")
April 24, 2019
Comments: