Enigmatic Code

Programming Enigma Puzzles

Enigma 1215: One and a bit

From New Scientist #2371, 30th November 2002 [link]

Brits who venture into Euroland quickly discover that you get one-and-a-bit euros for every pound. I can reveal that the “bit” varies between one-third and three-eighths because:

(a) EURO × 1 ⅓ = POUND
(b) EURO × 1 ⅜ = POUND

These two sums are entirely distinct: any letter may or may not have the same value in one sum as in the other. But within each sum digits have been consistently represented by capital letters, different letters being used for different digits. No number starts with a zero.

Find the 5-digit numbers represented by POUND in (a) and (b).

[enigma1215]

Advertisements

3 responses to “Enigma 1215: One and a bit

  1. Jim Randell 26 July 2015 at 9:35 am

    This Python program runs in 54ms.

    from enigma import irange, printf
    
    # check (<word>,<number>) pairs in <args>
    def check(*args, **kw):
      l2d = dict()
      for (w, n) in args:
        s = str(n)
        if len(w) != len(s) or s[0] == '0': return
        for (c, d) in zip(w, s):
          if c in l2d:
            if l2d[c] != d:
              return
          elif d in l2d.values():
            return
          else:
            l2d[c] = d
      # output a match?
      output = kw.get('output', None)
      if output is not None:
        if output: output += ' '
        printf("{output}{args}", args=' '.join(w + '=' + str(n) for (w, n) in args))
      # return the mapping
      return l2d
    
    for EURO in irange(1002, 9999, step=3):
      check(('EURO', EURO), ('POUND', 4 * (EURO // 3)), output='(a)')
    
    for EURO in irange(1000, 9999, step=8):
      check(('EURO', EURO), ('POUND', 11 * (EURO // 8)), output='(b)')
    

    Solution: (a) POUND = 12056. (b) POUND = 10945.

    • geoffrounce 26 July 2015 at 11:56 am
      from itertools import permutations
      
      for p in permutations('1234567890',7):
        e, u, r, o, p, n, d = p
        if e != '0' and p != '0':
          euro = int(e + u + r + o)
          pound = int(p + o + u + n + d)
          if 3 * pound == 4 * euro:
            print('EURO = {} (* 4/3) = POUND = {}'.format(euro,pound))
          if 8 * pound == 11 * euro:
            print('EURO = {} (* 11/8) = POUND = {}'.format(euro,pound))
            
      # EURO = 7960 (* 11/8) = POUND = 10945
      # EURO = 9042 (* 4/3) = POUND = 12056      
      
  2. Brian Gladman 26 July 2015 at 7:06 pm
    # Find EURO and POUND such that EURO * top = POUND * bottom
    # with capital letters representing different digits
    def compute(top, bottom):
      for i in range((10000 + top - 1) // top, 9999 // bottom + 1):
        euro, pound =  bottom * i, top * i
        E, U, R, O, P, o, u, N, D = str(euro) + str(pound)
        if o == O and u == U and len(set((E, U, R, O, P, N, D))) == 7:
          return euro, pound
    
    fs = '({}) EURO = {}, POUND = {}'
    print(fs.format('a', *compute( 4, 3)))
    print(fs.format('b', *compute(11, 8)))
    

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: