aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNat Lasseter <user@4574.co.uk>2019-10-28 10:30:04 +0000
committerNat Lasseter <user@4574.co.uk>2019-10-28 10:30:04 +0000
commitedd845305348a4ea573619068f64e75b11cdeeff (patch)
tree18644175a273ff46a5edafcb4a41de8716e2df56
parent11d885209c61828b6fc15815c04cf8556be70fe8 (diff)
day18, whodawhatnow still not working, not enough information?
-rwxr-xr-xday16/whodawhatnow49
1 files 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