PROBLEM:
solution (* 10) [1,2,3] = [10,20,30]
solution (+1) [0,1..] = [1,2..]
solution (+ 10) ([1,2]++[3,3..]) = [11,12]++[13,13..]
ROZWIĄZANIE:
module Solution where
findElem (a:b) (c:d) =
if a == c
then a
else findElem b d
getResult func a all st =
let elem = findElem a all in cycle (
(map (\x -> (x, func x)) (takeWhile (/= elem) $ tail a)) ++
reverse (
(takeWhile ((/= elem) . fst) st)
++ [head (dropWhile ((/=elem) . fst) st)]
)
)
solu func [] [] all st = []
solu func (a:b) [] all st = [(a, func a)] ++ (solu func b [] all st)
solu func (a:b) (c:d) all st =
if b == []
then
[(a, func a)]
else if a == head b
then
repeat (a, func a)
else
if a==c && st /= []
then
(let l = func a in [(a,l)] ++ getResult func (a:b) all ([(a,l)] ++ st))
else
(let l = func a in [(a,l)] ++ (
case d of
e:g -> solu func b g all ([(a,l)] ++ st)
_ -> solu func b [] all []
))
solution func a = map snd (solu func a a a [])