Hacker News new | ask | show | jobs
by lheck 434 days ago
almost-one-liner (though it will give you the full model):

    import z3; z3.solve([z3.Sum([ord(a) == z3.Int(f"k{i}") for i, a in enumerate(r[0])]) == r[1] for r in [("bbababbabb", 7), ("baaababaaa", 5), ("baaabbbaba", 3), ("bbaaabbaaa", z3.Int("x"))]])
1 comments

my take - more writeup style for people new to z3

https://happyhacks.bearblog.dev/solving-a-layton-puzzle-with...