From 8d5a356c8ee0f6c4f40ee40fd2b89ca248cc92c3 Mon Sep 17 00:00:00 2001 From: Jan Sucan Date: Sat, 11 Mar 2023 13:47:15 +0100 Subject: 3_b_4: Add solution --- README.md | 2 +- ch03/3_b_4.hs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 ch03/3_b_4.hs diff --git a/README.md b/README.md index 0157c7f..4ffc8f3 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ more visible in the list the first exercise of a group is in bold italics. | **_3_b_1_** | yes | 69 | | | 3_b_2 | yes, in 3_b_1 | | | | 3_b_3 | yes | | | -| 3_b_4 | | | | +| 3_b_4 | yes | | | | 3_b_5 | | | | | 3_b_6 | | 70 | | | 3_b_7 | | | | 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] -- cgit v1.2.3