Skip to content

Instantly share code, notes, and snippets.

@JPMoresmau
Created February 10, 2019 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JPMoresmau/4c301e6e03bd1b4da283b5cca17ac63e to your computer and use it in GitHub Desktop.
Save JPMoresmau/4c301e6e03bd1b4da283b5cca17ac63e to your computer and use it in GitHub Desktop.
Lovecraft: solve
use std::collections::HashMap;
use std::collections::VecDeque;
pub fn solve(grid: Grid) -> Vec<Pos> {
if is_solved(grid){
return vec!();
}
let mut ret = None;
let mut seen=HashMap::new();
seen.insert(grid,Vec::new());
let mut todo=VecDeque::new();
todo.push_back(grid);
while ret.is_none(){
match todo.pop_front(){
Some(g)=> {
ret = try_all(&g,&mut seen,&mut todo);
},
None=>panic!("no more grids to do"),
}
}
ret.expect("no result!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment