diff options
author | William Carroll <wpcarro@gmail.com> | 2020-01-15T14·23+0000 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-01-15T14·23+0000 |
commit | b4ee283b23b8a85c75339e07b0adf43d1c3ca770 (patch) | |
tree | 91fdf59f0646c66b9ccb03710056cc798fb96905 /crack_the_coding_interview/to_tree.hs | |
parent | 456d358cd7b0701b0ca2b8571d61f255d3da1488 (diff) |
Add "Crack the Coding Interview" examples
I believe I have multiple other snippets and attempts scattered across /tmp, ~/programming, and other directories. Again, I created these files and others before the mono-repo.
Diffstat (limited to 'crack_the_coding_interview/to_tree.hs')
-rw-r--r-- | crack_the_coding_interview/to_tree.hs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/crack_the_coding_interview/to_tree.hs b/crack_the_coding_interview/to_tree.hs new file mode 100644 index 000000000000..8496d88c0c0c --- /dev/null +++ b/crack_the_coding_interview/to_tree.hs @@ -0,0 +1,11 @@ +data Tree a = Node a [Tree a] deriving (Show) + +withRoot :: [a] -> [Tree a] +withRoot xs = xs |> toThing |> fmap buildTree + +buildTree :: (a, [a]) + + +toTree :: [a] -> Tree a +toTree [x] = Node x [] +toTree [x | xs] = Node x (toTree xs) |