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.

Revisions

  1. GeorgeMac created this gist Jan 8, 2016.
    6 changes: 6 additions & 0 deletions compress.rb
    Original 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