never met a part of the stack I didn't like. sr. engineer at clique studios in chicago, perpetual creative hobbyist, bird friend, local gay agenda promoter. she/her. tips: https://ko-fi.com/carlymho
OKAY FINALLY. I had to up the PHP default memory limit by 8x to actually get the second part to run because I kept running into memory allocation problems, haha. Also learned a bunch about how references work in PHP to stop the program from segmentation faulting! Exciting!
Part 2: (double circular linked list implementation)
<?phpini_set('memory_limit','1024M');classNode{public$content;public$prev;public$next;function__construct($content,$prev=null,$next=null){$this->content=$content;$this->prev=$prev;$this->next=$next;}functionprint(){return$this->content;}}classLinkedList{private$first;private$current;private$count;function__construct(){$this->count=1;$node=newNode(0);$node->prev=&$node;$node->next=&$node;$this->first=&$node;$this->current=&$node;}functionpush($content){$next=$this->current->next;$current=$this->current;$n=newNode($content,$current,$next);$next->prev=&$n;$current->next=&$n;$this->current=&$n;$this->count++;}functionpop(){$n=$this->current;$val=$n->content;$next=&$n->next;$prev=&$n->prev;$prev->next=$next;$next->prev=$prev;$this->current=$next;unset($n);$this->count--;return$val;}functiongoClockwise($num){for($i=0;$i<$num;$i++){$this->current=&$this->current->next;}}functiongoCounterClockwise($num){for($i=0;$i<$num;$i++){$this->current=&$this->current->prev;}}functionprint(){$arr=array($this->first->print());$c=$this->first;while($c->next!=$this->first){array_push($arr,$c->next->print());$c=$c->next;}echojoin(" ",$arr)."\n";return;}}$players=intval(trim($argv[1]));$lastval=intval(trim($argv[2]));$circle=newLinkedList();$elfscores=array_fill(0,$players,0);$elf=0;$round=1;for($i=1;$i<=$lastval;$i++){if($i%23==0){$elfscores[$elf]+=$i;$circle->goCounterClockwise(7);$add=$circle->pop();$elfscores[$elf]+=$add;}else{$circle->goClockwise(1);$circle->push($i);}$elf=($elf+1)%$players;if($elf==0){$round++;echo"Round ".$round." (".($lastval-$i)." marbles remaining)\n";// so i can see how close the program is to finishing, ha ha ha}}echomax($elfscores);die(1);
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
PHP
OKAY FINALLY. I had to up the PHP default memory limit by 8x to actually get the second part to run because I kept running into memory allocation problems, haha. Also learned a bunch about how references work in PHP to stop the program from segmentation faulting! Exciting!
Part 1 (brute force-ish):
Part 2: (double circular linked list implementation)