Enigmatic Code

Programming Enigma Puzzles

Enigma 1303: Lucky numbers

From New Scientist #2461, 21st August 2004

Alex and his big sister Monica were using a new method to work out their lucky numbers. First they chose at random a number from 1 to 26 and assigned that value to the letter A. They then valued each of the remaining letters B to Z, with a number relating to its position in the alphabet. For example, if A had been given the value 10, then B would be 11, C would be 12, and so on through to Q=26, R=1 … Z=9.

With this exercise complete, they added up the totals for their respective names to find their lucky numbers. Alex was delighted, because (A+L+E+X) was bigger than (M+O+N+I+C+A). And they were both pleased to find that when the two lucky numbers were added together they made a perfect square.

What was the original value chosen for A?

[enigma1303]

Advertisements

2 responses to “Enigma 1303: Lucky numbers

  1. Jim Randell 8 August 2014 at 6:53 am

    This Python program runs in 39ms.

    from enigma import irange, is_square, printf
    
    # order the letters
    letter = dict((x, i) for (i, x) in enumerate('ABCDEFGHIJKLMNOPQRSTUVWXYZ'))
    
    def value(word, A):
      return sum((letter[x] + A - 1) % 26 + 1 for x in word)
    
    for A in irange(1, 26):
      ALEX = value('ALEX', A)
      MONICA = value('MONICA', A)
      if not(ALEX > MONICA): continue
      if not is_square(ALEX + MONICA): continue
    
      printf("A={A} ALEX={ALEX} MONICA={MONICA}")
    

    Solution: The value chosen for A is 19.

  2. Paul 8 August 2014 at 12:34 pm

    Here is a MMa solution

    alphabet =CharacterRange["a","z"];
    rules=Thread[alphabet->Range[26]];
    al=Characters["alex"];
    mo=Characters["monica"];
      Do[rules=Thread[alphabet->RotateLeft[Range[26],n]];
        ta=Total[al/.rules];
        tm=Total[mo/.rules];
          If[ta>tm&&IntegerQ[Sqrt[ta+tm]],Print[rules]],
      {n,1,26}]//Timing
     {a->19,b->20,c->21,d->22,e->23,f->24,g->25,h->26,i->1,j->2,k->3,l->4,m->5,n->6,o->7,p->8,q->9,r->10,s->11,t->12,u->13,v->14,w->15,x->16,y->17,z->18}
    {0.015600,Null}
    

    Paul.

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: