Skip to content

Instantly share code, notes, and snippets.

@ldong
Created April 30, 2017 04:44
Show Gist options
  • Save ldong/557b2ed0b034b1db3fd98149a580e8e2 to your computer and use it in GitHub Desktop.
Save ldong/557b2ed0b034b1db3fd98149a580e8e2 to your computer and use it in GitHub Desktop.
Gamma python version
#!/usr/bin/env python
import math
def gamma(a):
# special case
if int(a) == 1:
return 0
ind = (int)(math.floor(math.log(a*1.0)/math.log(2.0)))
first = ind * '1' + '0'
size = ((int)(math.pow(2, (int)(math.floor(math.log(a*1.0)/math.log(2.0))))))
# print ind
# print "#0" + str(ind) +"b"
return first + (format(a%size, "0" + str(ind) +"b"))
for i in [4, 11, 47, 1, 202, 3, 2, 230, 8, 9]:
print i, gamma(i)
@ldong
Copy link
Author

ldong commented Apr 30, 2017

// peter piper picks papers

a = '$peterpiperpickspapers$'
b = []; // 22

for (var i=0; i<a.length-1; ++i) {
  console.log(a[i]+a[i+1]);
  b.push(''+[a[i]+a[i+1]]);
}

c = new Set(b); // size 16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment