blob: aaae87c3bc375609aee0b9c3806c74d3d693d10b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
module Main where
import Input
main :: IO ()
main = do
input <- head <$> getInput 4
let (low', high') = fmap tail (span (/= '-') input)
(low, high) = (read low', read high') :: (Int, Int)
rdigits 0 = []
rdigits n = n `mod` 10 : rdigits (n `div` 10)
rdigitpairs n = let l = rdigits n in zip l (tail l)
has2digit n = any (uncurry (==)) (rdigitpairs n)
nondecrease n = all (uncurry (>=)) (rdigitpairs n)
acceptable n = has2digit n && nondecrease n
print (length (filter acceptable [low..high]))
let has2digit' [] = False
has2digit' (a:b:c:xs) | a == b, b == c = has2digit' (dropWhile (== a) xs)
has2digit' (a:b:_) | a == b = True
has2digit' (_:xs) = has2digit' xs
acceptable' n = has2digit' (rdigits n) && nondecrease n
print (length (filter acceptable' [low..high]))
|