I don't know
This commit is contained in:
parent
9005e65ebc
commit
09d9dc126c
1 changed files with 34 additions and 48 deletions
82
24/main.rb
Executable file → Normal file
82
24/main.rb
Executable file → Normal file
|
@ -36,58 +36,44 @@ until gates.empty?
|
|||
gates.delete(gate)
|
||||
end
|
||||
|
||||
p wires.select { _1.match?(/^x/) }.sort_by(&:first).map { _1.last.to_s }.reverse.join.to_i(2)
|
||||
p wires.select { _1.match?(/^y/) }.sort_by(&:first).map { _1.last.to_s }.reverse.join.to_i(2)
|
||||
x = wires.select { _1.match?(/^x/) }.sort_by(&:first).map { _1.last.to_s }.reverse.join.to_i(2)
|
||||
y = wires.select { _1.match?(/^y/) }.sort_by(&:first).map { _1.last.to_s }.reverse.join.to_i(2)
|
||||
p (x + y)
|
||||
p wires.select { _1.match?(/^z/) }.sort_by(&:first).map { _1.last.to_s }.reverse.join.to_i(2)
|
||||
x = wires.select { _1.match?(/^x/) }.sort_by(&:first).map { _1.last.to_s }.reverse.join
|
||||
xi = x.to_i(2)
|
||||
y = wires.select { _1.match?(/^y/) }.sort_by(&:first).map { _1.last.to_s }.reverse.join
|
||||
yi = y.to_i(2)
|
||||
z = wires.select { _1.match?(/^z/) }.sort_by(&:first).map { _1.last.to_s }.reverse.join
|
||||
zi = z.to_i(2)
|
||||
|
||||
gates = input[split+1..]
|
||||
(x.size - 1).downto(0).each do |i|
|
||||
if x[i].to_i ^ y[i].to_i != z[i + 1].to_i
|
||||
p " " + x
|
||||
p " " + y
|
||||
p z
|
||||
p (" " * (i + 1)) + "^"
|
||||
# require"debug";debugger
|
||||
puts "Failed XOR at #{i}: #{gates.select { _1.match?(/z#{'%02d' % i}/) }}"
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
__END__
|
||||
x00: 1
|
||||
x01: 0
|
||||
x02: 1
|
||||
x00: 0
|
||||
x01: 1
|
||||
x02: 0
|
||||
x03: 1
|
||||
x04: 0
|
||||
y00: 1
|
||||
y01: 1
|
||||
x05: 1
|
||||
y00: 0
|
||||
y01: 0
|
||||
y02: 1
|
||||
y03: 1
|
||||
y04: 1
|
||||
y04: 0
|
||||
y05: 1
|
||||
|
||||
x00 AND y00 -> z05
|
||||
x01 AND y01 -> z02
|
||||
x02 AND y02 -> z01
|
||||
x03 AND y03 -> z03
|
||||
x04 AND y04 -> z04
|
||||
x05 AND y05 -> z00
|
||||
|
||||
ntg XOR fgs -> mjb
|
||||
y02 OR x01 -> tnw
|
||||
kwq OR kpj -> z05
|
||||
x00 OR x03 -> fst
|
||||
tgd XOR rvg -> z01
|
||||
vdt OR tnw -> bfw
|
||||
bfw AND frj -> z10
|
||||
ffh OR nrd -> bqk
|
||||
y00 AND y03 -> djm
|
||||
y03 OR y00 -> psh
|
||||
bqk OR frj -> z08
|
||||
tnw OR fst -> frj
|
||||
gnj AND tgd -> z11
|
||||
bfw XOR mjb -> z00
|
||||
x03 OR x00 -> vdt
|
||||
gnj AND wpb -> z02
|
||||
x04 AND y00 -> kjc
|
||||
djm OR pbm -> qhw
|
||||
nrd AND vdt -> hwm
|
||||
kjc AND fst -> rvg
|
||||
y04 OR y02 -> fgs
|
||||
y01 AND x02 -> pbm
|
||||
ntg OR kjc -> kwq
|
||||
psh XOR fgs -> tgd
|
||||
qhw XOR tgd -> z09
|
||||
pbm OR djm -> kpj
|
||||
x03 XOR y03 -> ffh
|
||||
x00 XOR y04 -> ntg
|
||||
bfw OR bqk -> z06
|
||||
nrd XOR fgs -> wpb
|
||||
frj XOR qhw -> z04
|
||||
bqk OR frj -> z07
|
||||
y03 OR x01 -> nrd
|
||||
hwm AND bqk -> z03
|
||||
tgd XOR rvg -> z12
|
||||
tnw OR pbm -> gnj
|
||||
|
|
Loading…
Reference in a new issue