Created
January 27, 2011 11:19
-
-
Save hristozov/798372 to your computer and use it in GitHub Desktop.
K2.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{- Georgi Ivanov Hristozov 80430 -} | |
{- 2 ZADACHA -} | |
-- Vrushta spisak ot chisloto x, povtoreno n puti | |
repeatn x n | |
| n <= 0 = [] | |
| otherwise = x:(repeatn x (n - 1)) | |
-- Realizaciq na repeat-stream | |
repeatstream [] = [] | |
repeatstream ((x,n):xs) = (repeatn x n)++(repeatstream xs) | |
-- Testova funkcia za repeatstream | |
gendoubles n = (n,n):(gendoubles (n+1)) | |
{- 3 ZADACHA -} | |
startsWith [] _ = True | |
startsWith (x:xs) (y:ys) | |
| x == y = startsWith xs ys | |
| otherwise = False | |
substAll [] _ _ = [] | |
substAll _ [] _ = [] | |
substAll l1 l2 l3 | |
| startsWith l2 l1 = l3++(substAll (drop (length l2) l1) l2 l3) | |
| otherwise = (head l1):substAll (tail l1) l2 l3 | |
substDictionary l [] = l | |
substDictionary l (x:xs) = substAll modifiedl (fst x) (snd x) | |
where modifiedl = substDictionary l xs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment