Created
February 11, 2013 22:45
-
-
Save johnliu/4758315 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/python | |
import os | |
import sys | |
import math | |
from random import random | |
DISTANCE = 10000 | |
# Generate random floating point numbers and print them to a file. | |
def main(n=100): | |
f = open('tmp', 'w') | |
points = [] | |
for i in range(n): | |
point = (DISTANCE * random(), DISTANCE * random()) | |
points.append(point) | |
f.write("%s,%s\n" % point) | |
f.close() | |
os.system('make clean') | |
os.system('make') | |
# os.system('cat tmp') | |
print '-------------------' | |
os.system('./closestpoints < tmp') | |
min_dist = 10000000000 | |
min_point_a = None | |
min_point_b = None | |
for ax, ay in points: | |
for bx, by in points: | |
if (ax, ay) != (bx, by): | |
dist = math.sqrt((ax - bx) ** 2 + (ay - by) ** 2) | |
if dist < min_dist: | |
min_dist = dist | |
min_point_a = (ax, ay) | |
min_point_b = (bx, by) | |
print '-------------------' | |
print '%.6f,%.6f' % min_point_a | |
print '%.6f,%.6f' % min_point_b | |
print 'Distance: %s' % min_dist | |
print '-------------------' | |
os.system('rm tmp') | |
os.system('make clean') | |
if __name__ == '__main__': | |
n = len(sys.argv) | |
if n >= 2: | |
main(int(sys.argv[1])) | |
else: | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment