I find only 784 (28^2) meets solution requirements, passing through 1,2,12,22,23,24,25,26,27,28,29,39,49,59,69,79,80,90,100

Lowest scoring route is anticlockwise around perimeter. Each “deviation” exposing a square, worth 9 added each. The white paper squares are not all adjacent..

]]>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# find a path through a 10 by 10 grid, starting at (0, 0) and # ending at (9, 9) with moves that increment either x or y but # not both; return the 'Snakes and Ladders' numbers on the path def solve(x, y, seq): # compute the 'Snakes and Ladders' number from (x, y) n = 10 * y + (10 - x if y % 2 else x + 1) s = seq + (n,) if x == 9 and y == 9: yield s else: if x < 9: yield from solve(x + 1, y, s) if y < 9: yield from solve(x, y + 1, s) # check all valid paths across the board (the first # move is specified) for seq in solve(1, 0, (1,)): # check that the sum of the numbers on the path # is the perfect square of a number it contains sm = sum(seq) sr = int(sm ** 0.5) if sr ** 2 == sm and sr in seq: # check that the path through this number # doesn't change direction ix = seq.index(sr) if seq[ix + 1] - seq[ix - 1] in {2, 20}: print(f'sum = {sm} ({sr}^2) {seq}') |