ruby/to_m3.rb
# convert memory-1 or memory-2 strategy into memory-3 strategy
convert memory-1 or memory-2 strategy into memory-3 strategy
convert memory - 1 or memory - 2 strategy into memory - 3 strategy
def m1_to_m3(m1)
  raise "invalid input" unless m1.size == 4 and m1.each_char.all? {|c| c=='c' or c=='d'}
  64.times.map do |i|
    b_1 = i&1
    a_1 = (i&8)/8
    idx = a_1*2 + b_1
    m1[idx]
  end.join
end
def m1_to_m3 ( m1 ) raise "invalid input" unless m1 . size == 4 and m1 . each_char . all? { | c | c == 'c' or c == 'd' } 64 . times . map do | i | b_1 = i & 1 a_1 = ( i & 8 ) / 8 idx = a_1 * 2 + b_1 m1 [ idx ] end . join end
convert memory-1 or memory-2 strategy into memory-3 strategy
convert memory - 1 or memory - 2 strategy into memory - 3 strategy
m1