Cryptogram solver
Orbitz - orbitz - November 20, 2006Newspaper puzzles beware. I have been working on soving newspaper cryptograms for the past few days in my free time. It is a bit more interesting of a problem to solve than sudoku I think. The algorithm I’ve implementing is nothing alltogether impressive and it relies on a good dictionary file to get solutions.
The algorithm works like so:
First you need an index which is a map of abstract words to lists of words.
An abstract word is taking a word and turning it into a pattern, for instance, ‘cat’ has the pattern ‘123’, as does ‘hat’, and ‘fat’. ‘mom’ has the pattern ‘121’.
Then it takes the sentence you have given it, splits it on spaces.
Popping the first word off the list, finds the list in the index of possible words it could be, iterates over it generating a map of letters to letters and recurses on the rest of the sentence, once it has reached the end of the sentence it puts the map it has generated into a list of possible solutions. If a generated map for a word conflicts with teh current map it is not a valid solution and moves onto the next possible solution.
The solve function returns a list of solution maps that can eb applied to any sentence to get the result.
Little things that make it helpful include being able to give an intial map, if you are sure some letters map to other letters you can give that as a hint. It can also remove any words whos pattern does not appear in the map.
Todo:
Solve only those subsets of words that, if solved, will result in the entire alphabet being solved. It should do this for all possible combinations of words in teh sentence that will result in this. This is not an optimizations, it should probably make it take longer to solve actually, however it allows it to solve sentences with words that might not exist in the dictionary but could come about as a result of solving the other words. I have a few ideas of how to do this but havn’t had time to implement it yet.
The current code can be downloaded here.
Categories: Blogs Orbitz
Erlang on Twitter
» materAwe (Maksim Terekhin): RT @narmaru: Actor-based concurrency with C++ from @FoundationDB http://t.co/ZXAr6bfzgt. And that’s faster than erlang and anything other. …
» Neku42 (Max Klyga): RT @narmaru: Actor-based concurrency with C++ from @FoundationDB http://t.co/ZXAr6bfzgt. And that’s faster than erlang and anything other. …
» ambrosebs (Ambrose BS): #erlang’s Dialyzer+TypEr are nice. core.typed is a good starting point for #clojure success typing. Annotation-less checking is appealing.
» mr_virtan (virtan): RT @narmaru: Actor-based concurrency with C++ from @FoundationDB http://t.co/ZXAr6bfzgt. And that’s faster than erlang and anything other. …
» tyralion (Ivan Piliaiev): RT @narmaru: Actor-based concurrency with C++ from @FoundationDB http://t.co/ZXAr6bfzgt. And that’s faster than erlang and anything other. …
» erlnews (Erlang news): Mnesia - Check for a value in either of the keys in the table #erlang http://t.co/Lro8B4DWSz
» pleax (pleax): RT @narmaru: Actor-based concurrency with C++ from @FoundationDB http://t.co/ZXAr6bfzgt. And that’s faster than erlang and anything other. …
» garazdawi (Lukas Larsson): RT @marick: This book on Elixir (a language on top of Erlang) looks interesting: http://t.co/3qNXsON6Vt Dave Thomas has an eye for up-and-c…
» mike_neck (器官なき身体): Erlangのlistsモジュールを試してみる - 第3回 - mike、mikeなるままに… http://t.co/kGF77EWKuT まだ三つしか関数書いてないお…
» Art1Pirat (← denkt selbst! ): via @DeX77: http://t.co/YFez5PRPsD #erlang #fp #code #programming
Statistics
Number of aggregated posts: 10650
Most recent article: May 20, 2013
Latest comments
» Moraru on This is Why You Spent All that Time Learning to Program: It is true that computer science was a pain in the back at time that i’ve had to learn it…
» Commercial hand dryers on Couchbase Meetup at new HQ: Buy online from here where you will get so much of variety in Commercial hand dryers for people. If you…
» Fort McMurray Homes on Motivated Reasoning and Erlang vs Python vs Node: I don’t really understand why this post is motivational? I don’t even see a post, just a title. Fort McMurray…