Merica!

H A W A I I I D A H O I O W A + O H I O S T A T E S \begin{array} { l l l l l l } & H & A & W & A & I & I \\ & & I & D & A & H & O \\ & & & I & O & W & A \\ + & & & O & H & I & O \\ \hline & S & T & A & T & E & S \\ \end{array}

In the above expression, each letter stands for a single unique digit. Calculate A E I O H W D S T \overline{AEIOHWDST} .

Details and Assumptions

  • None of the word starts with 0 0 .
Image Credit: Wikimedia Frydolin

Here are My CS Problems


The answer is 149350862.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

3 solutions

Pranjal Jain
Mar 30, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import re
import itertools

def solve(puzzle):
    words = re.findall('[A-Z]+', puzzle.upper())
    unique_characters = set(''.join(words))
    assert len(unique_characters) <= 10, 'Too many letters'
    first_letters = {word[0] for word in words}
    n = len(first_letters)
    sorted_characters = ''.join(first_letters) + \
        ''.join(unique_characters - first_letters)
    characters = tuple(ord(c) for c in sorted_characters)
    digits = tuple(ord(c) for c in '0123456789')
    zero = digits[0]
    for guess in itertools.permutations(digits, len(characters)):
        if zero not in guess[:n]:
            equation = puzzle.translate(dict(zip(characters, guess)))
            if eval(equation):
                return equation

if __name__ == '__main__':
    import sys
    for puzzle in sys.argv[1:]:
        print(puzzle)
        solution = solve(puzzle)
        if solution:
            print(solution)

This is a general solution for which I posted this problem. For more details, see this

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
from itertools import permutations
for i in permutations('0123456789'):
    x=''.join(i)
    H=x[0]
    A=x[1]
    W=x[2]
    I=x[3]
    D=x[4]
    O=x[5]
    W=x[6]
    S=x[7]
    T=x[8]
    E=x[9]
    if int(H+A+W+A+I+I)+int(I+D+A+H+O)+int(I+O+W+A)+int(O+H+I+O)==int(S+T+A+T+E+S):
        print(int(A+E+I+O+H+W+D+S+T))

Raghav for the win.

Raghav Vaidyanathan - 6 years, 2 months ago

Log in to reply

I knew this one. This problem was just for introducing some Python 3.x

Pranjal Jain - 6 years, 2 months ago

Log in to reply

Actually I don't know it.. I have just been copy pasting it from @Aditya Raut 's solution to solve everything.

Raghav Vaidyanathan - 6 years, 2 months ago

Log in to reply

@Raghav Vaidyanathan It just uses the different permutations of a string '0123456789'. Then join method is used to convert the permutation object to string. Now, randomly, all the letters are given a position. At the end, the condition is checked by converting string to int. Its easier to concatenate strings, thus conversion is followed by concatenation.

Pranjal Jain - 6 years, 2 months ago

A far more easier solution will be this .

Don't get angry at me Pranjal , it's just that I have bookmarked a lot of sites and now they are coming in handy !

A Former Brilliant Member - 6 years, 2 months ago
Deep Shah
Apr 1, 2015

Here is my C code.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<stdio.h>

void main()
{

    int sum,sum1;
    int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;

    for(a=1;a<10;a++)
    for(d=0;d<10;d++)
    for(e=0;e<10;e++)
    for(h=1;h<10;h++)
    for(i=1;i<10;i++)
    for(o=1;o<10;o++)
    for(s=1;s<10;s++)
    for(t=0;t<10;t++)
    for(w=0;w<10;w++)
    {
        sum = (h*100000+a*10000+w*1000+a*100+i*11);
        sum += (i*10000+d*1000+a*100+h*10+o);
        sum += (i*1000+o*100+w*10+a);
        sum += (o*1000+h*100+i*10+o);
        sum1 = (s*100000+t*10000+a*1000+t*100+e*10+s);
        if(a==d || a==e || a==h || a==i || a==o || a==s || a==t || a==w)
            continue;
        if(d==e || d==h || d==i || d==o || d==s || d==t || d==w)
            continue;
        if(e==h || e==i || e==o || e==s || e==t || e==w)
            continue;
        if(h==i || h==o || h==s || h==t || h==w)
            continue;
        if(i==o || i==s || i==t || i==w)
            continue;
        if(o==s || o==t || o==w)
            continue;
        if(s==t || s==w)
            continue;
        if(t==w)
            continue;
        if(sum==sum1)
        {
            printf("%d\n",a*100000000+e*10000000+i*1000000+o*100000+h*10000+w*1000+d*100+s*10+t);
        }
    }
    return;
}

Python is good but i like C.

Usually C/C++ are not of use while dealing with bigger numbers (due to lack of such data types). Thus, I have moved on to python recently.

Pranjal Jain - 6 years, 2 months ago
Brock Brown
Mar 30, 2015

Python 2.7:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from itertools import permutations as perms
problem = 'HAWAII+IDAHO+IOWA+OHIO==STATES'
chars = set(problem)
chars -= set(['+','='])
nonzero = 'HIOS'
decrypt = {'+':'+','=':'='}
def decode(guess):
    new = ''
    for c in problem:
        new = new + decrypt[c]
    return new
def goal(guess):
    index = 0
    for c in chars:
        decrypt[c] = str(guess[index])
        index += 1
        if index == 9:
            break
    for c in nonzero:
        if decrypt[c] == '0':
            return False
    new = decode(guess)
    return eval(new)
for guess in perms(xrange(10)):
    if goal(guess):
        answer = ''
        for c in 'AEIOHWDST':
            answer = answer + decrypt[c]
        print "Answer:", answer
        break

I'm pretty ashamed of needing to use 30 lines and 70 seconds of running time, but give me a break, I hit my head today on the road during a bicycle wreck and had a concussion. :P

Are you all right now ?

A Former Brilliant Member - 6 years, 2 months ago

Log in to reply

Yeah, I feel a million times better. Thanks for asking.

Brock Brown - 6 years, 2 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...