Created
December 9, 2015 05:54
-
-
Save epitron/75999363fc7b691b375e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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