Skip to content

Instantly share code, notes, and snippets.

@honzabrecka
Last active August 3, 2017 10:17
Show Gist options
  • Save honzabrecka/e225dc3cdb8f2bdae445c7c5fd067385 to your computer and use it in GitHub Desktop.
Save honzabrecka/e225dc3cdb8f2bdae445c7c5fd067385 to your computer and use it in GitHub Desktop.
module Problem1 where
import Prelude
import Data.List
isIncreasing :: List Int -> Boolean
isIncreasing Nil = true
isIncreasing (_ : Nil) = true
isIncreasing (x : y : ys) | x < y = isIncreasing (y : ys)
| otherwise = false
isPossibleIncreasing :: List Int -> Boolean
isPossibleIncreasing l = inner 0 l
where
inner :: Int -> List Int -> Boolean
inner _ Nil = true
inner _ (_ : Nil) = true
inner n (x : y : ys) | x < y = inner x (y : ys)
| x > n = isIncreasing(x : ys)
| y > n = isIncreasing(y : ys)
| otherwise = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment