aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xchallenge-065/stuart-little/haskell/ch-1.hs13
-rwxr-xr-xchallenge-065/stuart-little/haskell/ch-2.hs23
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-065/stuart-little/haskell/ch-1.hs b/challenge-065/stuart-little/haskell/ch-1.hs
new file mode 100755
index 0000000000..b86362be24
--- /dev/null
+++ b/challenge-065/stuart-little/haskell/ch-1.hs
@@ -0,0 +1,13 @@
+#!/usr/bin/env runghc
+
+-- run <script> <digit_number digit_sum>
+
+import System.Environment (getArgs,)
+
+digSum :: Int -> Int
+digSum = sum . (map (read::String->Int)) . (map (\x -> [x])) . show
+
+main = do
+ args <- getArgs
+ let (dignr:digsum:_) = map (read::String->Int) args
+ putStrLn $ unwords $ map show $ filter ((digsum==).digSum) [10 ^ (dignr-1) .. 10 ^ dignr -1]
diff --git a/challenge-065/stuart-little/haskell/ch-2.hs b/challenge-065/stuart-little/haskell/ch-2.hs
new file mode 100755
index 0000000000..fb9273ea3d
--- /dev/null
+++ b/challenge-065/stuart-little/haskell/ch-2.hs
@@ -0,0 +1,23 @@
+#!/usr/bin/env runghc
+
+{-
+Due to the ambiguity I am choosing to interpret the task literally: 'partition' means splitting into strings that (a) are disjoint, and (b) completely cover the original string.
+
+So I will find all partitions in this sense.
+
+run <script> <string>
+-}
+
+import System.Environment (getArgs,)
+import Data.List ((\\),inits,reverse,)
+
+palPart :: String -> [[String]]
+palPart str
+ |null str =[]
+ |str == reverse str =(l++[[str]])
+ |otherwise =l
+ where l=concat $ map (\x -> map (x:) $ palPart (str \\ x)) $ filter (\x -> x == reverse x) $ tail $ inits str
+
+main = do
+ (str:_) <- getArgs
+ mapM_ putStrLn $ map unwords $ palPart str