From f483de8747881a90f38aee72350f293c5c2d3327 Mon Sep 17 00:00:00 2001 From: Mysaa Date: Mon, 10 Jan 2022 09:19:12 +0100 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20fonctions=20oubli=C3=A9es=20dans?= =?UTF-8?q?=20fstfunc.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fstfunc.hs | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/fstfunc.hs b/fstfunc.hs index 1214874..e967b76 100644 --- a/fstfunc.hs +++ b/fstfunc.hs @@ -164,6 +164,107 @@ modifStrings l = [ case s of { _ -> [last s] } | 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 magnitude :: Vector -> Float