Created
January 8, 2016 13:16
-
-
Save GeorgeMac/da17102a0c91daef9a2b to your computer and use it in GitHub Desktop.
Im Sorry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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