diff --git a/02.hs b/02.hs index d81cdb0..697d4f0 100644 --- a/02.hs +++ b/02.hs @@ -71,19 +71,20 @@ concatShuffle xxs = let xxs' = filter (not . null) xxs in map head xxs' ++ concatShuffle (map tail xxs') nextSimpleExprsLists :: [Expr] -> [[Expr]] -nextSimpleExprsLists exprs = [[Succ e | e <- exprs, typeOf e == IntT], - [Sort e | e <- exprs, typeOf e == ListT], - [Recursive e | e <- exprs, typeOf e == ListT], - [FirstZero e | e <- exprs, typeOf e == ListT], - [Len e | e <- exprs, typeOf e == ListT]] +nextSimpleExprsLists exprs = let listExprs = [ e | e <- exprs, typeOf e == ListT] in + [[Succ e | e <- exprs, typeOf e == IntT], + map Sort listExprs, + map Recursive listExprs, + map FirstZero listExprs, + map Len listExprs] nextExprsLists :: [Expr] -> [[Expr]] -nextExprsLists exprs = nextSimpleExprsLists exprs ++ - [[e :+: e' | e <- exprs, typeOf e == ListT, - e' <- exprs, typeOf e' == ListT], - [SubList e from to | e <- exprs, typeOf e == ListT, - from <- exprs, typeOf from == IntT, - to <- exprs, typeOf to == IntT]] +nextExprsLists exprs = let listExprs = [ e | e <- exprs, typeOf e == ListT] in + let intExprs = [ e | e <- exprs, typeOf e == IntT] in + nextSimpleExprsLists exprs ++ + [[e :+: e' | e <- listExprs, + e' <- listExprs], + [SubList e from to | e <- listExprs, from <- intExprs, to <- intExprs]] nextSimpleExprs :: [Expr] -> [Expr] nextSimpleExprs exprs = (++) exprs $ concatShuffle $ nextSimpleExprsLists exprs @@ -107,20 +108,22 @@ nextSimpleExprs' = concatShuffle . nextSimpleExprsLists -- TODO: check formula for three args nextExprsLists' :: [Expr] -> [Expr] -> [[Expr]] -nextExprsLists' prevExprs allExprs = nextSimpleExprsLists prevExprs ++ - [[e :+: e' | e <- prevExprs, typeOf e == ListT, - e' <- allExprs, typeOf e' == ListT], - [e :+: e' | e <- allExprs, typeOf e == ListT, e `notElem` prevExprs, - e' <- prevExprs, typeOf e' == ListT], - [SubList e from to | e <- prevExprs, typeOf e == ListT, - from <- allExprs, typeOf from == IntT, - to <- allExprs, typeOf to == IntT], - [SubList e from to | e <- allExprs, typeOf e == ListT, e `notElem` prevExprs, - from <- prevExprs, typeOf from == IntT, - to <- allExprs, typeOf to == IntT], - [SubList e from to | e <- allExprs, typeOf e == ListT, e `notElem` prevExprs, - from <- allExprs, typeOf from == IntT, from `notElem` prevExprs, - to <- prevExprs, typeOf to == IntT]] +nextExprsLists' prevExprs allExprs = let notPrevExprs = [e | e <- allExprs, e `notElem` prevExprs] in + let listPrevExprs = [ e | e <- prevExprs, typeOf e == ListT] in + let intPrevExprs = [ e | e <- prevExprs, typeOf e == IntT] in + let listNotPrevExprs = [ e | e <- notPrevExprs, typeOf e == ListT] in + let intNotPrevExprs = [ e | e <- notPrevExprs, typeOf e == IntT] in + nextSimpleExprsLists prevExprs ++ + [[e :+: e' | e <- listPrevExprs, e' <- listPrevExprs], + [e :+: e' | e <- listPrevExprs, e' <- listNotPrevExprs], + [e :+: e' | e <- listNotPrevExprs, e' <- listPrevExprs], + [SubList e from to | e <- listPrevExprs, from <- intPrevExprs, to <- intPrevExprs], + [SubList e from to | e <- listNotPrevExprs, from <- intPrevExprs, to <- intPrevExprs], + [SubList e from to | e <- listPrevExprs, from <- intNotPrevExprs, to <- intPrevExprs], + [SubList e from to | e <- listPrevExprs, from <- intPrevExprs, to <- intNotPrevExprs], + [SubList e from to | e <- listNotPrevExprs, from <- intNotPrevExprs, to <- intPrevExprs], + [SubList e from to | e <- listNotPrevExprs, from <- intPrevExprs, to <- intNotPrevExprs], + [SubList e from to | e <- listPrevExprs, from <- intNotPrevExprs, to <- intNotPrevExprs]] nextExprs' :: [Expr] -> [Expr] -> [Expr] nextExprs' prevExprs allExprs = concatShuffle $ nextExprsLists' prevExprs allExprs @@ -141,7 +144,8 @@ areSame examples exprLeft exprRight | typeOf exprLeft == IntT = False | typeOf exprRight == IntT = False | otherwise = all (\Example {exampleInput, exampleOutput} -> let Just resLeft = execProg exampleInput exprLeft in let Just resRight = execProg exampleInput exprRight in - resLeft /= [] && resLeft == resRight) examples + resLeft /= [] -- NOTE: not in the base algorithm, way to remove rec deletion (?) + && resLeft == resRight) examples -----