Solved Day 9
parent
27497f9992
commit
43c9d56726
|
@ -0,0 +1,28 @@
|
||||||
|
Faerun to Tristram = 65
|
||||||
|
Faerun to Tambi = 129
|
||||||
|
Faerun to Norrath = 144
|
||||||
|
Faerun to Snowdin = 71
|
||||||
|
Faerun to Straylight = 137
|
||||||
|
Faerun to AlphaCentauri = 3
|
||||||
|
Faerun to Arbre = 149
|
||||||
|
Tristram to Tambi = 63
|
||||||
|
Tristram to Norrath = 4
|
||||||
|
Tristram to Snowdin = 105
|
||||||
|
Tristram to Straylight = 125
|
||||||
|
Tristram to AlphaCentauri = 55
|
||||||
|
Tristram to Arbre = 14
|
||||||
|
Tambi to Norrath = 68
|
||||||
|
Tambi to Snowdin = 52
|
||||||
|
Tambi to Straylight = 65
|
||||||
|
Tambi to AlphaCentauri = 22
|
||||||
|
Tambi to Arbre = 143
|
||||||
|
Norrath to Snowdin = 8
|
||||||
|
Norrath to Straylight = 23
|
||||||
|
Norrath to AlphaCentauri = 136
|
||||||
|
Norrath to Arbre = 115
|
||||||
|
Snowdin to Straylight = 101
|
||||||
|
Snowdin to AlphaCentauri = 84
|
||||||
|
Snowdin to Arbre = 96
|
||||||
|
Straylight to AlphaCentauri = 107
|
||||||
|
Straylight to Arbre = 14
|
||||||
|
AlphaCentauri to Arbre = 46
|
|
@ -0,0 +1,3 @@
|
||||||
|
London to Dublin = 464
|
||||||
|
London to Belfast = 518
|
||||||
|
Dublin to Belfast = 141
|
|
@ -0,0 +1,26 @@
|
||||||
|
#!/bin/env ruby
|
||||||
|
require 'pry'
|
||||||
|
distances = File.readlines('./input').map { |line| line.split(/\sto\s|=/).map(&:strip) }
|
||||||
|
locations = distances.map { |i| i[0..1] }.flatten.uniq.freeze
|
||||||
|
|
||||||
|
def travel(loc1, loc2, distances)
|
||||||
|
distances.filter_map do |pair|
|
||||||
|
pair if pair.include?(loc1) && pair.include?(loc2)
|
||||||
|
end.flatten[2].to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
routes = locations.permutation.to_a
|
||||||
|
routes.each do |route|
|
||||||
|
total = 0
|
||||||
|
route.each_cons(2) do |start, finish|
|
||||||
|
total += travel(start, finish, distances)
|
||||||
|
end
|
||||||
|
route.push(total)
|
||||||
|
end
|
||||||
|
|
||||||
|
shortest = routes.flatten.reject { |item| item.is_a?(String) }.min
|
||||||
|
longest = routes.flatten.reject { |item| item.is_a?(String) }.max
|
||||||
|
puts "Part 1 Solution: #{shortest}"
|
||||||
|
puts "Part 2 Solution: #{longest}"
|
||||||
|
|
||||||
|
# binding.pry
|
Loading…
Reference in New Issue