Enigmatic Code

Programming Enigma Puzzles

Enigma 1673: Just one

From New Scientist #2839, 19th November 2011 [link]

By placing the digits 1 to 9 in the boxes of a 3×3 grid, you create three three-figure numbers across the rows and three down the columns. Choose the positions of the digits so that, of those six three-figure numbers, just one is divisible by 2, just one is divisible by 3, just one is divisible by 5, just one is divisible by 6, just one is divisible by 8, just one is divisible by 9, one differs from a perfect square by just 1, and one differs from a perfect cube by just 1.

What are the smallest and biggest of your six three-figure numbers?

[enigma1673]

Advertisements

5 responses to “Enigma 1673: Just one

  1. Jim Randell 30 November 2011 at 4:27 pm

    A straightforward approach (in Python), yields a solution which runs in 860ms.

    from itertools import permutations
    from enigma import irange, is_square, is_cube
    
    for (A, B, C, D, E, F, G, H, I) in permutations(irange(1, 9), 9):
      if not(B < D): continue # for uniqueness
    
      ABC = 100*A + 10*B + C
      DEF = 100*D + 10*E + F
      GHI = 100*G + 10*H + I
      ADG = 100*A + 10*D + G
      BEH = 100*B + 10*E + H
      CFI = 100*C + 10*F + I
    
      s = list((ABC, DEF, GHI, ADG, BEH, CFI))
    
      if len(set(x for x in s if x % 2 == 0)) != 1: continue
      if len(set(x for x in s if x % 3 == 0)) != 1: continue
      if len(set(x for x in s if x % 5 == 0)) != 1: continue
      if len(set(x for x in s if x % 6 == 0)) != 1: continue
      if len(set(x for x in s if x % 8 == 0)) != 1: continue
      if len(set(x for x in s if x % 9 == 0)) != 1: continue
    
      if len(set(x for x in s if is_square(x + 1) or is_square(x - 1))) == 0: continue
      if len(set(x for x in s if is_cube(x + 1) or is_cube(x - 1))) == 0: continue
    
      print(min(s), max(s), s)
    

    This also uses the is_square() and is_cube() functions from my enigma.py library of useful functions. They check to see if their arguments are a perfect square or perfect cube, respectively.

    Solution: The smallest number is 143. The biggest number is 937.

    • K WARD 16 December 2011 at 10:25 pm

      Dear Jimrandell
      Could you do it with pencil and paper. I did.
      I too had sketched out a program in Basic but thought that that would take the fun of deduction away!
      However, Well done.
      What a pity that you published the answer to a PRIZE competition.
      At least the poster on the NS Forum just gave the difference which showed they had solved it without giving the ANSWER.

      • jimrandell 18 December 2011 at 9:01 am

        You can solve all Enigma puzzles without computer assistance, however this particular site is about sharing and discussing programmatic solutions (see the “About” page for more details). There are other sites on the web that focus on analytical solutions (and they also publish solutions, if you read the comments). And New Scientist itself warns you that the solution may appear in comments on its own site!

  2. k ward 26 December 2011 at 8:03 pm

    Hi jmrandell Thanks for your kind explan of how it all goes
    Could you suggest a blog that focuses on analytical sols
    Hope yve had a good holiday and Kind Regards
    K WARD

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: