aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-116/stuart-little/haskell/ch-1.hs15
-rwxr-xr-xchallenge-116/stuart-little/haskell/ch-2.hs13
2 files changed, 28 insertions, 0 deletions
diff --git a/challenge-116/stuart-little/haskell/ch-1.hs b/challenge-116/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..69e1d66883
--- /dev/null
+++ b/challenge-116/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,15 @@
+#!/usr/bin/env runghc
+
+-- run <script> <number>
+
+import Data.List (inits)
+import System.Environment (getArgs)
+
+fstRunOver :: String -> String -> [String]
+fstRunOver s1 s2 = reverse $ head $ dropWhile (\xss -> (length s2) > (sum $ map length xss)) $ iterate (\xs -> (show $ (+) 1 $ (read::String->Int) $ head xs):xs) [s1]
+
+consecSplit :: String -> [String]
+consecSplit s = head $ dropWhile (\ss -> s /= concat ss) $ map (\s'-> fstRunOver s' s) $ tail $ inits s
+
+main :: IO ()
+main = getArgs >>= putStrLn . unwords . consecSplit . head
diff --git a/challenge-116/stuart-little/haskell/ch-2.hs b/challenge-116/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..048200b765
--- /dev/null
+++ b/challenge-116/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,13 @@
+#!/usr/bin/env runghc
+
+-- run <script> <number>
+
+import Data.Char (digitToInt)
+import Math.NumberTheory.Roots (isSquare)
+import System.Environment (getArgs)
+
+digSqSum :: String -> Int
+digSqSum = sum . map (\x-> x*x) . map digitToInt
+
+main :: IO ()
+main = getArgs >>= putStrLn . show . fromEnum . isSquare . digSqSum . head