News for hackers. Stuff that matters.
Re:Using Monads in C++ to Solve Constraints: 1. The List Monad by RodericDay on Monday May 11, 2015 @09:12PM (#9528945)
this was mine, brutey

    import itertools as it
    a =  'dog'
    b =  'food'
    c = 'tasty'
    letters = sorted(set(a+b+c))
    for combo in it.permutations('0123456789', len(letters)):
        mapping = dict(zip(letters, combo))
        if len(c) > max(len(a), len(b)) and mapping[c[0]] is '0':
            continue
        f = lambda string: int(''.join(map(mapping.get, string)))
        n1, n2, n3 = map(f, [a, b, c])
        if n1 + n2 == n3:
            print( mapping )
            print( n1, n2, n3 )
            break
seems haskell friendly given all the mappings, but not in the way that the blogpost did it. but also not with that big nested loop either.

There are no comments on this comment yet.