aboutsummaryrefslogtreecommitdiff
path: root/challenge-061
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2020-05-19 23:54:59 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2020-05-19 23:54:59 +0100
commit1ce81cee438a8ece2ade5cbd25e889b54fe9c1f6 (patch)
tree281ef7e60a94a5c11036fc277806cf19dd8c1ddb /challenge-061
parentf0b99b16edf1e0dd3be5bfe49b6922322631c872 (diff)
downloadperlweeklychallenge-club-1ce81cee438a8ece2ade5cbd25e889b54fe9c1f6.tar.gz
perlweeklychallenge-club-1ce81cee438a8ece2ade5cbd25e889b54fe9c1f6.tar.bz2
perlweeklychallenge-club-1ce81cee438a8ece2ade5cbd25e889b54fe9c1f6.zip
- Added Haskell solutions by Ulrich Rieke.
Diffstat (limited to 'challenge-061')
-rw-r--r--challenge-061/ulrich-rieke/haskell/ch-1.hs18
-rw-r--r--challenge-061/ulrich-rieke/haskell/ch-2.hs28
2 files changed, 46 insertions, 0 deletions
diff --git a/challenge-061/ulrich-rieke/haskell/ch-1.hs b/challenge-061/ulrich-rieke/haskell/ch-1.hs
new file mode 100644
index 0000000000..711eaf57d0
--- /dev/null
+++ b/challenge-061/ulrich-rieke/haskell/ch-1.hs
@@ -0,0 +1,18 @@
+module Challenge061
+ where
+import Data.List ( sortOn )
+
+findSublist :: Int -> Int -> [a] -> [a]
+findSublist from to list = take ( to - from ) $ drop from list
+
+allcontiguousSublists :: [Int] -> [[Int]]
+allcontiguousSublists numbers = [ findSublist start end numbers | start
+<- [0..len - 1 ], end <- [start + 1..len]]
+where
+ len = length numbers
+
+findMaximumSublist :: [Int] -> (Int, [Int] )
+findMaximumSublist numbers =
+ let contiguous = allcontiguousSublists numbers
+ productlist = map (\li -> ( product li , li )) contiguous
+ in last $ sortOn fst productlist
diff --git a/challenge-061/ulrich-rieke/haskell/ch-2.hs b/challenge-061/ulrich-rieke/haskell/ch-2.hs
new file mode 100644
index 0000000000..cf31b294d5
--- /dev/null
+++ b/challenge-061/ulrich-rieke/haskell/ch-2.hs
@@ -0,0 +1,28 @@
+module Challenge061_2
+ where
+import Data.List.Split ( splitPlaces )
+import Data.List ( intercalate )
+
+isValidOctet :: String -> Bool
+isValidOctet s = number >= 0 && number <= 255
+ where
+ number = read s
+
+findCombinations :: Int -> [[Int]]
+findCombinations len = [[a, b , c , d] | a <- [1..3] , b <- [1..3] ,
+c <- [1..3] , d <- [1..3] , a + b + c + d == len]
+
+possibleIPs :: String -> [String]
+possibleIPs input =
+ let len = length input
+ inputsplits = map (\li -> splitPlaces li input ) $ findCombinations len
+ iplists = filter (\spl -> all(\letters -> isValidOctet letters) spl )
+ inputsplits
+ in map (\st -> intercalate "." st ) iplists
+
+validIPs :: String -> [String]
+validIPs ip
+ |len < 4 || len > 12 = []
+ |otherwise = possibleIPs ip
+ where
+ len = length ip