Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Dali duljinata na vseki string = elementa ot drugiq spisuk ["abc","cdef","a"] [3,4,1]-da
- func::[String]->[Int]->Bool
- func [] []=True
- func (x:xs) (y:ys)
- |length x==y=func xs ys
- |otherwise=False
- --countOccurences [1,2,4,5,2,3,2] 2->3
- countOccurences::(Eq a)=>[a]->a->Int
- countOccurences xs a=countOccurencesHelper xs a 0
- countOccurencesHelper::(Eq a)=>[a]->a->Int->Int
- countOccurencesHelper [] a count =count
- countOccurencesHelper (x:xs) a count
- |x==a=countOccurencesHelper xs a (count+1)--
- |otherwise=countOccurencesHelper xs a count
- countOccurences::(Eq a)=>[a]->a->Int
- countOccurences [] elem=0
- countOccurences (x:xs) elem
- |x==elem=1+countOccurences xs elem
- |otherwise=countOccurences xs elem
- myFilter::(a->Bool)->[a]->[a]
- myFilter f []=[]
- myFilter f (x:xs)
- |f x==True= x: myFilter f xs
- |otherwise= myFilter f xs
- type Matrix a=[[a]]
- type Column a=[a]
- --vzima kolona
- nthCol::Matrix Int->Int->Column Int
- nthCol [] n=[]
- nthCol xs n=map (!!n) xs
- --vzima red
- type Row a=[a]
- nthRow:: Matrix Int->Int->Row Int
- --nthRow xs n=xs!!n
- nthRow =(!!)
- any'::(a->Bool)->[a]->Bool
- any' f []=False
- any' f (x:xs)
- |f x==True=True
- |f x==False=any' f xs
- any'::(a->Bool)->[a]->Bool
- any' f xs=or(map f xs)
- --stava kato kompozicia ot funkcii map vrushta (F,T,T)
- or(F,T,T) vrushta True t.k imame pone 1 true
- --all
- all'::(a->Bool)->[a]->Bool
- all' f xs=and(map f xs)
- --split
- split::[a]->Int->([a],[a])
- split xs n=(take n xs,drop n xs)
- --group
- group'::(Eq a)=>[a]->[[a]]
- group' []=[]
- group' (x:xs)=takeWhile (==x) (x:xs) : group' (dropWhile (==x) (x:xs))
- --group'::(Eq a)=>[a]->[[a]]
- --group' []=[]
- --group' (x:xs)=[takeWhile (==x) (x:xs)] ++ group' (dropWhile (==x) (x:xs))
- --minElement
- minElement::(Ord a)=>[a]->a
- minElement (x:xs)=minElementHelper xs x
- minElementHelper::(Ord a)=>[a]->a->a
- minElementHelper[] min=min
- minElementHelper (x:xs) min
- |x<min=minElementHelper xs x
- |otherwise=minElementHelper xs min
- --(expr,expr)
- minElement::(Ord a)=>[a]->a
- minElement (x:xs)=foldl (min) x xs
- --remove
- remove::(Eq a)=>a->[a]->[a]
- remove n []=[]
- remove n (x:xs)
- |x==n=xs
- |otherwise=x:remove n xs
- --sort
- --da polzvam min i remove
- minElement::(Ord a)=>[a]->a
- minElement (x:xs)=minElementHelper xs x
- minElementHelper::(Ord a)=>[a]->a->a
- minElementHelper[] min=min
- minElementHelper (x:xs) min
- |x<min=minElementHelper xs x
- |otherwise=minElementHelper xs min
- remove::(Eq a)=>a->[a]->[a]
- remove n []=[]
- remove n (x:xs)
- |x==n=xs
- |otherwise=x:remove n xs
- sort'::(Ord a)=>[a]->[a]
- sort' []=[]
- sort' xs=(minElement xs):sort' (remove (minElement xs) xs)
- --(expr,expr)
- --8 github
- remove::(Eq a)=>a->[a]->[a]
- remove n []=[]
- remove n (x:xs)
- |x==n=xs
- |otherwise=x:remove n xs
- sortBy::(Ord a)=>(a->a->a)->[a]->[a]
- sortBy f []=[]
- sortBy f xs=minElement:sortBy f (remove minElement xs)
- where minElement=foldl f (head xs) xs
- --foldl min (head [3,1,5,2]) [3,1,5,2]->1
- --foldl func 4 [4,3,1,2]->1
- func::(Ord a)=>a->a->a
- func x y
- |x<y=x
- |otherwise=y
- --po-obshto reshenie
- remove::(Eq a)=>a->[a]->[a]
- remove n []=[]
- remove n (x:xs)
- |x==n=xs
- |otherwise=x:remove n xs
- -- minl (\x y -> length x < length y) ["strings","about","to","get","sorted"]->"to"
- minl::(Ord a)=>(a->a->Bool)->[a]->a
- minl f (x:xs)=minLen f x xs
- minLen::(a->a->Bool)->a->[a]->a
- minLen f min []=min
- minLen f min (x:xs)
- |f x min==True=minLen f x xs
- |otherwise=minLen f min xs
- sortBy::(Ord a)=>(a->a->Bool)->[a]->[a]
- sortBy f []=[]
- sortBy f xs=(minl f xs):sortBy f (remove (minl f xs) xs)
- --9 github
- replicate'::[a]->Int->[a]
- replicate' xs n=replicatef xs n n
- replicatef::[a]->Int->Int->[a]
- replicatef [] n originalN=[]
- replicatef (x:xs) n originalN
- |n==0=replicatef xs originalN originalN
- |otherwise=x: replicatef (x:xs) (n-1) originalN
- --16.01
- --[1,2,3,4,5]->[[1,2],[3,4],[5]]
- lis2::[Int]->[[Int]]
- lis2 []=[]
- lis2 [x]=[[x]]--ne moje da e samo [x] t.k ako ostava samo edin element ne stigame do prazniq spisuk i shte stane [1,2]:[3,4]:[5] koeto -----nishto ne dava
- --lis2 (x:y:xs)=[x:y:[]]++lis2 xs
- --lis2 (x:y:xs)=(x:y:[]):lis2 xs--moje samo [x,y] vmesto (x:y:[])
- lis2 xs=[take 2 xs]++lis2 (drop 2 xs)
- http://zvon.org/other/haskell/Outputprelude/foldl_f.html
- func::[(Int,Int)]->(Int,Int)
- func xs=(minimum (map fst xs),maximum (map snd xs))
- -- [(1,5), (6, 50)...]->(1,50) minimalnata 1va chast na 2ka i maksimalnata 2ra chast
- preff::[a]->[[a]]
- preff xs=[take x xs| x<-[1..length xs]]
- --[1,2,3]->[[1],[1,2],[1,2,3]]
- suff::[a]->[[a]]
- suff xs=[drop x xs| x<-[0..length xs-1]]
- --[1,2,3]->[[1,2,3],[2,3],[3]]
- f::[a]->[[a]]
- f xs=[take x xs| x<-[length xs,length xs-1..1]]
- --[1,2,3]->[[1,2,3],[1,2],[1]]
- sublist::(Eq a)=>[a]->[a]->Bool
- sublist xs []=False
- sublist xs ys=elem xs (preff ys)|| elem xs (suff ys)||sublist xs (tail ys)
- --sublist xs ys=
- --dali [2,3] e v [1,2,3,4]->true
- 18.01
- permutations::(Eq a) => [a]->[[a]]
- permutations[]=[[]]
- --permutations[x]=[[x]]
- --permutations [x,y]=[[x,y],[y,x]]
- permutations xs=[i:j|i<-xs,j<-permutations(delete xs i)]
- --[x:ys|x<-xs,ys<-perm(deletex xs)]
- delete::(Eq a)=>[a]->a->[a]
- delete [] z=[]
- delete (x:xs) z
- |x==z=xs
- |otherwise=x:delete xs z
- grayCode::Int->[[Int]]
- grayCode 0=[[]]
- grayCode x=(map (0:) lessGray)++ (map (1:) lessGray)
- where lessGray=grayCode(x-1)
- --GoldBach Every even integer greater than 2 can be expressed as the sum of two primes.[
- prime::Int->Bool
- prime 1=False
- prime 2=True
- prime x
- |null [i|i<-[2,3..x-1],divides x i]=True
- |otherwise=False
- divides::Int->Int->Bool
- divides x y
- |x`mod` y==0=True
- |otherwise=False
- --returns a list of prime numbers
- generatePrimes::Int->[Int]
- generatePrimes max=[i|i<-[2..max],prime i]
- --or we can do this in this way but it doesn't work
- --primeToList::Int->[Int]
- --primeToList max=primeToListHelper max 1 []
- --primeToListHelper::Int->Int->[Int]->[Int]
- --primeToListHelper max start resultList
- -- |start>max=resultList
- -- |prime start==True=primeToListHelper max (start+1) start:resultList
- -- |otherwise=primeToListHelper max (start+1) resultList
- goldhelp::Int->[(Int,Int)]
- goldhelp n = [(x,y) | x <- pr, y <- pr, x+y==n]
- where pr=generatePrimes n
Add Comment
Please, Sign In to add comment