You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
454 B
19 lines
454 B
4 years ago
|
import Data.List
|
||
|
|
||
|
digits :: Int -> [Int]
|
||
|
digits n = unfoldr nextDigit n where
|
||
|
nextDigit 0 = Nothing
|
||
|
nextDigit c = Just $ (c `mod` 10, c `div` 10)
|
||
|
|
||
|
isSorted :: Int -> Bool
|
||
|
isSorted n = (all (uncurry (<=)) ds') || (all (uncurry (>=)) ds'')
|
||
|
where ds = digits n
|
||
|
ds' = zip ds (maxBound : ds)
|
||
|
ds'' = zip ds (minBound : ds)
|
||
|
|
||
|
main = do
|
||
|
print $ isSorted 123456
|
||
|
print $ isSorted 1234561
|
||
|
print $ isSorted 97541
|
||
|
print $ isSorted 99431
|