From edd845305348a4ea573619068f64e75b11cdeeff Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Mon, 28 Oct 2019 10:30:04 +0000 Subject: day18, whodawhatnow still not working, not enough information? --- day16/whodawhatnow | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/day16/whodawhatnow b/day16/whodawhatnow index 337cec1..0e882c6 100755 --- a/day16/whodawhatnow +++ b/day16/whodawhatnow @@ -111,6 +111,16 @@ oprsorder = { 1<<2 => "eqir", 1<<1 => "eqri", 1<<0 => "eqrr" } +opsorder = %w( + addr addi + mulr muli + banr bani + borr bori + setr seti + gtir gtri gtrr + eqir eqri eqrr +) + ops = [ 0b1111111111111111, 0b1111111111111111, 0b1111111111111111, 0b1111111111111111, @@ -136,6 +146,41 @@ input.each_slice(3) do |sample| ops[opc] &= oprs.map{|opr|opr == a ? 1 : 0}.join.to_i(2) end -(0..15).each do |opc| - puts "#{opc}: #{oprsorder[ops[opc]]}" +iopts = { + "addr" => [], "addi" => [], + "mulr" => [], "muli" => [], + "banr" => [], "bani" => [], + "borr" => [], "bori" => [], + "setr" => [], "seti" => [], + "gtir" => [], "gtri" => [], "gtrr" => [], + "eqir" => [], "eqri" => [], "eqrr" => [] +} + +ops.each_with_index do |op, opc| + ("%016b" % op).chars.each_with_index do |bit, istr| + if bit == "1" then + iopts[opsorder[istr]] << opc + end + end +end + +res = [] + +until iopts.values.map(&:empty?).all? do + iopts.each do |istr, opcs| + puts "#{istr}: #{opcs}" + end + puts + + istr = iopts.select{|k, v| v.length == 1}.keys[0] + opc = iopts[istr][0] + res[opc] = istr + + iopts.each do |k, v| + v.delete(opc) + end +end + +res.each_with_index do |istr, opc| + puts "#{opc}: #{istr}" end -- cgit v1.2.1