Skip to content

Instantly share code, notes, and snippets.

@awave1
Created January 30, 2020 03:35
Show Gist options
  • Save awave1/cc03249d6686d5bc23f16f06a2415e00 to your computer and use it in GitHub Desktop.
Save awave1/cc03249d6686d5bc23f16f06a2415e00 to your computer and use it in GitHub Desktop.
group :: (a -> a -> Bool) -> [a] -> [[a]]
group _ [] = []
group _ [el] = [[el]]
group predicate (a : b : list)
| predicate a b = append a (group predicate (b : list))
| otherwise = [a] : group predicate (b : list)
where append el (a : list) = (el : a) : list
nbr :: Int -> Int -> Bool
nbr num1 num2 = abs (num1 - num2) <= 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment