Advent Of Code - PHP 库

dev-master 2021-12-27 13:00 UTC

This package is auto-updated.

Last update: 2024-09-27 18:46:39 UTC


README

Github Advent Of Code php

目录

安装

composer require migueabellan/aoc

基本用法

创建一个.env.local文件来设置环境变量。

# DO NOT COMMITTED THIS FILE

SESSION_AOC=your_cookie_session

自动加载

支持PSR-4自动加载器。

<?php

// When installed via composer
require_once 'vendor/autoload.php';

use Aoc\Client;

$client = new Client();

// Retrieve input by year and day
$input = $client->getInputBy(2020, 23);

echo $input; // 543769257...

高级用法

<?php

use Aoc\Puzzle\AbstractPuzzle;

class Puzzle extends AbstractPuzzle
{
    public function exec1(array $input = []): int|string
    {
        $result = 0;

        // ...

        return (string)$result;
    }

    public function exec2(array $input = []): int|string
    {
        $result = 0;

        // ...

        return (string)$result;
    }
}

工具

<?php

use Aoc\Utils;

$array = [0, 1, 2];

$permutations = ArrayUtil::permutations($array);

print_r($permutations); // [[0, 1, 2], [0, 2, 1], [2, 1, 0] ...]