Enigmatic Code

Programming Enigma Puzzles

Enigma 524: Spot check

From New Scientist #1676, 5th August 1989 [link]

I’m in the middle of a game of dominoes and I’m looking at the four dominoes laid end-to-end on the table.

If I replace the number of spots by digits and then read off the four-figure number formed by the first two dominoes, I get a perfect square. (For example, had the dominoes been:

Enigma 524

then I’d have read the number 1220).

The four-figure number formed by the middle two dominoes (which would be 2005 in the above example) is a prime.

And the total number of spots on the four dominoes is a perfect square.

What are the four dominoes.

[enigma524]

2 responses to “Enigma 524: Spot check

  1. Jim Randell 4 November 2019 at 7:41 am

    Suppose the dominoes are:

    [A-B] [B-C] [C-D] [D-E]

    Then we can solve the puzzle using the [[ SubstitutedExpression() ]] solver from the enigma.py library.

    The following run file executes in 139ms.

    Run: [ @repl.it ]

    #!/usr/bin/env python -m enigma -r
    
    SubstitutedExpression
    
    --distinct=""
    --digits="0-6"
    
    # the first 2 dominoes form a perfect square
    "is_square(ABBC)"
    
    # the middle 2 dominoes form a prime
    "is_prime(BCCD)"
    
    # the total number of spots is a perfect square
    "is_square(A + B + B + C + C + D + D + E)"
    
    # can't repeat a domino
    "seq_all_different(ordered(*d) for d in [(A, B), (B, C), (C, D), (D, E)])"
    
    # the answer is the 4 dominoes
    --answer="((A, B), (B, C), (C, D), (D, E))"
    

    Solution: The 4 dominoes are: [2-1] [1-6] [6-3] [3-3].

    If we allow duplicate dominoes the following are also solutions:

    [1-4] [4-4] [4-1] [1-6] (repeats the [1-4] domino)
    [4-2] [2-5] [5-1] [1-5] (repeats the [1-5] domino)

  2. GeoffR 4 November 2019 at 11:06 am
    % A Solution in MiniZinc
    include "globals.mzn";
     
    % Dominoes are (A-B) (B-C) (C-D) (D-E)
    var 0..6: A; var 0..6: B; var 0..6: C; var 0..6: D; var 0..6: E;
    
    var 1000..9999: ABBC = 1000*A + 110*B + C;
    var 1000..9999: BCCD = 1000*B + 110*C + D;
    
    predicate is_prime(var int: x) = 
       x > 1 /\ forall(i in 2..1 + ceil(sqrt(int2float(ub(x))))) 
      ((i < x) -> (x mod i > 0));
    
    predicate is_sq(var int: y) =
      let { var 1..ceil(sqrt(int2float(ub(y)))): z}
      in z*z = y;
       
    constraint is_sq(ABBC) /\ is_sq(A + B + B + C + C + D + D + E);
    constraint is_prime(BCCD);
    
    solve satisfy;
    
    output ["Four Dominoes are " ++ show(A) ++ "-"++ show(B) ++ ", " 
    ++ show(B) ++ "-" ++ show(C) ++ ", " ++ show(C) ++ "-" 
    ++ show(D) ++ ", " ++ show(D)++ "-" ++ show(E) ];
    
    % Four Dominoes are 2-1, 1-6, 6-3, 3-3
    % ----------
    % Four Dominoes are 4-2, 2-5, 5-1, 1-5
    % ----------
    % Four Dominoes are 1-4, 4-4, 4-1, 1-6
    % ----------
    % ==========
    
    
    

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: