Created
January 8, 2016 13:16
-
-
Save GeorgeMac/da17102a0c91daef9a2b to your computer and use it in GitHub Desktop.
Revisions
-
GeorgeMac created this gist
Jan 8, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ 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