adventofcode2017

package module
v0.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2025 License: GPL-3.0 Imports: 8 Imported by: 0

README

= Advent of code, 2017
:doctype: book
:toc:

image:https://godoc.org/gitlab.com/jhinrichsen/adventofcode2017?status.svg["godoc", link="https://godoc.org/gitlab.com/jhinrichsen/adventofcode2017"]
image:https://goreportcard.com/badge/gitlab.com/jhinrichsen/adventofcode2017["Go report card", link="https://goreportcard.com/report/gitlab.com/jhinrichsen/adventofcode2017"]
image:https://gitlab.com/jhinrichsen/adventofcode2017/badges/master/pipeline.svg[link="https://gitlab.com/jhinrichsen/adventofcode2017/-/commits/master",title="pipeline status"]
image:https://gitlab.com/jhinrichsen/adventofcode2017/badges/master/coverage.svg[link="https://gitlab.com/jhinrichsen/adventofcode2017/-/commits/master",title="coverage report"]

== Overview

Number of tries for a correct answer:

|===
| Day | Part 1 | Part 2
| 1   |   1    |   1
| 2   |   1    |   1
| 3   |   1    |   3
| 4   |   1    |   1
| 5   |   1    |   1
| 6   |   1    |   1
| 7   |   1    |   1
| 8   |   1    |   1
| 9   |   1    |   1
| 10  |        |
| 11  |        |
| 12  |        |
| 13  |        |
| 14  |        |
| 15  |        |
| 16  |        |
| 17  |        |
| 18  |        |
| 19  |        |
| 20  |        |
| 21  |        |
| 22  |        |
| 23  |        |
| 24  |        |
| 25  |        |
|===

== Day 1: Inverse Captcha

== Day 2: Corruption Checksum

== Day 3: Spiral Memory

=== Part 2

https://oeis.org/A141481

[source,pari]
----
{
	m=5;
	h=2*m-1;
	A=matrix(h, h);
	print1(A[m, m]=1, ", ");
	T=[[1, 0], [1, -1], [0, -1], [ -1, -1], [ -1, 0], [ -1, 1], [0, 1], [1, 1]];

	for (n=1, (h-2)^2-1,
		g=sqrtint(n);
		r=(g+g%2)\2;
		q=4*r^2;
		d=n-q;
		if (n<=q-2*r,
			j=d+3*r;
			k=r, if(n<=q, j=r; k=-d-r, if(n<=q+2*r, j=r-d; k=-r, j=-r; k=d-3*r)));
		j=j+m;
		k=k+m;
		s=0;
		for (c=1, 8, v=[j, k];
			v+=T[c];
			s=s+A[v[1], v[2]]);

		A[j, k]=s;
		print1(s, ", "))
}
----

I know a thing or two about C but this is just too dense to translate to Go.
The PARI based implementation uses no blocks, but comma operators all over the place and for loops in the arguments of a for loop.
I'll take the easy route and use the [https://oeis.org/A141481/b141481.txt] result table.

== Day 4: High-Entropy Passphrases

== Day 5: A Maze of Twisty Trampolines, All Alike

== Day 6: Memory Reallocation

== Day 7: Recursive Circus

== Day 8: I Heard You Like Registers

== Day 9: Stream Processing

== Day 10: Knot Hash

== Day 11: Hex Ed

== Day 12: Digital Plumber

== Day 13: Packet Scanners

== Day 14: Disk Defragmentation

== Day 15: Dueling Generators

== Day 16: Permutation Promenade

== Day 17: Spinlock

== Day 18: Duet

== Day 19: A Series of Tubes

== Day 20: Particle Swarm

== Day 21: Fractal Art

== Day 22: Sporifica Virus

== Day 23: Coprocessor Conflagration

== Day 24: Electromagnetic Moat

== Day 25: The Halting Problem

Documentation

Index

Constants

This section is empty.

Variables

View Source
var A141481 = []uint{}/* 479 elements not displayed */

A141481 Square spiral of sums of selected preceding terms, starting at 1. Table of a(n) for n = 0..478 (largest possible uint64) Source: https://oeis.org/A141481/b141481.txt

View Source
var ErrorDay10Length = fmt.Errorf("illegal length")

Functions

func Day00 added in v0.9.1

func Day00(s Puzzle, part1 bool) (uint, error)

Day00 solves the puzzle for day NN, and provides a result. The name `Day00` MUST be adjusted to `Day{{NN}}` for the given day NN. The identifier for day NN MUST be two digits even for single digit days (`Day07` not `Day7`). The name MUST NOT be changed to the puzzle name (`NotQuiteLisp`). The priority for implementations is maximum performance in runtime, and minimal garbage collection. Common practices for maintainability, ease of reading, clean code, are NOT REQUIRED. Implementations SHOULD use high performance parser using puzzle input as []byte and leave out the corresponding parser `NewPuzzle`. Implementations SHOULD limit the result types to `uint` (counts, sums), `string` (text) and `int` (solutions that include negative numbers, which is very rare).

func Day01Part1 added in v0.9.1

func Day01Part1(digits []byte) (sum uint)

Day01Part1 finds the sum of all digits that match the next digit.

func Day01Part2 added in v0.9.1

func Day01Part2(digits []byte) (sum uint)

Day01Part2 finds the sum of all digits that match the halfway around digit.

func Day02Part1 added in v0.9.1

func Day02Part1(spreadsheet [][]int) (sum uint)

Day02Part1 calculates the spreadsheet's checksum for smallest and largest cells.

func Day02Part2 added in v0.9.1

func Day02Part2(spreadsheet [][]int) (sum uint)

Day02Part2 calculates checksum for evenly divisible cells.

func Day03Part1 added in v0.9.1

func Day03Part1(square int) int

Day03Part1 returns the number of steps for a given square. A recursive implementation is used that produces a stack overflow for values around 1e8. The recursive call can be replaced by a loop based impl using delta() only.

func Day03Part2 added in v0.9.1

func Day03Part2(n uint) uint

Day03Part2 returns the first number larger than n of https://oeis.org/A141481.

func Day04Part1 added in v0.9.1

func Day04Part1(passphrases []string) (count uint)

Day04 returns the number of valid pass phrases. valid := contains no duplicate words, separated by space

func Day04Part2 added in v0.9.1

func Day04Part2(passphrases []string) (count uint)

func Day04Part2Valid added in v0.9.1

func Day04Part2Valid(passphrase string) bool

func Day05Part1

func Day05Part1(maze []int) int

Day05Part1 returns the number of steps until outside of maze.

func Day05Part2

func Day05Part2(maze []int) int

Day05Part2 returns the number of steps until outside of maze.

func Day06Part1 added in v0.9.1

func Day06Part1(banks Banks, activeBanks int) int

Day06Part1 returns number of redistribution cycles.

func Day06Part2 added in v0.9.1

func Day06Part2(banks Banks, activeBanks int) int

Day06Part2 returns number of redistribution cycles for a configuration already seen.

func Day07Part1 added in v0.9.1

func Day07Part1(ss []string) string

func Day07Part2 added in v0.9.1

func Day07Part2(ss []string) (uint, error)

Day07Part2 returns the excess weight to balance the complete tower.

func Day08Part1 added in v0.9.1

func Day08Part1(data []byte) (int, error)

func Day08Part2 added in v0.9.1

func Day08Part2(data []byte) (int, error)

Day08Part2 returns the highest value held in any register at any time during processing of the instructions.

func Day09Part1 added in v0.9.1

func Day09Part1(stream []byte) int

func Day09Part2 added in v0.9.1

func Day09Part2(stream []byte) int

Day09Part2 counts the number of non-canceled characters within garbage. The opening '<' and closing '>' are not counted. Canceled characters and the '!' doing the canceling are not counted either.

func Day10

func Day10(list []int, lengths []int) int

func Day10PreconditionLength

func Day10PreconditionLength(list []int, lengths []int) ([]int, error)

spec states "Lengths larger than the size of the list are invalid." which is a bit unclear as to wether this can occur in input or not. We opt for the safe side which makes it a precondition. Day10PreconditionLength checks if all length parameters are in list bounds. Returns a list of illegal length indices.

func Day10Reverse

func Day10Reverse(list []int, idx int, n int)

Day10Reverse in-place reverse slice list[idx:idx+n], wrapping n if n > len(list)

func Day12

func Day12(r io.Reader) int

Day12 returns number of programs being in the group that contains program ID 0.

func Day13UsingList

func Day13UsingList(l *node) int

Day13UsingList returns severity of whole trip through layers.

func Day13UsingSparseArray

func Day13UsingSparseArray(layers []int) int

Day13UsingSparseArray returns severity of whole trip through layers.

func NewProgram added in v0.9.1

func NewProgram(s string) (program, error)

NewProgram parses a string representation into a domain model. Examples: ktlj (57) fwft (72) -> ktlj, cntj, xhth

Types

type Banks

type Banks [16]int

func Day06

func Day06(banks Banks, activeBanks int) (Banks, int)

type Cmp

type Cmp int
const (
	EQ Cmp = iota
	NE
	LT
	LE
	GT
	GE
)

type Condition

type Condition struct {
	RA
	// contains filtered or unexported fields
}

type Disk added in v0.9.1

type Disk map[string]bool

type Instruction

type Instruction struct {
	Operation
	Condition
}

type Operation

type Operation struct {
	RA
	// contains filtered or unexported fields
}

type Puzzle added in v0.9.1

type Puzzle struct {
}

Puzzle acts as a generic name, implementations MUST adjust to concrete puzzle. All puzzles have a unique name that MUST be used instead of `Puzzle`, e.g. `NotQuiteLisp', the first puzzle ever (Day 1, 2015).

func NewPuzzle added in v0.9.1

func NewPuzzle(lines []string) (Puzzle, error)

NewPuzzle parses the puzzle input in text form into an efficient representation for day N. The parser function CAN be left out if the solver (`Day00`) is implemented using puzzle input []byte for maximum performance. Implementations CAN use puzzle input as []byte instead of []string for best performance, or if problem solution is grid based instead of line based.. When using []byte input, parser CAN rely on input in format end_of_line = lf, insert_final_newline = true, trim_trailing_whitespace = true. Parser DO NOT HAVE TO cater for malicious input, but use regular error handling e.g. when parsing numbers using strconv.Atoi(). Parser MUST NOT suppress or ignore errors.

type RA

type RA struct {
	// contains filtered or unexported fields
}

type Registers

type Registers map[string]int

func (Registers) Apply

func (a Registers) Apply(op Operation)

func (Registers) Step

func (a Registers) Step(i Instruction)

func (Registers) True

func (a Registers) True(c Condition) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL