Skip to content
Snippets Groups Projects
Commit 36ccf237 authored by chrg's avatar chrg
Browse files

Fix small problems

parent 6e284015
No related branches found
No related tags found
No related merge requests found
...@@ -11,8 +11,8 @@ class ReducePath: ...@@ -11,8 +11,8 @@ class ReducePath:
self.path.append(choice) self.path.append(choice)
return self return self
def didGuess(self): def left(self):
return self.index > len(self.path) return self.index - len(self.path)
def dispensable(self): def dispensable(self):
self.index += 1 self.index += 1
...@@ -25,16 +25,16 @@ class ReducePath: ...@@ -25,16 +25,16 @@ class ReducePath:
def reduce(predicate, rtree): def reduce(predicate, rtree):
r = ReducePath([]) r = ReducePath([])
i = rtree(r) i = rtree(r)
it = rtree(r.explore(True))
if not predicate(i): # While we don't consume all choices going down the true branch
return None while r.left() >= 0:
if predicate(it):
while r.didGuess(): # If true update the valid input
# Explore the left tree i = it
i = rtree(r.explore(True)) else:
# If the predcate fails, move right # If false we have to go down the left branch.
r.path[-1] = predicate(i) r.path[-1] = False
it = rtree(r.explore(True))
return i return i
......
...@@ -92,15 +92,14 @@ reduceT ...@@ -92,15 +92,14 @@ reduceT
-> IRTreeT l t i -> IRTreeT l t i
-> m i -> m i
reduceT lift_ p rt = do reduceT lift_ p rt = do
Seq.empty & fix \rec sq -> do (k', _, _) <- _probe Seq.empty
-- Try to run the true branch. (\f -> f Seq.empty k') $ fix \rec sq k -> do
(i, l, left) <- _probe (sq Seq.|> True) (i, l, left) <- _probe (sq Seq.|> True)
p l i >>= \case if left < 0
-- If predicate is true, and there is choices left then pure k
True | left > 0 -> rec (sq Seq.|> True) else do
-- If predicate is false (and stable) t <- p l i
False | left >= 0 -> rec (sq Seq.|> False) rec (sq Seq.|> t) (if t then i else k)
_ow -> pure i
where where
_probe sq = lift_ . probeT rt . fromChoiceList $ toList sq _probe sq = lift_ . probeT rt . fromChoiceList $ toList sq
{-# INLINE reduceT #-} {-# INLINE reduceT #-}
......
...@@ -3,4 +3,3 @@ ...@@ -3,4 +3,3 @@
111: 1 False 111: 1 False
1101: 2 False 1101: 2 False
11001: 3 False 11001: 3 False
11000: 1 + 2 True
...@@ -3,4 +3,3 @@ ...@@ -3,4 +3,3 @@
111: 2 False 111: 2 False
1101: 2 False 1101: 2 False
11001: 4 False 11001: 4 False
11000: 2 + 2 True
...@@ -2,4 +2,3 @@ ...@@ -2,4 +2,3 @@
11: 2 False 11: 2 False
101: 1 False 101: 1 False
1001: 3 False 1001: 3 False
1000: 2 + 1 True
1: 1 False 1: 1 False
01: 2 False 01: 2 False
001: 3 False 001: 3 False
000: 1 + 2 True
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment