Ejemplo n.º 1
0
<?php

require_once 'init.php';
header('Cache-Control: no-cache');
header('Content-Type: text/javascript');
$data = generateGrid($_SESSION['member_id'], $_GET['game']);
if (!empty($data)) {
    $winner = winner($data);
    if ($winner != -1) {
        setWinner($winner, $_GET['game']);
    } else {
        if ($winner == 0) {
            setTie($_GET['game']);
        }
    }
    echo json_encode(array('stat' => $winner));
}
Ejemplo n.º 2
0
    $count = 0;
    foreach ($grid as $row) {
        foreach ($row as $cell) {
            if ($cell) {
                $count++;
            }
        }
    }
    return $count;
}
function calculateLightStrength($grid)
{
    $strength = 0;
    foreach ($grid as $row) {
        foreach ($row as $cell) {
            $strength = $strength + $cell;
        }
    }
    return $strength;
}
$instructions = getInstructions("6input.txt");
$grid = generateGrid();
foreach ($instructions as $instruction) {
    processInstructionsFromSanta($instruction, $grid);
}
echo "Lights count: " . countLights($grid) . "<br>";
$grid = generateGrid(0);
foreach ($instructions as $instruction) {
    processInstructionsFromSanta($instruction, $grid, true);
}
echo "Light strength: " . calculateLightStrength($grid);