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:
self.path.append(choice)
return self
def didGuess(self):
return self.index > len(self.path)
def left(self):
return self.index - len(self.path)
def dispensable(self):
self.index += 1
......@@ -25,16 +25,16 @@ class ReducePath:
def reduce(predicate, rtree):
r = ReducePath([])
i = rtree(r)
if not predicate(i):
return None
while r.didGuess():
# Explore the left tree
i = rtree(r.explore(True))
# If the predcate fails, move right
r.path[-1] = predicate(i)
it = rtree(r.explore(True))
# While we don't consume all choices going down the true branch
while r.left() >= 0:
if predicate(it):
# If true update the valid input
i = it
else:
# If false we have to go down the left branch.
r.path[-1] = False
it = rtree(r.explore(True))
return i
......
......@@ -92,15 +92,14 @@ reduceT
-> IRTreeT l t i
-> m i
reduceT lift_ p rt = do
Seq.empty & fix \rec sq -> do
-- Try to run the true branch.
(k', _, _) <- _probe Seq.empty
(\f -> f Seq.empty k') $ fix \rec sq k -> do
(i, l, left) <- _probe (sq Seq.|> True)
p l i >>= \case
-- If predicate is true, and there is choices left
True | left > 0 -> rec (sq Seq.|> True)
-- If predicate is false (and stable)
False | left >= 0 -> rec (sq Seq.|> False)
_ow -> pure i
if left < 0
then pure k
else do
t <- p l i
rec (sq Seq.|> t) (if t then i else k)
where
_probe sq = lift_ . probeT rt . fromChoiceList $ toList sq
{-# INLINE reduceT #-}
......
......@@ -3,4 +3,3 @@
111: 1 False
1101: 2 False
11001: 3 False
11000: 1 + 2 True
......@@ -3,4 +3,3 @@
111: 2 False
1101: 2 False
11001: 4 False
11000: 2 + 2 True
......@@ -2,4 +2,3 @@
11: 2 False
101: 1 False
1001: 3 False
1000: 2 + 1 True
1: 1 False
01: 2 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