Skip to content

Instantly share code, notes, and snippets.

@jakubpizon
jakubpizon / PandasTour.ipynb
Created March 24, 2019 21:57 — forked from wesm/PandasTour.ipynb
Pandas Tour
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jakubpizon
jakubpizon / ASwiftTour.playground.swift
Created March 7, 2019 08:25 — forked from billbonney/ASwiftTour.playground.swift
A Swift Tour - The Swift Programming Language - Solutions
// The Swift Programming Language: Swift by Tutorials (solutions)
// Author: Bill Bonney <billbonney (at) communistech.com>
//
// This is all the code in The Swift Tour section in the Apple Book on Swift.
// This should allow you to play with the code and see behaviours, and help
// solve any paticulars you get stuck on when doing the Experiments.
//
// Please feel free to comment on any part, I am by no means an expert in Swift ;-)
//
// NOTE: Not all code is identical (since I was tinkering, but should help)
@jakubpizon
jakubpizon / dynamic_tsp.py
Created February 13, 2019 14:48 — forked from mlalevic/dynamic_tsp.py
Simple Python implementation of dynamic programming algorithm for the Traveling salesman problem
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}: