Giter Club home page Giter Club logo

aoc-go's Introduction

๐ŸŽ„ Advent of Code in Go ๐ŸŽ„

go run main.go --day=1

aoc-go is a repository intended to automate some tasks related to Advent of Code, like fetching input data and provide a starting template for each day, as well as providing utility functions for commonly used tasks. The repository should be forked and used to solve puzzles directly in it. If a solutions folder is present, delete it after forking to get started on your own.

Get your session token

First thing you need is your session token from adventofcode.com. This is used to fetch your personalized input data from each puzzle. It can be found under the network tab in your dev tools. Check this post for assistance.

Once you have your token, copy .env.example, rename it to .env, and include your token in the AOC_SESSION spot. In your .env file you can also adjust what year of Advent of Code you want to work with. Defaults to 2022.

Usage

  • Make sure you have your .env file setup and both the AOC_SESSION and YEAR variables set.
  • From the root of this project, run for example go run main.go --day=1. This will fetch data for day 1 for the configured year and set up a template for you to get started.
  • Templates will be created at the path solutions/{year}/{day}.

The template

The template to get started each day looks like below. Additional utilities are provided in the utils package.

package main

import (
	"fmt"
	"os"

	"github.com/Haugen/aoc-go/internal/utils"
)

var data []string

func main() {
	path, _ := os.Getwd()
	data = utils.FilenameToArray(path + "/input.txt")

	part1()
}

func part1() {
	for _, line := range data {
		fmt.Println(line)
	}
}

Useful utils while solving puzzles

All utility functions are provided in the github.com/Haugen/aoc-go/internal/utils package.

Function Description
utils.IntToStr Convert an int to a string
utils.StrToInt Convert a string to an int
utils.StrToArray Convert a string to an array of strings
utils.StrArrayToIntArray Convert an array of string to an array of int
utils.SumArray Sum array of int

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.