TI-BASIC, ~10596 bytes (87 for non-competing entry)
For your TI-84 series graphing calculator (!). ThereThis was quite a challenge, because there is no easy way to dowrite a buffered graphics routine (definitely nothing built in), and the graph screen has only four relevant graphics commands: Pxl-On()
, Pxl-Off()
, Pxl-Change()
, and pxl-Test()
.
Uses every accessible pixel on the screen, and wraps correctly. Each cell is one pixel, and the program updates line by line horizontally to the right across the screen. Because the calculators have only a 15MHz z80 processor and BASIC is a slow interpreted language, the code only gets one frame about every five minutes.
I use the clock state as a flag. At the start of the program, the date/time clock is enabled, and I use the value of the global isClockOn flag to determine whether it is the first iteration. After the first frame is drawn, I turn the clock off. Saves one byte over the shortest other method and about four over the obvious method.
I store the states of the three columns next to the one being updated in a 63-element array of base-7 numbers. The 49's place holds the column to the right, the 7's place holds the middle column, and the units place holds the left column--1 for a live cell and 0 for a dead cell. Then I take the remainder mod 6 of the sum of the three numbers around the cell being modified to find the total number of live neighbor cells (it's just like the divisibility by 9 trick—in base 7, the remainder mod 6 equals the sum of the digits). Saves about 10 bytes by itself and gives the opportunity to use the next two optimizations. Example diagram (let's say there is a glider centered at a certain column at Y=45:
Row # | Cell State | Stored number | Mod 6 = cell count ... 44 Live, Live, Live 49+7+1 = 57 3 45 Dead, Dead, Live 49+0+0 = 49 1 46 Dead, Live, Dead 0+7+0 = 7 1 ...
The center cell will stay dead, because it is surrounded by exactly five live cells.
After each row is completed, the numbers in the array are updated by dividing the existing numbers by 7, discarding the decimal part, and adding 49 times the values of the cells in the new column. Storing all three columns each time through would be much slower and less elegant, take at least 20 more bytes, and use three lists rather than one, because the values of cells in each row must be stored before cells are updated. This is by far the smallest way to store cell positions.
The snippet
int(3fPart(3cosh(
gives1
when the input equals 3/6,2
when it equals 4/6, and0
when it equals 0, 1/6, 2/6, or 5/6. Saves about 6 bytes.
Exact byte count and aditional explanation coming soon.