Skip to content

Commit

Permalink
I HATE EVERYTING.
Browse files Browse the repository at this point in the history
Thomasvdam committed Jun 11, 2014
0 parents commit 0fc3199
Showing 5 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions 1.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Find the last element of a list.

myLast :: [a] -> a
myLast [x] = x
myLast (_:xs) = myLast xs

main = print (myLast [1..10])
7 changes: 7 additions & 0 deletions 2.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Find the last but one element of a list.

myButLast :: [a] -> a
myButLast [x,y] = x
myButLast (_:xs) = myButLast xs

main = print (myButLast [1..10])
7 changes: 7 additions & 0 deletions 3.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- Find the K'th element of a list. The first element in the list is number 1.

elementAt :: [a] -> Int -> a
elementAt (x:_) 1 = x
elementAt (_:xs) y = elementAt xs (y - 1)

main = print (elementAt "Haskell" 5)
1 change: 1 addition & 0 deletions 4.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- Find the number of elements of a list.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.PHONY: all clean

all: clean

clean:
find . -type f -not -name '*.hs' -not -name 'Makefile' -not -path './.git/*' | xargs rm -f

0 comments on commit 0fc3199

Please sign in to comment.