Finally figured it out, lmao (php)
This commit is contained in:
parent
c30135ef6a
commit
7f9614953a
@ -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
25
2021/6/growth2.php
Normal 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";
|
||||
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user