import List
esPrefijoDe :: [Char] -> [Char] -> Bool
esPrefijoDe [] _ = True
esPrefijoDe _ [] = False
esPrefijoDe (x:xs) (y:ys) | x/=y = False
| otherwise = esPrefijoDe xs ys
posicionsub :: [Char] -> [Char] -> Int
posicionsub _ [] = -1
posicionsub (x:xs) (y:ys) | esPrefijoDe (x:xs) (y:ys) = 1
| otherwise = 1 + posicionsub (x:xs) ys
sumador :: [Int] -> [Int]
sumador [] = []
sumador [x] = [x]
sumador (x:y:[]) = [x] ++ [x+y]
sumador (x:y:xs) = [x] ++ sumador ([x+y] ++ xs)
busquedas3 :: [Char] -> [Char] -> [Int]
busquedas3 _ [] = []
busquedas3 xs (y:ys) | pos+1<length(ys)+1 = [pos] ++ busquedas3 xs (drop (pos-1) ys)
| otherwise = busquedas3 xs ys
where pos = posicionsub xs (y:ys)
busquedas4 :: [Char] -> [Char] -> [Int]
busquedas4 xs ys = sumador(busquedas3 xs ys)
esPrefijoDe :: [Char] -> [Char] -> Bool
esPrefijoDe [] _ = True
esPrefijoDe _ [] = False
esPrefijoDe (x:xs) (y:ys) | x/=y = False
| otherwise = esPrefijoDe xs ys
posicionsub :: [Char] -> [Char] -> Int
posicionsub _ [] = -1
posicionsub (x:xs) (y:ys) | esPrefijoDe (x:xs) (y:ys) = 1
| otherwise = 1 + posicionsub (x:xs) ys
sumador :: [Int] -> [Int]
sumador [] = []
sumador [x] = [x]
sumador (x:y:[]) = [x] ++ [x+y]
sumador (x:y:xs) = [x] ++ sumador ([x+y] ++ xs)
busquedas3 :: [Char] -> [Char] -> [Int]
busquedas3 _ [] = []
busquedas3 xs (y:ys) | pos+1<length(ys)+1 = [pos] ++ busquedas3 xs (drop (pos-1) ys)
| otherwise = busquedas3 xs ys
where pos = posicionsub xs (y:ys)
busquedas4 :: [Char] -> [Char] -> [Int]
busquedas4 xs ys = sumador(busquedas3 xs ys)
No hay comentarios:
Publicar un comentario