Hello there, everyone!
I'm running late but I'm doing the advent of code 2023 at adventofcode.com and for the first day, I ended up with the following. I"m wondering if someone could point out what I could have done to make it more efficient/better.
Day 1:
The newly-improved calibration document consists of lines of text; each line originally contained a specific calibration value that the Elves now need to recover. On each line, the calibration value can be found by combining the first digit and the last digit (in that order) to form a single two-digit number.
$input = "start
ckmb52fldxkseven3fkjgcbzmnr7
gckhqpb6twoqnjxqplthree2fourkspnsnzxlz1
2onetwocrgbqm7
frkh2nineqmqxrvdsevenfive
four9two";
$total = 0;
$separator = "\r\n";
$line = strtok($input, $separator);
while ($line !== false) {
$line = strtok( $separator );
foreach (str_split($line) as $char) {
if (is_numeric($char)) {
if(!ISSET($none)){
$none = $char;
}
$ntwo = $char;
}
}
$total = $none.$ntwo + $total;
echo $total."<br>";
UNSET($none);
UNSET($ntwo);
}