Source

bubble-economy / counting.py

Full commit
#!/usr/bin/env python
# encoding: utf-8
"""
counting.py

Utils for iterating through sets in useful ways for me - for example, grid
sampling the most important points first."""

import math

def cantor_count(i):
    if i in (0,1):
        return float(i)
    elif i==2:
        return 0.5
    else:
        exponent = rooter(i)
        offset = 1 + 2*(i-(2**(exponent-1)+1))
        return offset * 2.0**(-exponent)
    
def rooter(x):                    
    return int(math.ceil(math.log(x)/math.log(2)-0.0000001))

def spiral_count(i, dimensions):
    # this can be defined recursively in a relation with lower dimensional versions of itself. yes. 
    pass