exercises

package
v0.0.0-...-e61498d Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: Unlicense Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Day11

type Day11 struct {
	Monkeys []*Monkey
	Product int
}

Day11 is the exercise environment.

func (*Day11) ParseInput

func (d *Day11) ParseInput(instr string) error

ParseInput puts monkey information into struct

func (*Day11) ProcessRound

func (d *Day11) ProcessRound() error

ProcessRound processes a round of monkeys.

func (*Day11) ProcessRoundPart2

func (d *Day11) ProcessRoundPart2() error

ProcessRoundPart2 processes a round of monkeys.

type Exercise

type Exercise struct {
	common.BaseExercise
}

Exercise for Advent of Code 2022 day 11

func (Exercise) One

func (e Exercise) One(instr string) (any, error)

One returns the answer to the first part of the exercise. answer: 151312

func (Exercise) Two

func (e Exercise) Two(instr string) (any, error)

Two returns the answer to the second part of the exercise. answer: 51382025916

type Monkey

type Monkey struct {
	ID        int
	Items     []int
	Divisor   int
	Operator  string
	Scalar    int
	TargetOne int
	TargetTwo int
	Count     int
}

Monkey struct represents necessary aspect of a monkey for day 11. Items is a slice of worry levels for each item currently held by this monkey. Operation is a function that modifies a worry level after inspected. Test determines where an item is moved after inspection based on worry level.

func ParseMonkey

func ParseMonkey(mstr string) (*Monkey, error)

ParseMonkey parses a single monkey.

type MonkeyHeap

type MonkeyHeap []Monkey

MonkeyHeap implements heap.Interface and holds Monkeys. Ref https://golang.org/pkg/container/heap/

func (MonkeyHeap) Len

func (h MonkeyHeap) Len() int

Len is the number of elements in the collection.

func (MonkeyHeap) Less

func (h MonkeyHeap) Less(i, j int) bool

Less is greater-than here so we can pop *larger* items.

func (*MonkeyHeap) Pop

func (h *MonkeyHeap) Pop() interface{}

Pop removes and returns the maximum element (according to Less) from the heap.

func (*MonkeyHeap) Push

func (h *MonkeyHeap) Push(x interface{})

Push pushes the element x onto the heap.

func (MonkeyHeap) Swap

func (h MonkeyHeap) Swap(i, j int)

Swap swaps the elements with indexes i and j.

Jump to

Keyboard shortcuts

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