fork download
  1. import Data.List
  2.  
  3. splitWhen :: (a->Bool) -> [a] -> [[a]]
  4. splitWhen _ [] = []
  5. splitWhen f xs = first : (splitWhen f $ drop 1 $ rest)
  6. where (first,rest) = break f xs
  7.  
  8. incr :: String -> String -> Int
  9. incr lst rs@(r1:r2)
  10. | l < r && z = 10^(length rs)
  11. | l < r = 0
  12. | difL == [] = difPow
  13. | read difR > r = bigL 1
  14. | otherwise = bigL 0
  15. where ls = dropWhile (=='0') lst
  16. l = read ls :: Int
  17. r = read rs :: Int
  18. z = r1 == '0'
  19. (difL,difR) = splitAt ((length ls) - (length rs)) ls
  20. difPow = 10^(length rs)
  21. bigL = \n -> difPow * (read difL + n)
  22. incr _ _ = 0
  23.  
  24. parse :: [[String]] -> [Int]
  25. parse (x@(x11:x12:x13:x1s):xs) = [f1,f1+(read x13)..(recAdd + ((read x12)-1))] ++ (map (+recAdd) $ parse $ [x12]:xs)
  26. where f1 = read x11
  27. recAdd = incr x11 x12
  28. parse ((x11:x12:x1s):xs) = [read x11..(recAdd+((read x12)-1))] ++ (map (+recAdd) $ parse $ [x12]:xs)
  29. where recAdd = incr x11 x12
  30. parse ((x11:_):x2@(x21:_):xs) = read x11 : (map (+recAdd) $ parse $ x2:xs)
  31. where recAdd = incr x11 x21
  32. parse ((x11:_):xs) = [read x11]
  33. parse _ = []
  34.  
  35. main = interact $ (intercalate "\n\n").(map ((intercalate " ").(map show).parse.(map $ (filter (/= [])).splitWhen ((flip elem) ":-.")).(splitWhen (==',')))).lines
Success #stdin #stdout 0s 4784KB
stdin
1,3,7,2,4,1
1-3,1-2
1:5:2
104-2
104..02
545,64:11
stdout
1 3 7 12 14 21

1 2 3 11 12

1 3 5

104 105 106 107 108 109 110 111 112

104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202

545 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611