/*
* countshapes.c
* Calculates the number of circles, diamond, and hearts present in the nth
* generation of the Q-toothpick cellular automaton described by Sloane's A187210
*
* Created by Nathaniel Johnston (nathaniel@nathanieljohnston.com)
* http://www.nathanieljohnston.com/2011/03/the-q-toothpick-cellular-automaton/
* March 27, 2011
*/
#include
#include
unsigned int prevPts = 1, numPts = 1, pt[268435455];
FILE *file;
unsigned int getCoord (unsigned int pt, unsigned short coord)
{
unsigned short shift = 14*(coord-1);
return (pt & (16383*(1 << shift))) >> shift;
}
unsigned char getOrien (unsigned int pt)
{
return (pt & (3 << 28)) >> 28;
}
unsigned int getPt (unsigned short x, unsigned short y, unsigned short orien)
{
return x | (y << 14) | (orien << 28);
}
unsigned char addOrien (unsigned short x, unsigned short y, unsigned short orien)
{
unsigned int j, nh = 0, nv = 0;
unsigned short px, py, po;
for(j=0;j