Created
November 4, 2012 21:36
-
-
Save mariusae/4013882 to your computer and use it in GitHub Desktop.
Letterpress solver
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* ocamlbuild letterpress.native *) | |
let rec mkword ?(i=0) ?(l=[]) w = | |
if i = (String.length w) then | |
let l' = List.map Char.lowercase l in | |
List.fast_sort Char.compare l' | |
else | |
mkword ~i:(i+1) ~l:(w.[i]::l) w | |
let rec contains b w = match (b,w) with | |
| (x::b', y::_) when x < y -> contains b' w | |
| (x::b', y::w') when x = y -> contains b' w' | |
| (_, []) -> true | |
| _ -> false | |
let () = | |
let board = Sys.argv.(1) in | |
let b = mkword board in | |
try | |
while true do | |
let word = input_line stdin in | |
let w = mkword word in | |
if contains b w then | |
Printf.printf "%s\n" word | |
else () | |
done | |
with | |
End_of_file -> () |
Author
mariusae
commented
Nov 4, 2012
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment