diff options
| author | Jan Sucan <jan@jansucan.com> | 2023-03-11 13:47:15 +0100 |
|---|---|---|
| committer | Jan Sucan <jan@jansucan.com> | 2023-03-11 13:47:15 +0100 |
| commit | 8d5a356c8ee0f6c4f40ee40fd2b89ca248cc92c3 (patch) | |
| tree | c4cba13bc19e75b8c4595f3d47fbaf0dfe34160b /ch03 | |
| parent | 05ff6d55f6d6b0c8691b737dea2bc160b04178e2 (diff) | |
3_b_4: Add solution
Diffstat (limited to 'ch03')
| -rw-r--r-- | ch03/3_b_4.hs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/ch03/3_b_4.hs b/ch03/3_b_4.hs new file mode 100644 index 0000000..a711085 --- /dev/null +++ b/ch03/3_b_4.hs @@ -0,0 +1,15 @@ +-- Turn a list into a palindrome, i.e. it should read the same both backwards +-- and forwards. For example, given the list [1,2,3], your function should +-- return [1,2,3,3,2,1]. + +makePalindrome :: [a] -> [a] +makePalindrome [] = [] +makePalindrome (x:xs) = [x] ++ (makePalindrome xs) ++ [x] + +-- ghci> :l 3_b_4.hs +-- [1 of 1] Compiling Main ( 3_b_4.hs, interpreted ) +-- Ok, one module loaded. +-- ghci> makePalindrome [] +-- [] +-- ghci> makePalindrome [1, 2, 3] +-- [1,2,3,3,2,1] |
