Solved LeetCode program · 722 of 1,000
#0957 · Prison Cells After N Days
Original English source
Keep a shared cells holding 0, 1, 0, 1, 1, 0, 0, and 1.
To advance. The oldcells is a list of item 0 of cells, item 1 of cells, item 2 of cells, item 3 of cells, item 4 of cells, item 5 of cells, item 6 of cells, and item 7 of cells. Set item 0 of cells to 0. Set item 7 of cells to 0.
For every place from 1 to 6.
The before is item (place minus 1) of oldcells. The after is item (place plus 1) of oldcells. If before is after, set item place of cells to 1. If before is not after, set item place of cells to 0.
The day is 0. The days is 7.
Repeat while day is less than days.
Advance. Add 1 to day.
The parts is an empty list of text.
For each value in cells.
The word is format whole number value as text. Place word into parts.
The joined is join parts with ",". The line is empty text. Place "[" into line. Place joined into line. Place "]" into line. Show line.
Expected stdout
[0,0,1,1,0,0,0,0]