Day 13: Transparent Origami

array = Array.new(895,"."){Array.new(1311,".")}
movement = []
x_max = 0
y_max = 0

File.foreach("import.dat").with_index do |line|
  if (line[0] == "f") then
    a,b,c = line.split(" ")
    movement.push(c)
    next
  end
  a,b = line.split(',')
  if x_max < a.to_i
    x_max = a.to_i
  end
  if y_max < b.to_i
    y_max = b.to_i
  end
  array[b.to_i][a.to_i] = "■"
end

movement.each do |line|
  dim, val = line.split("=")
  val = val.to_i
  if (dim == "y")
    array.each_with_index do |y_line,y_index|
      y_line.each_with_index do |x_value,x_index|
        if array[y_max - y_index][x_index] == "■"
          array[y_index][x_index] = "■"
        end
      end
    end
    array.slice!(val,y_max)
    y_max = array.size() -1
  elsif (dim == "x")
    array.each_with_index do |y_line,y_index|
      y_line.each_with_index do |x_value,x_index|
        if array[y_index][x_max - x_index] == "■"
          array[y_index][x_index] = "■"
        end
      end
    end
    array.each do |y_line|
      y_line.slice!(val,x_max)
    end
    x_max = array[0].size() - 1
  end
end

i = 0
array.each do |line|
  p line
  line.each do |n|
    if n == "■"
    end
  end
end

メモ

xy平面の特定箇所に座標をプロット。折り紙のように折り返した時に座標を転写していく。xy平面と最後に残った座標をプリントした時に、最後に浮かび上がってくる文字列は…?暗号を解いているようで面白かった。ロジック自体は丁寧に問題を辿っていけば難しい所は特になかった。