Skip to content

Instantly share code, notes, and snippets.

@nhinds
Created June 6, 2015 02:17
Show Gist options
  • Save nhinds/c7fae9893237b4bd980d to your computer and use it in GitHub Desktop.
Save nhinds/c7fae9893237b4bd980d to your computer and use it in GitHub Desktop.
Genesis 1
<?php
define('BEGINNING',0);
define('FIRST_DAY',24*60*60);
define('SECOND_DAY',2*24*60*60);
define('THIRD_DAY',3*24*60*60);
define('FOURTH_DAY',4*24*60*60);
define('FIFTH_DAY',5*24*60*60);
define('SIXTH_DAY',6*24*60*60);
define('void',null);
define('lots',1000);
define('T_HEAVENS',1);
define('T_EARTH',2);
define('T_FIRMAMENT',4);
define('T_GRASS',8);
define('T_HERB',16);
define('T_FRUIT_TREE',32);
define('T_GREATER_LIGHT',64);
define('T_LESSER_LIGHT',128);
define('T_WATER_CREATURES',256);
define('T_FOWL',512);
define('T_CATTLE',1024);
define('T_CREEPING',2048);
define('T_BEAST',4096);
define('T_MAN_MALE',8192);
define('T_MAN_FEMALE',16384);
define('T_STARS',32768);
define('T_EVERYTHING',65535);
define('T_GOOD',1);
define('T_BAD',0);
define('T_VERY_GOOD',T_GOOD);
define('T_DARKNESS','darkness');
define('T_WATERS_ABOVE','waters_above');
class addable {
public $things=array();
public function add($what) {
if (!is_array($what)) $what=array($what);
$this->things=array_merge($this->things,$what);
}
}
class earth extends addable {
public $form;
public $deep;
public $waters;
public function __construct() {
$this->waters=new waters();
$this->deep=&$this->waters;
}
}
class waters {
public $waters_above;
public function __construct() {
$this->waters_above=&$this;
}
public function gather() {
return new seas();
}
}
class firmament extends addable {
public $waters_under;
public function __construct() {
$this->waters_under=new waters();
}
}
class creature {
public $habitat;
public $type;
public function __construct($habitat,$type='') {
$this->habitat=$habitat;
$this->type=$type;
}
}
class seas extends addable {
}
abstract class god {
public static function create($objects) {
$created=array();
if (($objects&T_HEAVENS)==T_HEAVENS) $created[]=new heavens();
if (($objects&T_EARTH)==T_EARTH) $created[]=new earth();
if (($objects&T_FIRMAMENT)==T_FIRMAMENT) $created[]=new firmament();
if (($objects&T_GRASS)==T_GRASS) $created[]=new plant('grass');
if (($objects&T_HERB)==T_HERB) $created[]=new plant('herb');
if (($objects&T_FRUIT_TREE)==T_FRUIT_TREE) $created[]=new plant('fruit_tree');
if (($objects&T_GREATER_LIGHT)==T_GREATER_LIGHT) $created[]=new sun();
if (($objects&T_LESSER_LIGHT)==T_LESSER_LIGHT) $created[]=new moon();
if (($objects&T_STARS)==T_STARS) $created[]=new stars(lots);
if (($objects&T_WATER_CREATURES)==T_WATER_CREATURES) $created[]=new creature('water');
if (($objects&T_FOWL)==T_FOWL) $created[]=new creature('air','fowl');
if (($objects&T_CATTLE)==T_CATTLE) $created[]=new creature('land','cattle');
if (($objects&T_CREEPING)==T_CREEPING) $created[]=new creature('land','creeping thing');
if (($objects&T_BEAST)==T_BEAST) $created[]=new creature('land','beast');
if (($objects&T_MAN_MALE)==T_MAN_MALE) $created[]=new man('male');
if (($objects&T_MAN_FEMALE)==T_MAN_FEMALE) $created[]=new man('female');
if (count($created)==1) $created=$created[0];
return $created;
}
public static function move($where) {
}
public static function bless($words) {
self::say($words);
}
public static function say($words) {
echo $words."\n";
}
public static function see($what) {
return ($what?T_GOOD:T_BAD);
}
public static function divide($what, $from) {
$divided=$what->{$from};
$what->{$from}=void;
return $divided;
}
public static function call($what, $name) {
global ${$name};
${$name}=$what;
}
public static function giveDominion($who,$what) {
foreach ($who as $whom) {
$whom->dominion=$what;
}
}
}
class man extends creature {
public $gender;
public $dominion;
public function __construct($gender) {
parent::__construct('land','man');
$this->gender=$gender;
}
}
class plant {
public $type;
public function __construct($type) {
$this->type=$type;
}
}
class universe {
public static $time;
public static $start;
public static function initialise() {
self::$start=array_merge($GLOBALS);
}
public static function display() {
$GLOBALS['time']=self::$time;
var_dump(array_diff_key($GLOBALS,self::$start));
}
}
class light {
public $darkness;
public function __construct() {
$this->darkness=new darkness();
}
}
class sun {
}
class moon {
}
class heavens {
}
class darkness {
}
class land {
}
class stars {
public $number;
public function __construct($number) {
$this->number=$number;
}
}
universe::initialise();
register_shutdown_function(array('universe','display'));
<?php
require('aether.php');
// Genesis 1:1
universe::$time=BEGINNING;
list($heavens,$earth)=god::create(T_HEAVENS|T_EARTH);
// Genesis 1:2
$earth->form=void;
god::move($earth->waters);
// Genesis 1:3
god::say('Let there be light');
$light=new light();
// Genesis 1:4
assert(god::see($light)===T_GOOD);
$darkness=god::divide($light,T_DARKNESS);
// Genesis 1:5
god::call($light, 'Day');
god::call($darkness, 'Night');
universe::$time=FIRST_DAY;
// Genesis 1:6
god::say('Let there be a firmament in the midst of the waters, and let it divide the waters from the waters');
// Genesis 1:7
$firmament=god::create(T_FIRMAMENT);
$waters_under=$firmament->waters_under;
$waters_above=god::divide($waters_under,T_WATERS_ABOVE);
// Genesis 1:8
god::call($firmament,'Heaven');
universe::$time=SECOND_DAY;
// Genesis 1:9
god::say('Let the waters under the heaven be gathered together unto one place, and let the dry land appear');
$gathered_waters=$waters_under->gather();
$land=new land();
$earth->add($land);
// Genesis 1:10
god::call($land,'Earth');
god::call($gathered_waters,'Seas');
assert(god::see($Earth)===T_GOOD);
// Genesis 1:11
god::say('Let the earth bring forth grass, the herb yielding seed, and the fruit tree yielding fruit after his kind, whose seed is in itself, upon the earth');
$plants=god::create(T_GRASS|T_HERB|T_FRUIT_TREE);
// Genesis 1:12
$earth->add($plants);
assert(god::see($plants)===T_GOOD);
// Genesis 1:13
universe::$time=THIRD_DAY;
// Genesis 1:14
god::say('Let there be lights in the firmament of the heaven, to divide the day from the night; and let them be for signs, and for seasons, and for days, and years');
// Genesis 1:15
god::say('And let them be for lights in the firmament of the heaven, to give light upon the earth');
// Genesis 1:16
$lights=god::create(T_GREATER_LIGHT|T_LESSER_LIGHT|T_STARS);
// Genesis 1:17
$firmament->add($lights);
// Genesis 1:18
assert(god::see($lights)===T_GOOD);
// Genesis 1:19
universe::$time=FOURTH_DAY;
// Genesis 1:20
god::say('Let the waters bring forth abundantly the moving creature that hath life, and fowl that may fly above the earth in the open firmament of heaven');
// Genesis 1:21
$water_creatures=god::create(T_WATER_CREATURES|T_FOWL);
$Seas->add($water_creatures);
assert(god::see($water_creatures)===T_GOOD);
// Genesis 1:22
god::bless('Be fruitful, and multiply, and fill the waters in the seas; and let fowl multiply in the earth');
// Genesis 1:23
universe::$time=FIFTH_DAY;
// Genesis 1:24
god::say('Let the earth bring forth the living creature after his kind, cattle, and creeping thing, and beast of the earth after his kind');
// Genesis 1:25
$land_creatures=god::create(T_CATTLE|T_CREEPING|T_BEAST);
$earth->add($land_creatures);
assert(god::see($land_creatures)===T_GOOD);
// Genesis 1:26
god::say('Let us make man in our image, after our likeness; and let them have dominion over the fish of the sea, and over the fowl of the air, and over the cattle, and over all the earth, and over every creeping thing that creepeth upon the earth');
// Genesis 1:27
$man=god::create(T_MAN_MALE|T_MAN_FEMALE);
$earth->add($man);
// Genesis 1:28
god::bless('Be fruitful, and multiply, and replenish the earth, and subdue it; and have dominion over the fish of the sea, and over the fowl of the air, and over every living thing that moveth upon the earth');
// Genesis 1:29
god::say('Behold, I have given you every herb bearing seed, which is upon the face of all the earth, and every tree, in the which is the fruit of a tree yielding seed; to you it shall be for meat');
// Genesis 1:30
god::say('And to every beast of the earth, and to every fowl of the air, and to every thing that creepeth upon the earth, wherein there is life, I have given every green herb for meat');
god::giveDominion($man,T_WATER_CREATURES|T_FOWL|T_CATTLE|T_BEAST|T_CREEPING|T_HERB|T_FRUIT_TREE);
// Genesis 1:31
assert(god::see(T_EVERYTHING)===T_VERY_GOOD);
universe::$time=SIXTH_DAY;
Let there be light
Let there be a firmament in the midst of the waters, and let it divide the waters from the waters
Let the waters under the heaven be gathered together unto one place, and let the dry land appear
Let the earth bring forth grass, the herb yielding seed, and the fruit tree yielding fruit after his kind, whose seed is in itself, upon the earth
Let there be lights in the firmament of the heaven, to divide the day from the night; and let them be for signs, and for seasons, and for days, and years
And let them be for lights in the firmament of the heaven, to give light upon the earth
Let the waters bring forth abundantly the moving creature that hath life, and fowl that may fly above the earth in the open firmament of heaven
Be fruitful, and multiply, and fill the waters in the seas; and let fowl multiply in the earth
Let the earth bring forth the living creature after his kind, cattle, and creeping thing, and beast of the earth after his kind
Let us make man in our image, after our likeness; and let them have dominion over the fish of the sea, and over the fowl of the air, and over the cattle, and over all the earth, and over every creeping thing that creepeth upon the earth
Be fruitful, and multiply, and replenish the earth, and subdue it; and have dominion over the fish of the sea, and over the fowl of the air, and over every living thing that moveth upon the earth
Behold, I have given you every herb bearing seed, which is upon the face of all the earth, and every tree, in the which is the fruit of a tree yielding seed; to you it shall be for meat
And to every beast of the earth, and to every fowl of the air, and to every thing that creepeth upon the earth, wherein there is life, I have given every green herb for meat
array
'earth' =>
object(earth)[2]
public 'form' => null
public 'deep' => &
object(waters)[3]
public 'waters_above' =>
&object(waters)[3]
public 'waters' => &
object(waters)[3]
public 'waters_above' =>
&object(waters)[3]
public 'things' =>
array
0 =>
object(land)[9]
1 =>
object(plant)[10]
public 'type' => string 'grass' (length=5)
2 =>
object(plant)[11]
public 'type' => string 'herb' (length=4)
3 =>
object(plant)[12]
public 'type' => string 'fruit_tree' (length=10)
4 =>
object(creature)[18]
public 'habitat' => string 'land' (length=4)
public 'type' => string 'cattle' (length=6)
5 =>
object(creature)[19]
public 'habitat' => string 'land' (length=4)
public 'type' => string 'creeping thing' (length=14)
6 =>
object(creature)[20]
public 'habitat' => string 'land' (length=4)
public 'type' => string 'beast' (length=5)
7 =>
object(man)[21]
public 'gender' => string 'male' (length=4)
public 'dominion' => int 7984
public 'habitat' => string 'land' (length=4)
public 'type' => string 'man' (length=3)
8 =>
object(man)[22]
public 'gender' => string 'female' (length=6)
public 'dominion' => int 7984
public 'habitat' => string 'land' (length=4)
public 'type' => string 'man' (length=3)
'heavens' =>
object(heavens)[1]
'light' =>
object(light)[4]
public 'darkness' => null
'darkness' =>
object(darkness)[5]
'Day' =>
object(light)[4]
public 'darkness' => null
'Night' =>
object(darkness)[5]
'firmament' =>
object(firmament)[6]
public 'waters_under' =>
object(waters)[7]
public 'waters_above' => null
public 'things' =>
array
0 =>
object(sun)[13]
1 =>
object(moon)[14]
2 =>
object(stars)[15]
public 'number' => int 1000
'waters_under' =>
object(waters)[7]
public 'waters_above' => null
'waters_above' =>
object(waters)[7]
public 'waters_above' => null
'Heaven' =>
object(firmament)[6]
public 'waters_under' =>
object(waters)[7]
public 'waters_above' => null
public 'things' =>
array
0 =>
object(sun)[13]
1 =>
object(moon)[14]
2 =>
object(stars)[15]
public 'number' => int 1000
'gathered_waters' =>
object(seas)[8]
public 'things' =>
array
0 =>
object(creature)[16]
public 'habitat' => string 'water' (length=5)
public 'type' => string '' (length=0)
1 =>
object(creature)[17]
public 'habitat' => string 'air' (length=3)
public 'type' => string 'fowl' (length=4)
'land' =>
object(land)[9]
'Earth' =>
object(land)[9]
'Seas' =>
object(seas)[8]
public 'things' =>
array
0 =>
object(creature)[16]
public 'habitat' => string 'water' (length=5)
public 'type' => string '' (length=0)
1 =>
object(creature)[17]
public 'habitat' => string 'air' (length=3)
public 'type' => string 'fowl' (length=4)
'plants' =>
array
0 =>
object(plant)[10]
public 'type' => string 'grass' (length=5)
1 =>
object(plant)[11]
public 'type' => string 'herb' (length=4)
2 =>
object(plant)[12]
public 'type' => string 'fruit_tree' (length=10)
'lights' =>
array
0 =>
object(sun)[13]
1 =>
object(moon)[14]
2 =>
object(stars)[15]
public 'number' => int 1000
'water_creatures' =>
array
0 =>
object(creature)[16]
public 'habitat' => string 'water' (length=5)
public 'type' => string '' (length=0)
1 =>
object(creature)[17]
public 'habitat' => string 'air' (length=3)
public 'type' => string 'fowl' (length=4)
'land_creatures' =>
array
0 =>
object(creature)[18]
public 'habitat' => string 'land' (length=4)
public 'type' => string 'cattle' (length=6)
1 =>
object(creature)[19]
public 'habitat' => string 'land' (length=4)
public 'type' => string 'creeping thing' (length=14)
2 =>
object(creature)[20]
public 'habitat' => string 'land' (length=4)
public 'type' => string 'beast' (length=5)
'man' =>
array
0 =>
object(man)[21]
public 'gender' => string 'male' (length=4)
public 'dominion' => int 7984
public 'habitat' => string 'land' (length=4)
public 'type' => string 'man' (length=3)
1 =>
object(man)[22]
public 'gender' => string 'female' (length=6)
public 'dominion' => int 7984
public 'habitat' => string 'land' (length=4)
public 'type' => string 'man' (length=3)
'time' => int 518400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment