def try_sit( chairs, cus ) n=cus[0] pos = 8.times.find{ |x| (x...(x+n)).all?{ |y| chairs[y%8]==0 } } if pos (pos...(pos+n)).each{ |x| chairs[x%8]=1 } cus.shift end end def progress( chairs ) chairs.size.times do |ix| chairs[ix] = (chairs[ix]+1) % 4 if chairs[ix]!=0 end end def solve_impl( chairs, cus ) loop do try_sit( chairs, cus ) return chairs if cus.empty? progress(chairs) end end def solve(s)
![ESM オフラインリアルタイムどう書くの問題を解いてみた - Qiita](https://cdn-ak-scissors.b.st-hatena.com/image/square/90a8bf5839633f95c0cf0e397d328e5eb93822da/height=288;version=1;width=512/https%3A%2F%2Fqiita-user-contents.imgix.net%2Fhttps%253A%252F%252Fcdn.qiita.com%252Fassets%252Fpublic%252Farticle-ogp-background-412672c5f0600ab9a64263b751f1bc81.png%3Fixlib%3Drb-4.0.0%26w%3D1200%26mark64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZ3PTk3MiZoPTM3OCZ0eHQ9RVNNJTIwJUUzJTgyJUFBJUUzJTgzJTk1JUUzJTgzJUE5JUUzJTgyJUE0JUUzJTgzJUIzJUUzJTgzJUFBJUUzJTgyJUEyJUUzJTgzJUFCJUUzJTgyJUJGJUUzJTgyJUE0JUUzJTgzJUEwJUUzJTgxJUE5JUUzJTgxJTg2JUU2JTlCJUI4JUUzJTgxJThGJUUzJTgxJUFFJUU1JTk1JThGJUU5JUExJThDJUUzJTgyJTkyJUU4JUE3JUEzJUUzJTgxJTg0JUUzJTgxJUE2JUUzJTgxJUJGJUUzJTgxJTlGJnR4dC1hbGlnbj1sZWZ0JTJDdG9wJnR4dC1jb2xvcj0lMjMyMTIxMjEmdHh0LWZvbnQ9SGlyYWdpbm8lMjBTYW5zJTIwVzYmdHh0LXNpemU9NTYmcz1iMjhlZDZlZjUwMDQ2OGJlMzU3OGM4M2M4MDVmNDRmZA%26mark-x%3D142%26mark-y%3D57%26blend64%3DaHR0cHM6Ly9xaWl0YS11c2VyLWNvbnRlbnRzLmltZ2l4Lm5ldC9-dGV4dD9peGxpYj1yYi00LjAuMCZoPTc2Jnc9NzcwJnR4dD0lNDBOYWJldGFuaSZ0eHQtY29sb3I9JTIzMjEyMTIxJnR4dC1mb250PUhpcmFnaW5vJTIwU2FucyUyMFc2JnR4dC1zaXplPTM2JnR4dC1hbGlnbj1sZWZ0JTJDdG9wJnM9YmFkODMwNzgwZjU4ZmQ1ZmUxYjM0Y2MzYmZiNTQ5NmU%26blend-x%3D142%26blend-y%3D486%26blend-mode%3Dnormal%26s%3D58409d60df0a064da50546360c04e10b)