From a19ead443386ff165fd19efa6b43aabb2f9a28f4 Mon Sep 17 00:00:00 2001 From: Harad Date: Mon, 7 Mar 2011 19:32:54 +0100 Subject: [PATCH 1/2] Kata 1 en Haskell. --- harad/kata1.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 harad/kata1.hs diff --git a/harad/kata1.hs b/harad/kata1.hs new file mode 100644 index 0000000..6586093 --- /dev/null +++ b/harad/kata1.hs @@ -0,0 +1,14 @@ +add :: String -> Int +add "" = 0 +add ('/':'/':separator:'\n':ys) = foldl (\acc x -> acc + read x) 0 (tokens ys separator) +add xs = add ("//,\n" ++ xs) + +tokens xs separator + | head xs == '-' && separator /= '-' = + let func x = (if x=="" then " " else '-':(head x):[]) + in error ("Negatives not allowed:" ++ + cfoldl (\acc x -> acc ++ func x) "" (tokens xs '-')) + | ',' `notElem` xs && '\n' `notElem` xs && separator `notElem` xs = [xs] + | otherwise = let + (x,y) = span (\x -> if x /= ',' && x /= '\n' && x /= separator then True else False) xs + in x:tokens (tail y) separator \ No newline at end of file From 0acbb2f84a7821ce63e71783077f004c189dcb8c Mon Sep 17 00:00:00 2001 From: Harad Date: Mon, 7 Mar 2011 20:51:16 +0100 Subject: [PATCH 2/2] =?UTF-8?q?Corregido=20un=20peque=C3=B1o=20typo.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- harad/kata1.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/harad/kata1.hs b/harad/kata1.hs index 6586093..98b21e3 100644 --- a/harad/kata1.hs +++ b/harad/kata1.hs @@ -7,8 +7,8 @@ tokens xs separator | head xs == '-' && separator /= '-' = let func x = (if x=="" then " " else '-':(head x):[]) in error ("Negatives not allowed:" ++ - cfoldl (\acc x -> acc ++ func x) "" (tokens xs '-')) + foldl (\acc x -> acc ++ func x) "" (tokens xs '-')) | ',' `notElem` xs && '\n' `notElem` xs && separator `notElem` xs = [xs] | otherwise = let (x,y) = span (\x -> if x /= ',' && x /= '\n' && x /= separator then True else False) xs - in x:tokens (tail y) separator \ No newline at end of file + in x:tokens (tail y) separator