Enigmatic Code

Programming Enigma Puzzles

Enigma 1490: Board with squares?

From New Scientist #2652, 19th April 2008

A snakes and ladders board consists of a 10-by-10 grid of squares. In the first row (at the bottom) the squares are numbered from 1 to 10 from left to right. Then in the second row the squares are numbered 11 to 20 from right to left. Then in the third row they are 21 to 30 from left to right again, and so on, ending up at square “100” in the top left-hand corner.

From such a board I have cut out a square-shaped piece consisting precisely of some of its squares, but not including square “1”. The total of all the numbers in my piece is the square of one of the numbers in it.

What is that total?

[enigma1490]

One response to “Enigma 1490: Board with squares?

  1. Jim Randell 20 November 2012 at 1:42 pm

    The following Python program runs in 40ms.

    from itertools import product
    from enigma import irange, flatten, is_square, printf
    
    # construct the board
    b = list(list(irange(10 * i + 1, 10 * (i + 1))) for i in irange(0, 9))
    for i in irange(1, 9, step=2): b[i].reverse()
    
    # one corner of the cut piece
    for (x1, y1) in product(irange(0, 9), irange(0, 9)):
      # and the other corner
      for n in irange(1, min(9 - x1, 9 - y1)):
        (x2, y2) = (x1 + n, y1 + n)
        # what numbers are on the removed square?
        ns = flatten(r[x1:x2] for r in b[y1:y2])
        # it can't include 1
        if 1 in ns: continue
        # sum the numbers
        s = sum(ns)
        # is the sum a square number?
        r = is_square(s)
        if r is None: continue
        # is the root contained in the square?
        if r not in ns: continue
        
        printf("sum={s} = {r}^2 [ns={ns}]")
    

    Solution: The total sum of all the numbers in the cut out square is 225.

    Enigma 1490 - Solution

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: