diff options
| author | Mart Lubbers | 2015-04-16 21:22:20 +0200 | 
|---|---|---|
| committer | Mart Lubbers | 2015-04-16 21:22:20 +0200 | 
| commit | 6f604b19d3f5966e5c1d7c4fdf3703bd6ff0861c (patch) | |
| tree | 96d580507249f7f58368476d9113007d4afcd748 /fp1/week1/camil | |
| parent | Added student numbers (diff) | |
update to fp2 yay, public and licence
Diffstat (limited to 'fp1/week1/camil')
| -rw-r--r-- | fp1/week1/camil/1.1/Start.icl | 18 | ||||
| -rw-r--r-- | fp1/week1/camil/1.1/antwoorden.txt | 29 | ||||
| -rw-r--r-- | fp1/week1/camil/2.1/NotatieFuncties.icl | 39 | ||||
| -rw-r--r-- | fp1/week1/camil/2.1/antwoorden.txt | 8 | ||||
| -rw-r--r-- | fp1/week1/camil/2.11/BottlesOfBeer.icl | 21 | ||||
| -rw-r--r-- | fp1/week1/camil/2.2/VindtDeRedex.icl | 17 | ||||
| -rw-r--r-- | fp1/week1/camil/2.2/antwoorden.txt | 42 | ||||
| -rw-r--r-- | fp1/week1/camil/2.3/MatchStrings.dcl | 8 | ||||
| -rw-r--r-- | fp1/week1/camil/2.3/MatchStrings.icl | 48 | 
9 files changed, 230 insertions, 0 deletions
| diff --git a/fp1/week1/camil/1.1/Start.icl b/fp1/week1/camil/1.1/Start.icl new file mode 100644 index 0000000..b56a850 --- /dev/null +++ b/fp1/week1/camil/1.1/Start.icl @@ -0,0 +1,18 @@ +module Start
 +
 +import StdEnv
 +
 +Start = expr11
 +
 +expr0 = "Hello World!"
 +expr1 = "Hello " +++ "World!"
 +expr2 = 5
 +expr3 = 5.5
 +//expr4 = 5 + 5.5
 +expr5 = [1..10]
 +expr6 = (expr1,expr2,expr3,expr5)
 +//expr7 = [expr1,expr2,expr3,expr5]
 +expr8 = [1,3..10]
 +expr9 = ['a'..'z']
 +expr10 = ['a','c'..'z']
 +expr11 = ['Hello World!']
\ No newline at end of file diff --git a/fp1/week1/camil/1.1/antwoorden.txt b/fp1/week1/camil/1.1/antwoorden.txt new file mode 100644 index 0000000..3a223e2 --- /dev/null +++ b/fp1/week1/camil/1.1/antwoorden.txt @@ -0,0 +1,29 @@ +Antwoorden opgave 1.1 +Camil Staps (s4498062) + +1.	Het programma wordt gecompileerd. +2.	Het programma wordt uitgevoerd. +3.	De data types van de variabelen worden automatisch achterhaald door de IDE (en hoeven dus niet expliciet te  worden gegeven door de programmeur) + +expr1	"Hello World!" +	De strings worden geconcateneerd +expr2	5 +	Dit is een Int waarde +expr3	5.5 +	Dit is een Real waarde +expr4	Type error; cannot unify types Real and Int +	Dat is omdat + is niet gedefinieerd voor Real met Int +expr5	[1,2,3,4,5,6,7,8,9,10] +	Dit is een korte schrijfwijze voor deze lijst ([min..max]) +expr6	("Hello World!",5,5.5,[1,2,3,4,5,6,7,8,9,10]) +	Een tupeltje +expr7	Type error; cannot unify types [Int] and Real +	Dat is omdat elementen van een lijst hetzelfde type moeten hebben, en dat hier niet het geval is +expr8	[1,3,5,7,9] +	Een andere vorm van expr5 waarmee in het begin wordt aangegeven wat de interval is +expr9	['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] +	Een lijst van karakters +expr10	['a','c','e','g','i','k','m','o','q','s','u','w','y'] +	Een combinatie van expr9 en expr8 +expr11	['H','e','l','l','o',' ','W','o','r','l','d','!'] +	Blijkbaar wordt ['...'] als lijst van karakters beschouwd diff --git a/fp1/week1/camil/2.1/NotatieFuncties.icl b/fp1/week1/camil/2.1/NotatieFuncties.icl new file mode 100644 index 0000000..bab2054 --- /dev/null +++ b/fp1/week1/camil/2.1/NotatieFuncties.icl @@ -0,0 +1,39 @@ +module NotatieFuncties
 +
 +import StdEnv
 +
 +f1			:: Int
 +f1			= 1 + 5
 +
 +f2			:: Int
 +f2			= (+) 1 5
 +
 +f3			:: Int Int -> Int
 +f3 m n
 +| m < n		= m
 +| otherwise	= n
 +
 +f4			:: String Int -> String
 +f4 s n
 +| n <= 0	= ""
 +| otherwise	= s +++ f4 s (n-1)
 +
 +f5			:: Int Int -> Int
 +f5 x 0		= x
 +f5 x y		= f5 y (x rem y)
 +
 +f6			:: (Int,Int) -> Int
 +f6 x		= fst x + snd x
 +
 +f7			:: (a,b) -> (b,a)
 +f7 (a,b)	= (b,a)
 +
 +f8			:: (a,a) -> (a,a)
 +f8 x		= f7 (f7 x)
 +
 +//Start		= (f3 1 5, f3 4 3, f3 6 6)
 +//Start		= f4 "ab" 4
 +//Start		= (f5 13 5, f5 8 4, f5 20 20)
 +//Start		= f6 (2,3)
 +//Start		= f7 (5,7)
 +Start		= f8 (5,7)
 diff --git a/fp1/week1/camil/2.1/antwoorden.txt b/fp1/week1/camil/2.1/antwoorden.txt new file mode 100644 index 0000000..c0c98d6 --- /dev/null +++ b/fp1/week1/camil/2.1/antwoorden.txt @@ -0,0 +1,8 @@ +f1	5+1=6; constant +f2	Reverse polix notation voor f1; zelfde functie dus +f3	Geeft de kleinste van twee integers terug +f4	Herhaalt s n keer +f5	Geeft de ggd van x en y met Euclides' algoritme +f6	Geeft de optelling x+y voor een tupel (x,y) +f7	Flipt de twee elementen van een tupel +f8	Flipt de twee elementen van een tupel twee keer (heeft geen effect) diff --git a/fp1/week1/camil/2.11/BottlesOfBeer.icl b/fp1/week1/camil/2.11/BottlesOfBeer.icl new file mode 100644 index 0000000..70628a1 --- /dev/null +++ b/fp1/week1/camil/2.11/BottlesOfBeer.icl @@ -0,0 +1,21 @@ +module BottlesOfBeer
 +
 +import StdEnv
 +
 +Start = [(fst_line x +++ "\n" +++ snd_line x +++ "\n\n") \\ x <- [99,98..0]]
 +
 +fst_line :: Int -> String
 +fst_line n = btl n True +++ wall +++ ", " +++ btl n False +++ " of beer."
 +
 +snd_line :: Int -> String
 +snd_line 0 = "Go to the store and buy some more, " +++ btl 99 False +++ wall +++ "."
 +snd_line n = "Take one down and pass it around, " +++ btl (n-1) False +++ wall +++ "."
 +
 +btl :: Int Bool -> String
 +btl 0 True = "No more bottles"
 +btl 0 False = "no more bottles"
 +btl 1 b = "1 bottle"
 +btl n b = toString n +++ " bottles"
 +
 +wall :: String
 +wall = " of beer on the wall"
\ No newline at end of file diff --git a/fp1/week1/camil/2.2/VindtDeRedex.icl b/fp1/week1/camil/2.2/VindtDeRedex.icl new file mode 100644 index 0000000..c7ec330 --- /dev/null +++ b/fp1/week1/camil/2.2/VindtDeRedex.icl @@ -0,0 +1,17 @@ +module VindtDeRedex
 +
 +import StdEnv
 +
 +e1 = 42
 +
 +e2 = 1 + 125 * 8 / 10 - 59
 +
 +e3 = not True || True && False
 +
 +e4 =  1 + 2  ==  6 - 3
 +
 +e5 = "1 + 2" == "6 - 3"
 +
 +e6 = "1111 + 2222" == "1111" +++ " + " +++ "2222"
 +
 +Start = e6
 diff --git a/fp1/week1/camil/2.2/antwoorden.txt b/fp1/week1/camil/2.2/antwoorden.txt new file mode 100644 index 0000000..413465c --- /dev/null +++ b/fp1/week1/camil/2.2/antwoorden.txt @@ -0,0 +1,42 @@ +e1 = 42 	Is elementair + +e2 = 1 + 125 * 8 / 10 - 59 +e2 = (1 + ((125 * 8) / 10)) - 59 +            ------- +e2 = (1 + (1000 / 10)) - 59 +           --------- +e2 = (1 + 100) - 59 +      ------- +e2 = 101 - 59 +     -------- +e2 = 42 + +e3 = not True || True && False +e3 = (not True) || (True && False) +      -------- +e3 = False || (True && False) +               ------------- +e3 = False || False +     -------------- +e3 = False + +e4 = 1 + 2 == 6 - 3 +e4 = (1 + 2) == (6 - 3) +      ----- +e4 = 3 == (6 - 3) +           ----- +e4 = 3 == 3 +e4 = True + +e5 = "1 + 2" == "6 - 3" +     ------------------ +e5 = False + +e6 = "1111 + 2222" == "1111" +++ " + " +++ "2222" +e6 = "1111 + 2222" == (("1111" +++ " + ") +++ "2222") +                       ----------------- +e6 = "1111 + 2222" == ("1111 + " +++ "2222") +                       -------------------- +e6 = "1111 + 2222" == "1111 + 2222" +     ------------------------------ +e6 = True diff --git a/fp1/week1/camil/2.3/MatchStrings.dcl b/fp1/week1/camil/2.3/MatchStrings.dcl new file mode 100644 index 0000000..527447c --- /dev/null +++ b/fp1/week1/camil/2.3/MatchStrings.dcl @@ -0,0 +1,8 @@ +definition module MatchStrings
 +
 +head			::        String -> Char
 +tail			::        String -> String
 +is_gelijk		:: String String -> Bool
 +is_deelstring	:: String String -> Bool
 +is_deel			:: String String -> Bool
 +is_match		:: String String -> Bool
 diff --git a/fp1/week1/camil/2.3/MatchStrings.icl b/fp1/week1/camil/2.3/MatchStrings.icl new file mode 100644 index 0000000..17859ae --- /dev/null +++ b/fp1/week1/camil/2.3/MatchStrings.icl @@ -0,0 +1,48 @@ +implementation module MatchStrings
 +
 +import StdEnv
 +
 +head				:: String -> Char
 +head ""				= abort "head uitgevoerd op lege string"
 +head s				= s.[0]
 +
 +tail				:: String -> String
 +tail ""				= abort "tail uitgevoerd op lege string"
 +tail s				= s % (1, size s - 1)
 +
 +is_gelijk			:: String String -> Bool
 +is_gelijk "" ""		= True
 +is_gelijk a ""		= False
 +is_gelijk "" b 		= False
 +is_gelijk a b		= (head a == head b) && (is_gelijk (tail a) (tail b))
 +
 +is_deelstring		:: String String -> Bool
 +is_deelstring "" b	= True
 +is_deelstring a ""	= False
 +is_deelstring a b	= is_gelijk a (b % (0, size a - 1)) || is_deelstring a (tail b)
 +
 +is_deel				:: String String -> Bool
 +is_deel "" b		= True
 +is_deel a ""		= False
 +is_deel a b			= head a == head b && is_deel (tail a) (tail b) || is_deel a (tail b)
 +
 +is_match			:: String String -> Bool
 +is_match "" ""		= True
 +is_match "" b		= False
 +is_match "*" ""		= True
 +is_match a ""		= False
 +is_match a b		= (head a == '.' || head a == head b) && is_match (tail a) (tail b) || head a == '*' && (is_match a (tail b) || is_match (tail a) b)
 +
 +//Start				= (head pink_floyd, tail pink_floyd)
 +//Start				= is_gelijk     "" " "
 +//Start				= is_deelstring "there"          pink_floyd
 +//Start				= is_deelstring "there"          marillion
 +//Start				= is_deel       "there"          marillion
 +//Start				= is_deel       "she and her"    pink_floyd
 +//Start				= is_deel       radiohead        pink_floyd
 +//Start				= is_match      "*.here*.here*." pink_floyd
 +//Start				= is_match      ".here.here."    pink_floyd
 +
 +pink_floyd			= "Is there anybody in there?"
 +marillion			= "Just for the record"
 +radiohead			= "There there"
 | 
