tasks a-s

This commit is contained in:
Ingy döt Net 2013-04-10 23:57:08 -07:00
parent 47bf37c096
commit b83f433714
12433 changed files with 156208 additions and 123 deletions

View file

@ -0,0 +1,13 @@
import Data.List (intercalate)
extractRange :: [Int] -> String
extractRange = intercalate "," . f
where f :: [Int] -> [String]
f (x1 : x2 : x3 : xs) | x1 + 1 == x2 && x2 + 1 == x3
= (show x1 ++ '-' : show xn) : f xs'
where (xn, xs') = g (x3 + 1) xs
g a (n : ns) | a == n = g (a + 1) ns
| otherwise = (a - 1, n : ns)
g a [] = (a - 1, [])
f (x : xs) = show x : f xs
f [] = []

View file

@ -0,0 +1,2 @@
> extractRange $ [0..2] ++ 4 : [6..8] ++ 11 : 12 : [14..25] ++ [27..33] ++ [35..39]
"0-2,4,6-8,11,12,14-25,27-33,35-39"