Skip to content

Instantly share code, notes, and snippets.

@apua
Created August 10, 2015 14:08
Show Gist options
  • Save apua/d2f981d34621c95f63ae to your computer and use it in GitHub Desktop.
Save apua/d2f981d34621c95f63ae to your computer and use it in GitHub Desktop.
-- > toChunks "qwer1234asdf" 5
-- ["qwer1","234as","df000"]
toChunks "" _ = []
toChunks str len = ch:toChunks str' len
where (ch, str') = get len str
get len str = if len==0 then ("", str) else (head:chunk, str')
where (head, tail) = pop str
(chunk, str') = get (len-1) tail
pop "" = (fill,"")
pop (v:vs) = (v,vs)
fill = '0'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment