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

View Source
const BroadcasterID = "broadcaster"

Variables

This section is empty.

Functions

This section is empty.

Types

type Broadcast

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

func (*Broadcast) GetDests

func (b *Broadcast) GetDests() []string

func (*Broadcast) GetID

func (b *Broadcast) GetID() string

func (*Broadcast) Receive

func (b *Broadcast) Receive(msg Message)

type Conjuncter

type Conjuncter interface {
	Module

	GetMemory() Memory
	SetMemory(string, Pulse)
	GetInputs() []string
	AllHigh() bool
}

type Conjunction

type Conjunction struct {
	ID string
	// contains filtered or unexported fields
}

func (*Conjunction) AllHigh

func (c *Conjunction) AllHigh() bool

func (*Conjunction) GetDests

func (c *Conjunction) GetDests() []string

func (*Conjunction) GetID

func (c *Conjunction) GetID() string

func (*Conjunction) GetInputs

func (c *Conjunction) GetInputs() []string

func (*Conjunction) GetMemory

func (c *Conjunction) GetMemory() Memory

func (*Conjunction) Receive

func (c *Conjunction) Receive(msg Message)

func (*Conjunction) SetMemory

func (c *Conjunction) SetMemory(id string, p Pulse)

type Exercise

type Exercise struct {
	common.BaseExercise
}

Exercise for Advent of Code 2023 day 20.

func (Exercise) One

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

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

func (Exercise) Two

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

Two returns the answer to the second part of the exercise. not: 2_237_580_152_160_073 (too high)

type FlipFlop

type FlipFlop struct {
	ID string

	State State
	// contains filtered or unexported fields
}

func (*FlipFlop) GetDests

func (ff *FlipFlop) GetDests() []string

func (*FlipFlop) GetID

func (ff *FlipFlop) GetID() string

func (*FlipFlop) GetState

func (ff *FlipFlop) GetState() State

func (*FlipFlop) Receive

func (ff *FlipFlop) Receive(msg Message)

func (*FlipFlop) SetState

func (ff *FlipFlop) SetState(s State)

type FlipFlopper

type FlipFlopper interface {
	Module

	GetState() State
	SetState(State)
}

type Memory

type Memory map[string]Pulse

func (Memory) String

func (m Memory) String() string

type Message

type Message struct {
	Src   string
	Dst   string
	Pulse Pulse
}

type MessageQueue

type MessageQueue []Message

func (*MessageQueue) Send

func (mq *MessageQueue) Send(src, dst string, p Pulse)

type ModConfig

type ModConfig map[string]Module

func (ModConfig) DebugPrint

func (cfg ModConfig) DebugPrint()

func (ModConfig) GetFeed

func (cfg ModConfig) GetFeed(id string) (*Conjunction, error)

find the module that sends a signal to the target

func (ModConfig) InitModules

func (cfg ModConfig) InitModules()

InitModules populates the memory of all conjunction modules and sets all flipflops to off.

func (ModConfig) ProcessQueue

func (cfg ModConfig) ProcessQueue() (int, int)

func (ModConfig) ProcessUntilHigh

func (cfg ModConfig) ProcessUntilHigh(cj Conjuncter) int

type Module

type Module interface {
	GetID() string
	Receive(Message)
	GetDests() []string
}

type Pulse

type Pulse int
const (
	Low Pulse = iota
	High
)

func (Pulse) String

func (i Pulse) String() string

type State

type State int
const (
	Off State = iota
	On
)

func (State) String

func (i State) String() string

Jump to

Keyboard shortcuts

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