Search code examples
sortinghaskellintdigits

Check if number has its digits in order


I am trying to check if, given any number, its digits are in order. Example:

1479 -> TRUE

1293 -> FALSE

Is there a proper way to do this in Haskell? I am new to the language and feel really lost at the moment. Thank you.


Solution

  • My idea is this:

    ordenado n
       | mod n 10 > mod (div n 10) 10 = ordenado (div n 10)
       | n == 0 = True
       | otherwise = False