Skip to content

Instantly share code, notes, and snippets.

@be5invis
Created March 29, 2012 12:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save be5invis/2236963 to your computer and use it in GitHub Desktop.
Save be5invis/2236963 to your computer and use it in GitHub Desktop.
Answer for Ninputer: merge spaces
def rest(s) = s.slice 1
def mergeSpaces(s) = phase_normal s
where phase_normal(s) = piecewise
when(not s) s
when(s[0] == ' ') s[0] + phase_space rest s
otherwise s[0] + phase_normal rest s
phase_space(s) = piecewise
when(not s) s
when(s[0] == ' ') phase_space rest s
otherwise s[0] + phase_normal rest s
trace mergeSpaces 'abc def'
trace mergeSpaces 'abc def'
trace mergeSpaces 'a bcd ef'
trace ('[' + mergeSpaces ' ' + ']')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment