Skip to content

Instantly share code, notes, and snippets.

@gthandavam
gthandavam / index.html
Last active August 29, 2015 14:06 — forked from mbostock/.block
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
</head>
<body>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.6.0"></script>
<script type="text/javascript">
var svg = d3.select("body").append("svg")
def solve_tsp_dynamic(points):
#calc all lengths
all_distances = [[length(x,y) for y in points] for x in points]
#initial value - just distance from 0 to every other point + keep the track of edges
A = {(frozenset([0, idx+1]), idx+1): (dist, [0,idx+1]) for idx,dist in enumerate(all_distances[0][1:])}
cnt = len(points)
for m in range(2, cnt):
B = {}
for S in [frozenset(C) | {0} for C in itertools.combinations(range(1, cnt), m)]:
for j in S - {0}:
@gthandavam
gthandavam / facebook.py
Created August 11, 2012 09:33 — forked from abraham/facebook.py
Finds who among your Facebook friends you have the most common interests and likes with
#!/usr/bin/python -tt
# MIT licensed by Abraham Williams - http://abrah.am
# Pulls your Facebook friends likes and interest and finds who you have the most in common with.
import urllib, json, sys
graph_url = 'https://graph.facebook.com/'
def print_intersect_count(access_token):
tally = {}