You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.0 KiB
57 lines
1.0 KiB
1 week ago
|
robots = DATA.read.scan(/-?\d+/).map(&:to_i).each_slice(4).to_a
|
||
|
|
||
|
MAX_X = 101
|
||
|
MAX_Y = 103
|
||
|
# MAX_X = 11
|
||
|
# MAX_Y = 7
|
||
|
|
||
|
QUADRANTS = [
|
||
|
[(0...MAX_X/2), (0...MAX_Y/2)],
|
||
|
[(MAX_X/2+1..), (0...MAX_Y/2)],
|
||
|
[(0...MAX_X/2), (MAX_Y/2+1..)],
|
||
|
[(MAX_X/2+1..), (MAX_Y/2+1..)],
|
||
|
]
|
||
|
|
||
|
robots_s = -> {
|
||
|
(0..MAX_Y).map {|y|
|
||
|
(0..MAX_X).map {|x|
|
||
|
robots.any? {|r_x,r_y,_,_| r_x == x && r_y == y } ? ?# : ?.
|
||
|
}.join
|
||
|
}.join("\n")
|
||
|
}
|
||
|
|
||
|
(0..).each do |i|
|
||
|
robots.each do |robot|
|
||
|
p_x, p_y, v_x, v_y = robot
|
||
|
robot[0] = (p_x + v_x) % MAX_X
|
||
|
robot[1] = (p_y + v_y) % MAX_Y
|
||
|
end
|
||
|
|
||
|
if (i - 46) % 103 == 0
|
||
|
puts i
|
||
|
puts robots_s[]
|
||
|
end
|
||
|
end
|
||
|
|
||
|
pp [
|
||
|
[(0...MAX_X/2), (0...MAX_Y/2)],
|
||
|
[(MAX_X/2+1..), (0...MAX_Y/2)],
|
||
|
[(0...MAX_X/2), (MAX_Y/2+1..)],
|
||
|
[(MAX_X/2+1..), (MAX_Y/2+1..)],
|
||
|
].map {|xx,yy| robots.count {|x,y,_,_| xx.cover?(x) && yy.cover?(y) }}
|
||
|
.inject(&:*)
|
||
|
|
||
|
__END__
|
||
|
p=0,4 v=3,-3
|
||
|
p=6,3 v=-1,-3
|
||
|
p=10,3 v=-1,2
|
||
|
p=2,0 v=2,-1
|
||
|
p=0,0 v=1,3
|
||
|
p=3,0 v=-2,-2
|
||
|
p=7,6 v=-1,-3
|
||
|
p=3,0 v=-1,-2
|
||
|
p=9,3 v=2,3
|
||
|
p=7,3 v=-1,2
|
||
|
p=2,4 v=2,-3
|
||
|
p=9,5 v=-3,-3
|