Boggle - and dictionary = Dictionary.read_dictionary dict_file in let width = Board.width board in let rec solveHelper x y = let newList = if(x 1 =

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
let findWords x y board dictionary = let bcurs = Board.cursor board x y in let tcurs = Trie.cursor dictionary [] in let rec findWordsHelper acc bcurs tcurs = let (x, y) = Board.coordinates_of_cursor bcurs in let bchar = Board.get board x y in match Trie.advance tcurs bchar with None -> [] | Some(c) -> let wd = match Trie.getc c with None -> [] | Some(b) -> if b = true then [Board.get_word bcurs] else [] in wd @ (List.fold_left (fun a (x,y) -> (findWordsHelper [] (Board.move_cursor bcurs x y) c)@a) acc (Board.unvisited_neighbors bcurs)) in findWordsHelper [] bcurs tcurs let solve board_file dict_file out_file = let board = Board.load_board board_file
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: and dictionary = Dictionary.read_dictionary dict_file in let width = Board.width board in let rec solveHelper x y = let newList = if (x+1) = width then (if (y+1) = width then else solveHelper 0 (y+1)) else solveHelper (x+1) y in (findWords x y board dictionary) @ newList in let (_, wds) = List.fold_left (fun (last, acc) w -> if last = w then (last, acc) else (w, w::acc)) ("", ) (List.sort String.compare (solveHelper 0 0)) in let oc = open_out out_file in try List.iter (fun s -> output_string oc (s ^ "\n"); flush oc) (List.rev wds); close_out oc with e -> close_out_noerr oc; raise e...
View Full Document

This note was uploaded on 10/25/2009 for the course CS 3110 at Cornell University (Engineering School).

Ask a homework question - tutors are online