@ 2023-12-03T14:53:14Z <?php
//
//$maxRed = 12;
//$maxGreen = 13;
//$maxBlue = 14;
//
//$lines = file($_SERVER["DOCUMENT_ROOT"]."/input2.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
<?php
$lines = [
'Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green',
'Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue',
'Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red',
'Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red',
'Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green',
];
//$limits = [
// 'red' => 12,
// 'green' => 13,
// 'blue' => 14,
//];
$limits = [12, 13, 14];
foreach ($lines as $game)
{
$colonPos = strpos($game, ':');
$sets = explode(';', trim(substr($game, $colonPos + 1)));
$ok = true;
foreach ($sets as $set)
{
if (!$ok)
{
break;
}
$picks = explode(',', $set);
$pickSum = [0,0,0];
foreach ($picks as $pick)
{
$pickArray = explode(' ', trim($pick));
$attempt = (int)$pickArray[0];
$color = $pickArray[1];
switch($color)
{
case 'red':
$pickSum[0] += $attempt;
break;
case 'green':
$pickSum[1] += $attempt;
break;
case 'blue':
$pickSum[2] += $attempt;
break;
}
if ($limits > $pickSum)
{
$ok = false;
break 2;
}
}
preg_match('/\d+/', substr($game, 0, $colonPos), $matches);
var_dump($matches);
}
}
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 8.3.0 0.010 0.010 28.09 8.2.13 0.003 0.016 28.09 8.2.12 0.012 0.006 28.09 8.2.11 0.013 0.006 28.09 8.2.10 0.015 0.004 28.09 8.2.9 0.012 0.006 28.09 8.2.8 0.011 0.007 28.09 8.2.7 0.017 0.000 28.09 8.2.6 0.013 0.007 28.09 8.2.5 0.007 0.014 28.09 8.2.4 0.018 0.003 28.09 8.2.3 0.009 0.006 28.09 8.2.2 0.004 0.011 28.09 8.2.1 0.009 0.006 28.09 8.2.0 0.007 0.007 28.09 8.1.26 0.000 0.014 28.09 8.1.25 0.007 0.007 28.09 8.1.24 0.007 0.007 28.09 8.1.23 0.004 0.011 28.09 8.1.22 0.000 0.008 28.09 8.1.21 0.010 0.003 28.09 8.1.20 0.005 0.005 28.09 8.1.19 0.008 0.000 28.09 8.1.18 0.003 0.006 28.09 8.1.17 0.003 0.006 28.09 8.1.16 0.006 0.003 28.09 8.1.15 0.008 0.000 28.09 8.1.14 0.003 0.006 28.09 8.1.13 0.006 0.003 28.09 8.1.12 0.004 0.004 28.09 8.1.11 0.003 0.005 28.09 8.1.10 0.005 0.003 28.09 8.1.9 0.000 0.008 28.09 8.1.8 0.004 0.004 28.09 8.1.7 0.008 0.000 28.09 8.1.6 0.008 0.000 28.09 8.1.5 0.004 0.004 28.09 8.1.4 0.004 0.004 28.09 8.1.3 0.008 0.000 28.09 8.1.2 0.003 0.005 28.09 8.1.1 0.003 0.006 28.09 8.1.0 0.005 0.003 28.09
preferences:dark mode live preview
134.99 ms | 1421 KiB | 7 Q