14_docking_data.rb
# Could move the common parts of run1 + run2 into a run
# yielding on addr to account for the differences there.
# But it is a little slower and doesn't help readability that much.
Could move the common parts of run1 + run2 into a run
yielding on addr to account for the differences there.
But it is a little slower and doesn't help readability that much.
Could move the common parts of run1 + run2 into a run yielding on addr to account for the differences there . But it is a little slower and doesn ' t help readability that much .
def run1(insts)
  mask_zeroes = nil
  mask_ones = nil
  insts.each_with_object(Hash.new(0)) { |(inst, arg), mem|
    case inst
    when :mask
      mask_zeroes, mask_ones, _ = arg
    when :mem
      addr, val = arg
      mem[addr] = (val | mask_ones)  & ~mask_zeroes
    else raise "bad #{inst} #{arg}"
    end
  }
end
def run1 ( insts ) mask_zeroes = nil mask_ones = nil insts . each_with_object ( Hash . new ( 0 ) ) { | ( inst , arg ) , mem | case inst when :mask mask_zeroes , mask_ones , _ = arg when :mem addr , val = arg mem [ addr ] = ( val | mask_ones ) & ~ mask_zeroes else raise "bad #{inst} #{arg}" end } end
Could move the common parts of run1 + run2 into a run
yielding on addr to account for the differences there.
Could move the common parts of run1 + run2 into a run yielding on addr to account for the differences there .
insts
<not_specific>