Solved Day 19
parent
bab9d00c4f
commit
c638723521
|
@ -0,0 +1,45 @@
|
|||
Al => ThF
|
||||
Al => ThRnFAr
|
||||
B => BCa
|
||||
B => TiB
|
||||
B => TiRnFAr
|
||||
Ca => CaCa
|
||||
Ca => PB
|
||||
Ca => PRnFAr
|
||||
Ca => SiRnFYFAr
|
||||
Ca => SiRnMgAr
|
||||
Ca => SiTh
|
||||
F => CaF
|
||||
F => PMg
|
||||
F => SiAl
|
||||
H => CRnAlAr
|
||||
H => CRnFYFYFAr
|
||||
H => CRnFYMgAr
|
||||
H => CRnMgYFAr
|
||||
H => HCa
|
||||
H => NRnFYFAr
|
||||
H => NRnMgAr
|
||||
H => NTh
|
||||
H => OB
|
||||
H => ORnFAr
|
||||
Mg => BF
|
||||
Mg => TiMg
|
||||
N => CRnFAr
|
||||
N => HSi
|
||||
O => CRnFYFAr
|
||||
O => CRnMgAr
|
||||
O => HP
|
||||
O => NRnFAr
|
||||
O => OTi
|
||||
P => CaP
|
||||
P => PTi
|
||||
P => SiRnFAr
|
||||
Si => CaSi
|
||||
Th => ThCa
|
||||
Ti => BP
|
||||
Ti => TiTi
|
||||
e => HF
|
||||
e => NAl
|
||||
e => OMg
|
||||
|
||||
ORnPBPMgArCaCaCaSiThCaCaSiThCaCaPBSiRnFArRnFArCaCaSiThCaCaSiThCaCaCaCaCaCaSiRnFYFArSiRnMgArCaSiRnPTiTiBFYPBFArSiRnCaSiRnTiRnFArSiAlArPTiBPTiRnCaSiAlArCaPTiTiBPMgYFArPTiRnFArSiRnCaCaFArRnCaFArCaSiRnSiRnMgArFYCaSiRnMgArCaCaSiThPRnFArPBCaSiRnMgArCaCaSiThCaSiRnTiMgArFArSiThSiThCaCaSiRnMgArCaCaSiRnFArTiBPTiRnCaSiAlArCaPTiRnFArPBPBCaCaSiThCaPBSiThPRnFArSiThCaSiThCaSiThCaPTiBSiRnFYFArCaCaPRnFArPBCaCaPBSiRnTiRnFArCaPRnFArSiRnCaCaCaSiThCaRnCaFArYCaSiRnFArBCaCaCaSiThFArPBFArCaSiRnFArRnCaCaCaFArSiRnFArTiRnPMgArF
|
|
@ -0,0 +1,51 @@
|
|||
#!/bin/env ruby
|
||||
require 'pry'
|
||||
|
||||
input = File.readlines('./input').map(&:chomp)
|
||||
starting_molecule = input.pop.scan(/[A-Z][a-z]?/)
|
||||
starting_molecule.freeze
|
||||
input.pop
|
||||
|
||||
input.map! { |pair| pair.split('=>').map(&:strip) }
|
||||
results = []
|
||||
|
||||
starting_molecule.each.with_index do |element, i|
|
||||
input.each do |pair|
|
||||
next unless pair[0] == element
|
||||
|
||||
molecule = starting_molecule.dup
|
||||
molecule[i] = pair[1]
|
||||
results.push(molecule.reduce(&:+))
|
||||
end
|
||||
end
|
||||
|
||||
puts "Part 1 Solution: #{results.uniq.count}"
|
||||
# binding.pry
|
||||
|
||||
result = starting_molecule.reduce(&:+)
|
||||
count = 0
|
||||
counts = []
|
||||
100.times do
|
||||
until result == 'e'
|
||||
previous = result.dup
|
||||
matches = input.map do |pair|
|
||||
# pair[1].scan(/[A-Z]/).size * result.scan(pair[1]).size
|
||||
result.scan(pair[1]).size
|
||||
end
|
||||
match = matches.find_index(matches.reject(&:zero?).sample)
|
||||
result.gsub!(input[match][1], input[match][0]) unless match.nil?
|
||||
count += matches[match] unless match.nil?
|
||||
next unless previous == result
|
||||
|
||||
input.shuffle!
|
||||
count == 0
|
||||
result = starting_molecule.reduce(&:+)
|
||||
# break if gets.chomp == 'q'
|
||||
end
|
||||
result = starting_molecule.reduce(&:+)
|
||||
input.shuffle!
|
||||
counts.push(count)
|
||||
count = 0
|
||||
end
|
||||
|
||||
puts "Part 2 Solution: #{counts.min}"
|
Loading…
Reference in New Issue