Skip to content

Advent of Code in Java/(Kotlin) with useful utils and a Makefile for easy templating

Notifications You must be signed in to change notification settings

janetschel/advent-of-code

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advent of Code

Welcome to my repo for all Advent of Codes advent-of-code.
I have decided to -- from now on -- redo all AoC's done so far (and all future AoC's) in Java, so I made this repository to host them all.

Project/day setup

  • macOS Monterey 12.0.1
  • Maven 4.0.0 project with Java 17 LTS
  • ./Makefile to automatically create each new day from template files for THE CURRENT YEAR
  • util package for whatever
  • Day's (dev/janetschel/calendar/dayx/) are set up like this:
    • input.txt for the input → will be fetched automatically and NOT created by the Makefile
    • Puzzle.java for the actual solution each day
    • README.md for solve times (if year >= 2020, before that, I didn't do AoC)

All you need to do if you want to create a new day to start coding is:
  • In the terminal navigate to ./
  • Type following: make new year=<year>

This will generate the needed file structure for day x in this year's AoC

Utils

My utils will have some handy functions/classes to work with the input.

Dynamic execution of code

Since this repo contains code to all AoC's and I needed the way to execute them all together AND independently of each other, there is a handy class (Calendar.java) which -- via reflection -- searches and executes all classes belonging to the specified year/day.

It works as follows: (Calendar.java)

@ExecutedDays(day = ALL_DAYS)
public class Calendar {
    private static final String CURRENT_YEAR = "2021";

    // ...
}

Change the annotation @ExecutedDays according to this regex:

^ALL_DAYS|DAY_(?:0[1-9]|1[0-9]|2[0-5])$

And it will run the specified day (or all days) from the corresponding year.
It searches all relevant packages and executes top level classes in these packages.

If you want to exclude specific classes (like DTOs, ...) from executing place them in a folder either called:

  • modles or
  • refactored.

A possible folder structure could look like this:

advent-of-code/
├── src.main.java.dev.janetschel
│   ├── calendar
│   │   └── year2021/
│   │       └── day01/                // <-- all this structure is generated by 'make new'
│   │           ├── refactored/       // <-- classes in this folder (or models) are not executed
│   │           ├── Puzzle.java
│   │           ├── README.md
│   │           └── input.txt         // <-- created by fetch utils
│   └── utils/
├── Makefile 
└── template/                        // <-- change the files in this folder if you wish to modify your blueprint

When running/executing days, the output will be in following format:

Solutions for Advent of Code 2021
Day 01:
01.1: 1527 (-> took ~6.7ms [6699.458µs])
01.2: 1575 (-> took ~1.2ms [1208.291µs])

Fetch utils

The fetch utils will automatically fetch the input from the current day and create an input.txt file.
If the file has been created once, it is be cached and only read from -- not updated -- so the API from won't be spammed.

You need to do no setup for this -- except for your session-key. More information can be found here.

About

Advent of Code in Java/(Kotlin) with useful utils and a Makefile for easy templating

Topics

Resources

Stars

Watchers

Forks