more
This commit is contained in:
parent
0a7e277873
commit
90c5785d68
3 changed files with 31 additions and 0 deletions
1
Fib.hs
1
Fib.hs
|
|
@ -4,5 +4,6 @@ fib 1 = 1
|
|||
fib n =
|
||||
fib (n-2) + fib (n-1)
|
||||
|
||||
main :: IO ()
|
||||
main =
|
||||
print (fib 10)
|
||||
|
|
|
|||
16
Hanoi.hs
Normal file
16
Hanoi.hs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
data Tower = First | Middle | Last deriving Show
|
||||
|
||||
data Instruction = Move Tower Tower deriving Show
|
||||
|
||||
-- show :: Instruction -> String
|
||||
-- show Move from to = "Moving " ++ show from ++ " to " ++ show to
|
||||
|
||||
solve :: Tower -> Tower -> Tower -> Integer -> [Instruction]
|
||||
solve _ _ _ 0 = []
|
||||
solve from over to n = solve from to over (n - 1) ++ [Move from to] ++ solve over from to (n - 1)
|
||||
|
||||
main :: IO ()
|
||||
main = let
|
||||
solution = solve First Middle Last 4
|
||||
in
|
||||
print solution
|
||||
14
LinkedList.hs
Normal file
14
LinkedList.hs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
data LinkedList a = Empty | Cons a (LinkedList a)
|
||||
|
||||
cons :: a -> LinkedList a -> LinkedList a
|
||||
cons elem list = Cons elem list
|
||||
|
||||
first :: LinkedList a -> Maybe a
|
||||
first Empty = Nothing
|
||||
first (Cons first _) = Just first
|
||||
|
||||
main :: IO ()
|
||||
main =
|
||||
let
|
||||
a = Empty
|
||||
in print "asdf"
|
||||
Loading…
Add table
Add a link
Reference in a new issue