Enigmatic Code

Programming Enigma Puzzles

Enigma 1530: Tom Daley

From New Scientist #2693, 31st January 2009 [link] [link]

Before being the youngest member of the British team at the 2008 Beijing Olympics, Tom Daley had become the youngest European diving champion on record by winning the individual title from the 10-metre platform board while still aged only 13.

So it is appropriate that I can offer this puzzle:

TOM × 13 = DALEY

Each letter stands for a different digit, and no number starts with a zero.

What is the five-digit number represented by DALEY?

[enigma1530]

12 responses to “Enigma 1530: Tom Daley

  1. Jim Randell 9 July 2012 at 8:18 am

    This one is easy to brute force. Here’s my original Perl code. It runs in 9ms.

    use strict;
    
    my ($TOM, $DALEY);
    for $TOM (780..987) {
      $DALEY = $TOM * 13;
      next if "$TOM$DALEY" =~ /(.).*\1/;
      print "$TOM x 13 = $DALEY\n";
    }
    

    Solution: DALEY = 10348.

    • Jim Randell 9 July 2012 at 8:23 am

      A similar thing in Python. It runs in 40ms.

      from enigma import (irange, is_duplicate, printf)
      
      for TOM in irange(780, 987):
        DALEY = str(TOM * 13)
        if is_duplicate(DALEY + str(TOM)): continue
        printf("DALEY={DALEY} TOM={TOM}")
      
      • Jim Randell 12 February 2013 at 6:56 pm

        And here’s a Python version using the SubstitutedSum class from the enigma.py library. It also runs in 40ms.

        from enigma import SubstitutedSum
        
        s = 'TOM x 13 = DALEY'
        p = SubstitutedSum(['TOM'] * 13, 'DALEY')
        for r in p.solve():
          print(s + ' / ' + p.substitute(r, s))
        
      • Jim Randell 21 September 2022 at 12:02 pm

        I used this puzzle as one of the examples for developing the [[ SubstitutedExpression ]] solver in the enigma.py library. (See: Solving Alphametics with Python).

        A puzzle like this can be solved directly from the command line:

        % python3 -m enigma SubstitutedExpression "{TOM} * 13 = {DALEY}"
        (TOM * 13 = DALEY)
        (796 * 13 = 10348) / A=0 D=1 E=4 L=3 M=6 O=9 T=7 Y=8
        [1 solution]
        

        The command runs in 64ms. The internal runtime of the generated program is 281µs.

  2. Naim Uygun 9 July 2012 at 10:03 am

    The answer will be ready when you click on enter key
    if you write the expression TOM*13=DALEY
    on the site http://www.iread.it/cryptarithms.php
    in the section Cryptarithms Solve
    The answer will be seen as
    M Y T O D A L E
    6 8 7 9 1 0 3 4

  3. GeoffR 22 February 2022 at 11:02 am
    ' Enigma 1530 - A console solution in Visual Basic 2019
    Module Module1
      Sub Main()
        Dim T, O, M, D, A, L, E, Y As Integer
        Dim TOM, DALEY As Integer
    
        For T = 1 To 9
          For O = 0 To 9
            If O = T Then Continue For
            For M = 0 To 9
              If M = O Or M = T Then Continue For
              TOM = 100 * T + 10 * O + M
    
              For D = 1 To 9
                If D = M Or D = O Or D = T Then Continue For
                For A = 0 To 9
                  If A = D Or A = M Or A = O Or A = T Then Continue For
                  For L = 0 To 9
                    If L = A Or L = D Or L = M Or L = O Or L = T _
                      Then Continue For
                    For E = 0 To 9
                      If E = L Or E = A Or E = D Or E = M Or E = O Or E = T _
                        Then Continue For
                      For Y = 0 To 9
                        If Y = E Or Y = L Or Y = A Or Y = D Or Y = M Or Y = O Or Y = T _
                          Then Continue For
    
                        DALEY = 10000 * D + 1000 * A + 100 * L + 10 * E + Y
    
                        If 13 * TOM = DALEY Then
                          Console.WriteLine("DALEY is {0}", DALEY)
                          Console.ReadLine()
                        End If
    
                      Next 'Y  
                    Next 'E
                  Next  'L
                Next  'A
              Next  'D
            Next  'M
          Next  'O
        Next  'T
    
      End Sub
    
    End Module
    
    ' DALEY is 10348
    
    
    
    
    
  4. GeoffR 22 February 2022 at 4:50 pm
    % A Solution in MiniZinc
    include "globals.mzn";
    
    var 1..9:T; var 1..9:D; var 0..9:O;  var 0..9:M;   
    var 0..9:A; var 0..9:L;  var 0..9:E; var 0..9:Y; 
     
    var  100..999:TOM = 100*T + 10*O + M;
    var 10000..99999:DALEY = 10000*D + 1000*A + 100*L + 10*E + Y;
    
    constraint TOM * 13 == DALEY;
    constraint all_different([T, O, M, D, A, L, E, Y]);
    
    solve satisfy;
    output[ "DALEY = " ++ show(DALEY) ];
    
    % DALEY = 10348
    % ----------
    % ==========
    
    
    

    Another solution.

    from itertools import permutations
    
    for p1 in permutations('1234567890', 8):
        T, O, M, D, A, L, E, Y = p1
        if T =='0' or D == '0':continue
        tom, daley = int(T + O + M), int(D + A + L + E + Y)
        if tom * 13 == daley:
            print(f"DALEY = {daley}")
    
    # DALEY = 10348    
    
    
    
  5. NJF 20 September 2022 at 5:10 pm

    As this thread came to life again a few months ago, I don’t feel too uncomfortable about posting this snippet in from Google Apps Script.

    
    function daleyDose(){
    
    // Precalculated bounds: 769 < TOM < 992
    
      var t,o,m,d,a,l,e,y;
    
      for(TOM=770;TOM<=991;TOM=TOM+13){
        DALEY = TOM * 13;
    
        t=parseInt(TOM.toString().substring(0,1));
        o=parseInt(TOM.toString().substring(1,2));
        m=parseInt(TOM.toString().substring(2,3));
    
        d=parseInt(DALEY.toString().substring(0,1));
        a=parseInt(DALEY.toString().substring(1,2));
        l=parseInt(DALEY.toString().substring(2,3));
        e=parseInt(DALEY.toString().substring(3,4));
        y=parseInt(DALEY.toString().substring(4,5));
    
        if(isUnique([t,o,m,d,a,l,e,y])){
          Logger.log(TOM+'.'+DALEY);
        }
      }
    }
    function isUnique(arrVals){
    
      for(p=0;p<=arrVals.length-1;p++){
        for(q=0;q<=arrVals.length-1;q++){
          if(p!=q){
            if(arrVals[p]!=arrVals[q]){
    
            }
            else {
              return false;
            }
          }
        }
      }
      return true;
    }
    
  6. NJF 20 September 2022 at 7:25 pm

    This problem is actually simple enough for a paper & pencil approach.

    Establishing bounds for TOM is trivial: the values must lie between 770 to 978 and be exactly divisible by 13. There are only 18 of these and you can strike out 7 of them for not having unique digits. By inspection, the 11 corresponding values of DALEY can quickly be reduced to 4 with unique digits and only 1 where the digits of TOM and DALEY are all unique.

    It took me longer to write this post than to find the solution 🙂

    • NJF 20 September 2022 at 7:27 pm

      Apologies, I misspoke: it’s the DALEY value which must be exactly divisible by 13, from which we derive the TOM values. More haste, less speed !!

Leave a Comment

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