Created
December 2, 2021 10:48
-
-
Save PJB3005/dff34b85d39dc000d9ed8a1a0b892a41 to your computer and use it in GitHub Desktop.
Advent Of Core 2021 Day 1 NTSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (substr($content, 1, 6) == "!load") | |
{ | |
$lenContent = length($content); | |
$dataString = substr($content, 6, $lenContent+1); | |
$data = explode($dataString, ","); | |
mem("data", $data); | |
mem("i", 1); | |
mem("last", 10000); | |
mem("count", 0); | |
$lenData = length($data); | |
$lenDataStr = tostring($lenData); | |
$datStr = vector2text($data); | |
broadcast("LD: " + $lenDataStr, $freq, "Sloeber", "Computer"); | |
broadcast("dat: " + $datStr, $freq, "Sloeber", "Computer"); | |
} | |
elseif ($content == "!c") | |
{ | |
$data = mem("data"); | |
$i = mem("i"); | |
$last = mem("last"); | |
$count = mem("count"); | |
$c = 1; | |
$lenData = length($data); | |
$lenDataStr = tostring($lenData); | |
$iStr = tostring($i); | |
$lastStr = tostring($last); | |
$countStr = tostring($count); | |
broadcast("LD: " + $lenDataStr + ", i: " + $iStr + ", last: " + $lastStr + "count: " + $countStr, $freq, "Sloeber", "Computer"); | |
while ($i <= $lenData && $c < 50) | |
{ | |
$valStr = at($data, $i); | |
$iStr = tostring($i); | |
//broadcast("$valStr, $i: " + $valStr + ", " + $iStr, $freq, "Sloeber", "Computer"); | |
$val = tonum($valStr); | |
if ($val > $last) | |
{ | |
$count += 1; | |
} | |
$last = $val; | |
$i += 1; | |
$c += 1; | |
} | |
if ($i > $lenData) | |
{ | |
// Got it! | |
$countStr = tostring($count); | |
//broadcast("The answer is... " + $countStr + "!", $freq, "Sloeber", "Computer"); | |
return; | |
} | |
mem("i", $i); | |
mem("last", $last); | |
mem("count", $count); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment