Ajout de fonctions oubliées dans fstfunc.c
This commit is contained in:
parent
ac1d6b24e2
commit
f483de8747
101
fstfunc.hs
101
fstfunc.hs
@ -164,6 +164,107 @@ modifStrings l = [ case s of {
|
|||||||
_ -> [last s]
|
_ -> [last s]
|
||||||
} | s<-l]
|
} | s<-l]
|
||||||
|
|
||||||
|
allMin :: Ord a => [a] -> a
|
||||||
|
allMin [e] = e
|
||||||
|
allMin (e:s) = min e (allMin s)
|
||||||
|
|
||||||
|
fact :: Num a => Eq a => a -> a
|
||||||
|
fact 0 = 1
|
||||||
|
fact n = n*(fact (n-1))
|
||||||
|
|
||||||
|
replicate' :: (Num i, Ord i) => i -> a -> [a]
|
||||||
|
replicate' n x
|
||||||
|
| n <= 0 = [ ]
|
||||||
|
| otherwise = x : replicate' (n - 1) x
|
||||||
|
|
||||||
|
ssum :: Num a => [a] -> a
|
||||||
|
ssum [] = 0
|
||||||
|
ssum (e:s) = e+(ssum s)
|
||||||
|
|
||||||
|
ppea :: Ord a => a -> [a] -> [a]
|
||||||
|
ppea x [] = []
|
||||||
|
ppea x (e:s)
|
||||||
|
| e<=x = e:(ppea x s)
|
||||||
|
| otherwise = (ppea x s)
|
||||||
|
|
||||||
|
pgq :: Ord a => a -> [a] -> [a]
|
||||||
|
pgq x [] = []
|
||||||
|
pgq x (e:s)
|
||||||
|
| e>x = e:(pgq x s)
|
||||||
|
| otherwise = (pgq x s)
|
||||||
|
|
||||||
|
triPivot :: Ord a => [a] -> [a]
|
||||||
|
triPivot [] = []
|
||||||
|
triPivot (x:s) = (triPivot (ppea x s)) ++ [x] ++ (triPivot (pgq x s))
|
||||||
|
|
||||||
|
apply3 :: (a -> a) -> a -> a
|
||||||
|
apply3 f x = f (f (f x))
|
||||||
|
|
||||||
|
applyN :: Int -> (a->a) -> a -> a
|
||||||
|
applyN 0 f x = x
|
||||||
|
applyN n f x = f (applyN (n-1) f x)
|
||||||
|
|
||||||
|
myMap :: (a -> b) -> [a] -> [b]
|
||||||
|
myMap f l = [f x | x <- l]
|
||||||
|
|
||||||
|
myMap2 :: (a->b)->[a]->[b]
|
||||||
|
myMap2 f [] = []
|
||||||
|
myMap2 f (e:s) = (f e):(myMap2 f s)
|
||||||
|
|
||||||
|
myFilter :: (a -> Bool) -> [a] -> [a]
|
||||||
|
myFilter f [] = []
|
||||||
|
myFilter f (e:s)
|
||||||
|
| f e = e:(filter f s)
|
||||||
|
| otherwise = filter f s
|
||||||
|
|
||||||
|
myZipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
|
||||||
|
myZipWith o l l' = map applicateur (zip l l')
|
||||||
|
where applicateur (x,y) = o x y
|
||||||
|
|
||||||
|
minimum' :: [Float] -> Float
|
||||||
|
minimum' [e] = e
|
||||||
|
minimum' (e:s) = min e (minimum' s)
|
||||||
|
|
||||||
|
minimum'' :: [Float] -> Float
|
||||||
|
minimum'' (u:l) = go l u
|
||||||
|
where go [] x = x
|
||||||
|
go (e:s) x
|
||||||
|
| e>x = go s x
|
||||||
|
| otherwise = go s e
|
||||||
|
|
||||||
|
|
||||||
|
and' :: [Bool] -> Bool
|
||||||
|
and' [] = True
|
||||||
|
and' (e:s) = e && (and' s)
|
||||||
|
|
||||||
|
and'' :: [Bool] -> Bool
|
||||||
|
and'' l = go l True
|
||||||
|
where go [] x = x
|
||||||
|
go (e:s) x = go s (e && x)
|
||||||
|
|
||||||
|
reduce :: (t->t->t) -> [t] -> t
|
||||||
|
reduce f [e] = e
|
||||||
|
reduce f (e:s) = f e (reduce f s)
|
||||||
|
|
||||||
|
reduce' :: (t->t->t) -> [t] -> t
|
||||||
|
reduce' f (e:s) = go s e
|
||||||
|
where go [] x = x
|
||||||
|
go (h:t) x = go t (f h x)
|
||||||
|
|
||||||
|
rminimum l = reduce' min l
|
||||||
|
rand l = reduce' (&&) l
|
||||||
|
|
||||||
|
reduceTotal :: (t->t->t) -> t -> [t] -> t
|
||||||
|
reduceTotal f x0 [] = x0
|
||||||
|
reduceTotal f x0 (e:s) = f e (reduceTotal f x0 s)
|
||||||
|
|
||||||
|
reduceTotal' :: (t->t->t) -> t -> [t] -> t
|
||||||
|
reduceTotal' f x0 l = go l x0
|
||||||
|
where go [] x = x
|
||||||
|
go (h:t) x = go t (f h x)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data Vector = Vec3 Float Float Float
|
data Vector = Vec3 Float Float Float
|
||||||
|
|
||||||
magnitude :: Vector -> Float
|
magnitude :: Vector -> Float
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user