part1

#!/usr/bin/env php
<?php
/** Day 9 Part 1
 * 
 */

require(__DIR__.'/functions.php');

if (@$argv[1] == 'sample'){
    $input = file_get_contents(__DIR__.'/sample.txt');
} else {
    $input = file_get_contents(__DIR__.'/input.txt');
}

$lines = explode("\n", trim($input));
$expected_output = null;

$differences_stack = [];

$sum_extrapolated_values = 0;
$sum_left_values = 0;

global $ops; 
$ops = 0;

foreach ($lines as $line){

    $nums = explode(" ",trim($line));
    $nums = array_map(function($v){return (int)$v;}, $nums);
    $zeroed_stack = array_merge([$nums], get_zeroed_stack($nums));
    echo "\n\nzeroed stack\n";
    print_r($zeroed_stack);
    $extended_stack = extend_zeroed_stack($zeroed_stack);

    $next_value = array_pop($extended_stack[0]);

    $sum_extrapolated_values += $next_value;

    $extended_left = extend_stack_left($extended_stack);
    $sum_left_values += $extended_left[0][0];

    //print_r($extended_left);

    //exit;

    //echo "\n\nextended_stack\n\n";
    //print_r($extended_stack);

    //break;
}


echo "\n\nExtrapolated right is: $sum_extrapolated_values\n\n";
echo "\n\nExtrapolated left is: $sum_left_values\n\n";
echo "\n\nTotal Right Predictions: $ops \n\n";