Skip to content

Commit

Permalink
explain the propagation algorithm a little better in a comment
Browse files Browse the repository at this point in the history
also make something that Elm can do TCO on
  • Loading branch information
BrianHicks committed Feb 21, 2020
1 parent c15e790 commit d10b537
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/Wave.elm
Expand Up @@ -166,10 +166,25 @@ propagate todo (Wave wave) =
propagate rest (Wave wave)

Just cell ->
[ Direction.up, Direction.down, Direction.left, Direction.right ]
|> List.foldl (propagateInDirection target cell) ( Wave wave, rest )
-- TODO this prevents TCO. Should rearrange the code once it works.
|> (\( finalWave, finalRest ) -> propagate finalRest finalWave)
-- Starting at the given cell, constrain neighbor cells to
-- possibilities compatible with the ones in this cell. If
-- we reduce the number of possibilities, we then
-- propagate again based on that new cell.
--
-- While doing this, if a cell becomes finalized (that is,
-- we remove all possibilites but one) we mark them as such
-- and continue propagation.
--
-- If a cell becomes blocked (that is, we remove all
-- possibilities) we mark it as such and stop propagation.
let
( propagatedWave, propagatedTodo ) =
List.foldl (propagateInDirection target cell)
( Wave wave, rest )
[ Direction.up, Direction.down, Direction.left, Direction.right ]
in
-- be careful that this can be TCO'd
propagate propagatedTodo propagatedWave


propagateInDirection :
Expand Down

0 comments on commit d10b537

Please sign in to comment.