From a7d7542dc646a5fd124ef71e71ce260889f1701b Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 2 Feb 2016 19:24:50 +0100 Subject: Moved to 1415 directory --- 1415/fp2/week3/mart/GetallenRaden.icl | 52 +++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 1415/fp2/week3/mart/GetallenRaden.icl (limited to '1415/fp2/week3/mart/GetallenRaden.icl') diff --git a/1415/fp2/week3/mart/GetallenRaden.icl b/1415/fp2/week3/mart/GetallenRaden.icl new file mode 100644 index 0000000..c1b2bb0 --- /dev/null +++ b/1415/fp2/week3/mart/GetallenRaden.icl @@ -0,0 +1,52 @@ +// Mart Lubbers s4109503, Camil Staps s4498062 + +module GetallenRaden + +import StdEnv +import StdDynamic, StdDynamicFileIO +import StdFileSelect + +// Example generation program +//fib :: [Int] +//fib = [fib` i \\ i <- [0..]] +// where +// fib` 0 = 0 +// fib` 1 = 1 +// fib` n = fib` (n-1) + fib` (n-2) +// +//Start :: *World -> (Bool, *World) +//Start world = writeDynamic "fib" (dynamic fib) world + +makeSeq :: Dynamic -> [Int] +makeSeq (x :: [Int]) = x +makeSeq _ = abort "You selected a file not containing a sequence" + +basename :: String Int -> String +basename s 0 = toString s.[0] +basename s n = let c = toString s.[n] in if (c == "\\") "" ((basename s (n-1)) +++ c) + +loadSeq :: String *World -> *([Int], String, *World) +loadSeq s world +# s = let l = size s in s % (0, l-5) +# (ok, dyn, world) = readDynamic s world +| not ok = abort "You didn't select a dynamic file" +| otherwise = (makeSeq dyn, basename s ((size s)-1), world) + +play :: *File String [Int] Int Int -> *File +play io _ _ _ 5 = io <<< "Congratulations, you had 5 correct answers\n" +play io seqname [nextnum:sequence] currentnum correct +# io = io <<< (seqname +++ "[" +++ toString currentnum +++ "] = " +++ toString nextnum +++ "\n") +# (ok, guessednumber, io) = freadi io +| not ok = play (snd (freadline io)) seqname sequence (currentnum + 1) correct +# (io, correct) = if (guessednumber == hd sequence) (io, correct+1) (io <<< "Incorrect...\n", correct) += play (snd (freadline io)) seqname sequence (currentnum + 1) correct + +Start :: *World -> *World +Start world +# (inputfilepath, world) = selectInputFile world +| isNothing inputfilepath = abort "Please select a file" +# (sequence, sequencename, world) = loadSeq (fromJust inputfilepath) world +# (io, world) = stdio world +# io = (play io sequencename sequence 0 0) <<< "Press any key to close" +# (_, world) = fclose io world += world -- cgit v1.2.3