Skip to content

Instantly share code, notes, and snippets.

@GeorgeMac
Created January 8, 2016 13:16
Show Gist options
  • Save GeorgeMac/da17102a0c91daef9a2b to your computer and use it in GitHub Desktop.
Save GeorgeMac/da17102a0c91daef9a2b to your computer and use it in GitHub Desktop.
Im Sorry
def compress(str)
_c = ->(u, r, head, tail, count, accum) do
tail==[] ? r[accum,head,count] : ((h, t = u[tail]); (_ = _c.curry[u,r,h,t]); (h == head ? _[count+1, accum] : _[1, r[accum, head, count]]))
end
(u=->(a){[a[0], a[1..-1]]}); str == '' ? str : _c[u, ->(a,h,c){(r=->(l,n){(n>1)?"#{l}#{n}":l});"#{a}#{r[h,c]}"}, *u[str.split('')], 1, '']
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment