From d10b537d95605165dc96e001484a503cccb03287 Mon Sep 17 00:00:00 2001 From: Brian Hicks Date: Fri, 21 Feb 2020 09:54:51 -0600 Subject: [PATCH] explain the propagation algorithm a little better in a comment also make something that Elm can do TCO on --- src/Wave.elm | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Wave.elm b/src/Wave.elm index ed53585..52db4a4 100644 --- a/src/Wave.elm +++ b/src/Wave.elm @@ -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 :