Skip to content

Instantly share code, notes, and snippets.

@WillNess
Last active December 15, 2015 00:59
Show Gist options
  • Save WillNess/5177263 to your computer and use it in GitHub Desktop.
Save WillNess/5177263 to your computer and use it in GitHub Desktop.
split l-o-n into chunks of consecutive numbers areas
-- http://stackoverflow.com/questions/10368835/partitioning-a-list-in-racket
foldr (\x r-> case r of [] -> [[x]]; ((a:_):_) | x+1 /= a -> [x]:r; (b:c) -> ((x:b):c)) []
-- or, MUCH preferred, TRMC:
foldr (\x r-> let (b:c)=case r of {[] -> [[]]; ((a:_):_) | x+1 /= a -> []:r; _ -> r} in ((x:b):c)) []
-- [1,2,3,5,6,8,9] ==> [[1,2,3],[5,6],[8,9]]
@WillNess
Copy link
Author

WillNess commented Sep 1, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment