Finally figured it out, lmao (php)

This commit is contained in:
Steph 2022-12-01 21:02:00 +01:00
parent c30135ef6a
commit 7f9614953a
2 changed files with 26 additions and 6 deletions

View File

@ -1,18 +1,13 @@
#!/usr/bin/env php
<?php
// This is very hacky
ini_set('memory_limit', '-1');
$input = file_get_contents("input");
$input = explode(",", $input);
$days = 256;
$days = 80;
for($day=0; $day<$days; $day++){
echo "\rAt day $day/$days. ".count($input)." lanternfish currently. Memory usage: " . floor(memory_get_peak_usage() / 1024 / 1024) . "MiB.";
foreach($input as $i => &$v) {
$v--;
if($v == -1) {

25
2021/6/growth2.php Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env php
<?php
$input = file_get_contents("input");
$input = explode(",", trim($input));
$fish = array_count_values($input);
for($i=0; $i<=10; $i++)
if(!array_key_exists($i, $fish)) $fish[$i] = 0;
$days = 256;
for($day=0; $day<$days; $day++) {
$fish[7] += $fish[0];
$fish[9] += $fish[0];
for($i=0; $i<10; $i++) {
$fish[$i] = $fish[$i+1];
}
}
echo "Total number of fish after $days days: " . array_sum($fish) . "\n";
?>