Browse Source

Merge branch 'exo'

From slide 30 to slide 37
DricomDragon 5 years ago
parent
commit
5e01e75874
3 changed files with 29 additions and 0 deletions
  1. 23 0
      listfct.hs
  2. 3 0
      myflip.hs
  3. 3 0
      tripy.hs

+ 23 - 0
listfct.hs

@@ -0,0 +1,23 @@
+-- Reverse list order
+myexchanger xs zs = case xs of
+	[] -> zs
+	y:ys -> myexchanger ys (y:zs)
+
+myreverse xs = myexchanger xs []
+
+-- Delete the first item
+mydelete l y = case l of
+	[] -> []
+	x:xs -> if x == y then xs else x:(mydelete xs y)
+
+-- Find the maximum
+mymaximum l = mymaximumof l 0
+
+mymaximumof l x = case l of
+	[] -> x
+	y:ys -> if y > x then mymaximumof ys y else mymaximumof ys x
+
+-- Sort the list
+trimax l = if l == []
+	then []
+	else let y = mymaximum l in y:(trimax (mydelete l y))

+ 3 - 0
myflip.hs

@@ -0,0 +1,3 @@
+myflip::(a -> a -> b) -> a -> a -> b
+
+myflip f a1 a2 = f a2 a1

+ 3 - 0
tripy.hs

@@ -0,0 +1,3 @@
+square n = [(x, x * x) | x <- [1..n], x * x > 10]
+
+tripy n = [(a, b, c) | a <- [0..(div n 3)], b <- [(a + 1)..(div n 2)], c <- [(b + 1)..n], a^2 + b^2 == c^2, a + b + c == n]