Skip to content

ismtabo/advent-of-code-2021

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advent of code 2021

Repository of solutions for the Advent of Code 2021 done by ismtabo

As last year the language I will use Typescript with Deno. Check the repository of the Advent of Code 2020.

Usage

Prerequisites

You may need to install deno to use this repository.

CLI tool

After installing it you can run the solutions using the cli tool:

$ deno run -A --unstable src/cli/mod.ts -h

  Usage:   aoc2021
  Version: v0.1.0

  Description:

    Solutions for Advent of Code 2021. https://adventofcode.com/

  Options:

    -h, --help     - Show this help.
    -V, --version  - Show the version number for this program.

  Commands:

    run      - Run day solution
    run-all  - Run multiple day solution
    new      - Create new day solution folder skeleton

Run a day solution

The solutions can be run with the run sub-command:

$ deno run -A --unstable src/cli/mod.ts run -h

  Usage:   aoc2021 run
  Version: v0.1.0

  Description:

    Run day solution

  Options:

    -h, --help                        - Show this help.
    -d, --day        <day:number>     - Day to run
    -p, --part       <part:number>    - Part of the day solution to run.                             (Default: 1)
    -a, --all-parts                   - Execute both parts. If present part option will be ignore.
    -t, --time                        - Show spent time
    -f, --file       <file:string>    - Input file. If missing, the day input file is used instead.
    --sample                          - Run day using sample input instead of day input file.        (conflicts: file)
    --format         <format:string>  - Output format.                                               (Default: "plain")

Also, to run all the solutions you can use run-all sub-command:

$ deno run -A --unstable src/cli/mod.ts run-all -h

  Usage:   aoc2021 run-all
  Version: v0.1.0

  Description:

    Run multiple day solution

  Options:

    -h, --help                        - Show this help.
    -p, --part       <part:number>    - Part of the day solution to run.                            (Default: 1)
    -a, --all-parts                   - Execute both parts. If present part option will be ignore.
    -t, --time                        - Show spent time
    --sample                          - Run day using sample input instead of day input file.
    --format         <format:string>  - Output format.                                              (Default: "plain")

Test day solutions

Some of the day solutions have unit tests. To run them use deno built-in test runner:

$ deno test [OPTIONS] [file]

Some of the test need --allow-read to read the sample inputs of its day.

Bundle AOC 2021 solutions

Using deno built-in bundler, you can bundle the problems module into a js module:

$ deno bundle [OPTIONS] <source_file> [out_file]

To bundle the solutions module the <source_file> need to be src/problems/mod.ts.

Repository content

The source code of the repository is inside the src path:

Folder

/ src
├- app: TBD
├-/ cli: Module of the cli tool to run problems and more
└-/ solutions: Module of solutions

Cli tool structure

/ cli
├- template: Templates for day solution generation
├- mod.ts: Main module of the cli tool
├- type.d.ts: Types used in the cli tool
└- [...]: other stuff

Day solution structure

Each day solution has the following structure:

/ dayX
├-/ {partOne,partTwo}: Modules of parts one and two
| ├- mod.ts: Main module of the part solution
| ├- [test.ts]: Test of the part solution
| ├- [type.d.ts]: Types of the part solution
| └- [...]: other stuff
| ...
├- mod.ts: Main module of the day solution
├- sample.txt: Sample input case
├- input.txt: Day input case
├- [type.d.ts]: Types used in both parts
└- [...]: other stuff

The main module exports two functions main and preprocess to run the solution parts and preprocess the input respectively. Each part module exports a function partXxx with its name in addition to other possible issues.

Built with

  • Typescript - Language used
  • Deno - Runtime for Javascript and Typescript
  • Cliffy - Command line framework for Deno

Authors

  • Ismael Taboada - Frontend developer - @ismtabo

License

This repository is under MIT License - look up LICENSE for more details

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published