Skip to content

Instantly share code, notes, and snippets.

@gzm55
Created April 20, 2015 04:49
Show Gist options
  • Save gzm55/c716e3c7497b90ff48d7 to your computer and use it in GitHub Desktop.
Save gzm55/c716e3c7497b90ff48d7 to your computer and use it in GitHub Desktop.
def from(initial: Stream[(Block, List[Move])],
explored: Set[Block]): Stream[(Block, List[Move])] = initial.headOption.map {
case (block, _) if done(block) => initial.head #:: from(initial.tail, explored)
case (block, history) =>
val newMoreBlocks = newNeighborsOnly(neighborsWithHistory(block, history), explored)
val newExploredBlocks = Set(block.left, block.down, block.right, block.up).filter(_.isLegal).filterNot(done)
(block, history) #:: from(initial.tail ++ newMoreBlocks, explored | newExploredBlocks)
}.getOrElse(Stream())
@gzm55
Copy link
Author

gzm55 commented Apr 20, 2015

fix unneeded tail evaluation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment