Hardest Cryptarithmetic Puzzle

If:

THIS + A + FIRE + THEREFORE + FOR + ALL + HISTORIES + I + TELL + A + TALE + THAT + FALSIFIES + ITS + TITLE + TIS + A + LIE + THE + TALE + OF + THE + LAST + FIRE + HORSES + LATE + AFTER + THE + FIRST + FATHERS + FORESEE + THE + HORRORS + THE + LAST + FREE + TROLL + TERRIFIES + THE + HORSES + OF + FIRE + THE + TROLL + RESTS + AT + THE + HOLE + OF + LOSSES + IT + IS + THERE + THAT + SHE + STORES + ROLES + OF + LEATHERS + AFTER + SHE + SATISFIES + HER + HATE + OFF + THOSE + FEARS + A + TASTE + RISES + AS + SHE + HEARS + THE + LEAST + FAR + HORSE + THOSE + FAST + HORSES + THAT + FIRST + HEAR + THE + TROLL + FLEE + OFF + TO + THE + FOREST + THE + HORSES + THAT + ALERTS + RAISE + THE + STARES + OF + THE + OTHERS + AS + THE + TROLL + ASSAILS + AT + THE + TOTAL + SHIFT + HER + TEETH + TEAR + HOOF + OFF + TORSO + AS + THE + LAST + HORSE + FORFEITS + ITS + LIFE + THE + FIRST + FATHERS + HEAR + OF + THE + HORRORS + THEIR + FEARS + THAT + THE + FIRES + FOR + THEIR + FEASTS + ARREST + AS + THE + FIRST + FATHERS + RESETTLE + THE + LAST + OF + THE + FIRE + HORSES + THE + LAST + TROLL + HARASSES + THE + FOREST + HEART + FREE + AT + LAST + OF + THE + LAST + TROLL + ALL + OFFER + THEIR + FIRE + HEAT + TO + THE + ASSISTERS + FAR + OFF + THE + TROLL + FASTS + ITS + LIFE + SHORTER + AS + STARS + RISE + THE + HORSES + REST + SAFE + AFTER + ALL + SHARE + HOT + FISH + AS + THEIR + AFFILIATES + TAILOR + A + ROOFS + FOR + THEIR + SAFE == FORTRESSES

Find:

    F+O+R+T+R+E+S+S+E+S


The answer is 38.

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.

1 solution

Chris Oliver
Oct 21, 2019

I have found two ways of doing this, one a shorter code length but longer solve time, and one with a longer code length, but shorter solver time

from re import sub
def solve(q):
    try:
        n = next((i for i in q if i.isalpha()))
    except StopIteration:
        return q if eval(sub(r'(^|[^0-9])0+([1-9]+)', r'\1\2', q)) else False
    else: 
        for i in (str(i) for i in range(10) if str(i) not in q):
            r = solve(q.replace(n,str(i)))
        if r:
            print(r)
        return

if __name__ == "__main__":
    query = "AA + BB == CC" #If you enter the problem here, it will solve it
    solve(query)

or

import itertools, time
sentences = [
    "AA + BB == CC" #If you enter the problem here, it will solve it
    ]
def show_solution(s):
    print(s)
    print('{' + ', '.join(['"'+ chr(i) + '"=>' + chr(trantab[i]) for i in trantab]) + '}\n')
for sentence in sentences:
    t1 = time.time()
    words = [ss for ss in sentence.split() if ss.isalpha()]
    letters = ''
    for w in words:
        for l in w:
            if l not in letters:
                letters += l        ## ELL not ONE
    letters = ''.join(sorted(letters))
    length = len(letters)
    for p in itertools.permutations(("0","1","2","3","4","5","6","7","8","9"), length):
        p2 = "".join(p)
        trantab = str.maketrans(letters, p2)
        ww = []
        lead_0 = False
        for w in words:
            w2 = w.translate(trantab)
            if w2[0] == "0":
                lead_0 = True
                break
            ww.append(int(w2))
        if not lead_0 and sum(ww[:-1]) == ww[-1]:
            show_solution('"{0}": {1:.2f} sec.'.format(sentence, time.time() - t1))
            break

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...