Enigmatic Code

Programming Enigma Puzzles

Puzzle #67: My prime

From New Scientist #3290, 11th July 2020 [link] [link]

I am thinking of a two-digit prime number. The special thing about my prime, though, is that if I square its two digits, the difference between these square numbers is also prime.

As it happens, I haven’t given you enough information to identify my number. But whatever my number is, you can be certain that its two digits have a particular relationship to each other. What is that relationship?

[puzzle#67]

4 responses to “Puzzle #67: My prime

  1. Jim Randell 11 July 2020 at 8:29 am

    If the prime number is AB, then we also require |A² − B²| to be prime.

    Note that:

    |A² − B²| = |A + B|.|A − B|

    And in order for this to be prime one of the terms in the product will have to be 1. And as the digits are non-zero, we see that:

    |A − B| = 1

    So the solutions are those 2-digit primes where the digits differ by 1.

    Run: [ @repl.it ]

    #!/usr/bin/env python -m enigma -r
    
    SubstitutedExpression
    
    "is_prime(AB)"
    "is_prime(abs(A * A - B * B))" # or: "abs(A - B) = 1"
    

    Solution: The digits of the prime must differ by 1.

    So the number is one of: 23, 43, 67, 89.

  2. Rob Ferguson 17 July 2020 at 12:46 pm

    Very neat. I got this one by code, but your analytical solution is much more elegant.

  3. GeoffR 17 July 2020 at 7:49 pm
    % A Solution in MiniZinc
    include "globals.mzn";
     
    var 1..9:A; var 1..9:B;
    var 11..97: AB = 10*A + B;
    
    predicate is_prime(var int: x) = 
    x > 1 /\ forall(i in 2..1 + ceil(sqrt(int2float(ub(x)))))
    ((i < x) -> (x mod i > 0));
    
    constraint is_prime(AB) /\ is_prime(abs(A*A - B*B));
    
    solve satisfy;
    
    output ["Two digit prime is " ++ show(AB) ] ++
    [", Digit difference = " ++ show(abs(A-B)) ] ;
    
    % Two digit prime is 23, Digit difference = 1
    % ----------
    % Two digit prime is 43, Digit difference = 1
    % ----------
    % Two digit prime is 67, Digit difference = 1
    % ----------
    % Two digit prime is 89, Digit difference = 1
    % ----------
    % ==========
    
    
    
    

Leave a Comment

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