Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
haskell_exam
-- 1.(a) f a b = sum [x | (x, y) <- zip a b, x `mod` y == 0] -- 1.(b) g [] _ = 0 g _ [] = 0 g [x] [y] = if x `mod` y == 0 then x else 0 g (x:xs) (y:ys) = g [x] [y] + g xs ys -- 2.(a) p a | intList == [] = 0 | otherwise = maximum intList where intList = [read [x] :: Int | x <- a, x `elem` "0123456789"] -- 2.(b) q [] = 0 q [x] = if x `elem` "0123456789" then read[x] :: Int else 0 q (x:xs) = max (q [x]) (q xs) -- 2.(c) r a | intList == [] = 0 | otherwise = maximum intList where intList = [read [x] :: Int | x <- filter (`elem` "0123456789") a] -- 3.(a) data Move = Go Int -- move the given distance in the current direction | Turn -- reverse direction | Dance -- dance in place, without changing direction data Command = Nil -- do nothing | Command :#: Move -- do a command followed by a move type Position = Int data Direction = L | R deriving (Show,Eq) type State = (Position, Direction) --isFacingLeft L = True --isFacingLeft R = False reverseDirection L = R reverseDirection R = L state :: Move -> State -> State state (Go x) (p, d) = if d == L then (p - x, L) else (p + x, R) state Turn (p, d) = (p, reverseDirection d) state Dance s = s -- 3.(b) trace :: Command -> State -> [State] trace Nil s = [s] --trace m s = [state m s] main = print $ state Dance (4,R)
run
|
edit
|
history
|
help
0
Modeling algebraic understanding with Haskell in KS1
Sierpinski Triangle as lazy list
Traversable
project euler 9, haskell
ex3
Znajdz trójkąty prostokątne
Métodos simples
project euler 4, haskell
NQueens
Token