Created
June 20, 2010 07:20
-
-
Save makimoto/445640 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python | |
# vim:fileencoding=utf-8 | |
''' | |
a experiment for Kamogawa Equal-Distance Law | |
usage: | |
% kamogawa.py #pairs second_pair_distance | |
eg. | |
% kamogawa.py 10 100.0 | |
''' | |
from sys import argv,stderr | |
from collections import defaultdict | |
try: | |
num_pairs = int(argv[1]) | |
second_pair_distance = float(argv[2]) | |
except(NameError,IndexError,ValueError): | |
stderr.write('Invalid Arguments! Abort\n') | |
exit(1) | |
pairs = [] | |
pairs.append(0.0) | |
pairs.append(second_pair_distance) | |
for n in xrange(num_pairs-2): | |
distance = 0.0 | |
pos = 0.0 | |
for i in xrange(len(pairs)-1): | |
a = pairs[i] | |
b = pairs[i+1] | |
if abs(a - b) > distance: | |
distance = abs(a - b) | |
pos = min(a,b) + distance/2.0 | |
pairs.append(pos) | |
pairs.sort() | |
dist_dict = defaultdict(int) | |
for i in xrange(len(pairs)-1): | |
a = pairs[i] | |
b = pairs[i+1] | |
dist_dict[abs(a - b)] += 1 | |
print('distance variations:') | |
for i in sorted(dist_dict.items()): | |
print('%f\t%d' % i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment