Skip to content

Instantly share code, notes, and snippets.

@epitron
Created December 9, 2015 05:54
Show Gist options
  • Save epitron/75999363fc7b691b375e to your computer and use it in GitHub Desktop.
Save epitron/75999363fc7b691b375e to your computer and use it in GitHub Desktop.
ds = open("input.txt").
map { |line| c, d = line.strip.split(" = "); cs = c.split(" to "); [[cs, d.to_i], [cs.reverse, d.to_i]] }.
flatten(1).
to_h
cs = ds.keys.flatten.uniq
tours = cs.permutation(cs.size).
map { |perm| perm.each_cons(2).map{|pair| ds[pair] }.reduce(:+) }
p min: tours.min, max: tours.max
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment