summaryrefslogtreecommitdiff
path: root/70b-73
diff options
context:
space:
mode:
Diffstat (limited to '70b-73')
-rw-r--r--70b-73/70.hs16
-rw-r--r--70b-73/70b.hs3
-rw-r--r--70b-73/70c.hs7
-rw-r--r--70b-73/71.hs6
-rw-r--r--70b-73/72.hs5
-rw-r--r--70b-73/73.hs7
6 files changed, 44 insertions, 0 deletions
diff --git a/70b-73/70.hs b/70b-73/70.hs
new file mode 100644
index 0000000..69f42f5
--- /dev/null
+++ b/70b-73/70.hs
@@ -0,0 +1,16 @@
+data Tree a = Node a [Tree a] deriving (Eq, Show)
+
+stringToTree :: [Char] -> Tree Char
+
+stringToTree l = fst $ build l
+ where build (x:xs) = (Node x chd'', xs'')
+ where loop ('^':xs) = ([], xs)
+ loop xs = (chd':c, x)
+ where (chd', xs') = build xs
+ (c, x) = loop xs'
+ (chd'', xs'') = loop xs
+
+
+treeToString :: Tree Char -> [Char]
+
+treeToString (Node v xs) = v:(concat $ map treeToString xs) ++ "^"
diff --git a/70b-73/70b.hs b/70b-73/70b.hs
new file mode 100644
index 0000000..dbeb5b5
--- /dev/null
+++ b/70b-73/70b.hs
@@ -0,0 +1,3 @@
+data Tree a = Node a [Tree a] deriving (Eq, Show)
+
+-- Haskell is type-safe, so there is no solution.
diff --git a/70b-73/70c.hs b/70b-73/70c.hs
new file mode 100644
index 0000000..2a10432
--- /dev/null
+++ b/70b-73/70c.hs
@@ -0,0 +1,7 @@
+import Data.List (foldl')
+
+data Tree a = Node a [Tree a] deriving (Eq, Show)
+
+nnodes :: Tree a -> Int
+
+nnodes (Node _ xs) = 1 + (foldl' (+) 0 $ map nnodes xs)
diff --git a/70b-73/71.hs b/70b-73/71.hs
new file mode 100644
index 0000000..e99c3fe
--- /dev/null
+++ b/70b-73/71.hs
@@ -0,0 +1,6 @@
+data Tree a = Node a [Tree a] deriving (Eq, Show)
+
+ipl :: Tree a -> Int
+
+ipl = ipl' 0
+ where ipl' l (Node _ xs) = l + (sum $ map (ipl' (l + 1)) xs)
diff --git a/70b-73/72.hs b/70b-73/72.hs
new file mode 100644
index 0000000..06f2ec9
--- /dev/null
+++ b/70b-73/72.hs
@@ -0,0 +1,5 @@
+data Tree a = Node a [Tree a] deriving (Eq, Show)
+
+bottomUp :: Tree Char -> [Char]
+
+bottomUp (Node v xs) = (concat $ map bottomUp xs) ++ [v]
diff --git a/70b-73/73.hs b/70b-73/73.hs
new file mode 100644
index 0000000..0db324e
--- /dev/null
+++ b/70b-73/73.hs
@@ -0,0 +1,7 @@
+import Data.List (intersperse)
+data Tree a = Node a [Tree a] deriving (Eq, Show)
+
+display :: Tree Char -> [Char]
+
+display (Node v []) = [v]
+display (Node v xs) = '(':v:' ':(concat $ intersperse " " $ map display xs) ++ ")"