Skip to content
This repository has been archived by the owner on Feb 13, 2020. It is now read-only.

Commit

Permalink
Week 5 done
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalwoerde committed Oct 11, 2013
1 parent a695c94 commit 1355608
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Week 5/Flipper.icl
@@ -0,0 +1,8 @@
module Flipper

import StdEnv

//Start = ( (+) 4 2, flip (+) 4 2 )// 6,6
//Start = ( (-) 4 2, flip (-) 4 2 ) // 2, -2
//Start = ( (*) 4 2, flip (*) 4 2 ) // 8, 8
//Start = ( (/) 4 2, flip (/) 4 2 ) // 2, 0
34 changes: 34 additions & 0 deletions Week 5/Origami.icl
@@ -0,0 +1,34 @@
module Origami

import StdEnv

sum` :: [Int] -> Int
sum` x = foldr (+) 0 x

prod` :: [Int] -> Int
prod` x = foldr (*) 1 x

flatten` :: [[a]] -> [a]
flatten` x = foldr (++) [] x

length` :: [a] -> Int
length` x = foldr (\_ n = n + 1) 0 x

reverse` :: [a] -> [a]
reverse` a = foldl (\xs x = [x] ++ xs) [] a

takeWhile` :: (a -> Bool) [a] -> [a]
takeWhile` a b = foldr (\x xs = if (a x) [x:xs] []) [] b

maxList` :: [a] -> a | Ord a
maxList` x = foldr max (hd x) x

Start = and
[ sum` [1 .. 5] == sum [1 .. 5]
, prod` [1 .. 5] == prod [1 .. 5]
, flatten` [[],[1],[1,2],[1,2,3]] == flatten [[],[1],[1,2],[1,2,3]]
, length` [1 .. 5] == length [1 .. 5]
, reverse` [1 .. 5] == reverse [1 .. 5]
, takeWhile` ((<>) 0) [1,2,3,0,4,5,6] == takeWhile ((<>) 0) [1,2,3,0,4,5,6]
, maxList` [1 .. 5] == maxList [1 .. 5]
]

0 comments on commit 1355608

Please sign in to comment.