Run Code

API

Code Wall

Users

Misc

Feedback

Login

Theme

Privacy

Blog
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
Please
log in
to post a comment.
project euler 7, haskell
Factorial in haskell
pascal triangle
equiv
Split into n distinct parts
tried some polynoms 2: now with some `*` and foldr(p)
(‿‿)
haskell_exam_demo
haskell_exam
Semilattice
stackse  search stackoverflow differently
Please log in to post a comment.