advent

package
v0.0.0-...-8eca7a6 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

DayN is an empty day to be copy/pasted for a new day It contains an Init() function to load input, setup the day, and Run to run the puzzle

Index

Constants

View Source
const (
	SideUp    = 0x01
	SideRight = 0x02
	SideDown  = 0x04
	SideLeft  = 0x08
)

Variables

View Source
var (
	StepStyle = lipgloss.NewStyle().Foreground(color.LightYellow11)
)

Functions

func DensityColor

func DensityColor(cellX, cellY int, dots [8]byte) (fg, bg int, ok bool)

DensityColor colors cells based on how many dots are on. 0 dots -> gray 1–2 -> blue 3–4 -> green 5–6 -> yellow 7–8 -> red

func FindValue

func FindValue[T int | uint | byte | rune | bool](board [][]T, c T) (x, y int)

find

func GetBoardValue

func GetBoardValue[T int | uint | byte | rune | bool](x, y int, board [][]T) T

GetBoardValue returns a rune/int/bool at x,y in the input or the empty value if out of bounds

func MakeBoard

func MakeBoard[T any](width, height int) [][]T

func MustAtoi

func MustAtoi[T string | []byte](s T) int

func ReadInputAsIntBoard

func ReadInputAsIntBoard(filename string) ([][]int, error)

read input as a series of rune lines

func ReadInputAsRunes

func ReadInputAsRunes(filename string) ([][]rune, error)

read input as a series of rune lines

func RenderBraille

func RenderBraille(grid [][]byte) string

RenderBraille renders a grid of bytes as a string of Unicode braille cells. grid[y][x] == 0 => pixel off, != 0 => pixel on.

func RenderBrailleWithColor

func RenderBrailleWithColor(grid [][]byte, colorFn BrailleColorFunc) string

RenderBrailleWithColor renders a grid of bytes as a string of Unicode braille cells and uses colorFn to optionally wrap each cell in ANSI color codes.

grid[y][x] == 0 => pixel off grid[y][x] != 0 => pixel "on" with that value (used only by colorFn)

func Run

func Run(d Day, filename string, opts ...Option) error

func RunVisual

func RunVisual(d Day, filename string, opts ...Option) error

func ValidPosition

func ValidPosition(p Point, width, height int) bool

Types

type BrailleColorFunc

type BrailleColorFunc func(cellX, cellY int, dots [8]byte) (fg, bg int, ok bool)

BrailleColorFunc decides how to color a single Braille cell.

cellX, cellY: braille cell coordinates (0-based) in the output grid dots: 8 bytes, one per dot (1..8), 0 = off, non-zero = whatever was in grid

Return values:

fg:  0–255 for 256-color foreground, or -1 for "no fg color"
bg:  0–255 for 256-color background, or -1 for "no bg color"
ok:  if false, RenderBrailleWithColor will render without any color

type Day

type Day interface {
	Day() int
	Init(filename string, options *Options) error
	Run(updates chan<- DayUpdate) error
}

type Day1

type Day1 struct {
	*Options
	// contains filtered or unexported fields
}

func (*Day1) Day

func (d *Day1) Day() int

func (*Day1) Init

func (d *Day1) Init(filename string, options *Options) (err error)

Init loads in the input from the file and initializes the Day

func (*Day1) Progress

func (d *Day1) Progress() bool

func (*Day1) Run

func (d *Day1) Run(updates chan<- DayUpdate) error

type Day2

type Day2 struct {
	*Options
	// contains filtered or unexported fields
}

func (*Day2) Day

func (d *Day2) Day() int

func (*Day2) Init

func (d *Day2) Init(filename string, options *Options) (err error)

Init loads in the input from the file and initializes the Day

func (*Day2) Progress

func (d *Day2) Progress() (done bool)

Progress progresses one "step" and returns true if finished

func (*Day2) Run

func (d *Day2) Run(updates chan<- DayUpdate) error

type Day3

type Day3 struct {
	*Options
	// contains filtered or unexported fields
}

func (*Day3) Day

func (d *Day3) Day() int

func (*Day3) Init

func (d *Day3) Init(filename string, options *Options) (err error)

Init loads in the input from the file and initializes the Day

func (*Day3) Run

func (d *Day3) Run(updates chan<- DayUpdate) error

type Day4

type Day4 struct {
	*Options
	// contains filtered or unexported fields
}

func (*Day4) Day

func (d *Day4) Day() int

func (*Day4) Init

func (d *Day4) Init(filename string, options *Options) (err error)

Init loads in the input from the file and initializes the Day

func (*Day4) Run

func (d *Day4) Run(updates chan<- DayUpdate) error

type Day5

type Day5 struct {
	*Options
	// contains filtered or unexported fields
}

func (*Day5) Day

func (d *Day5) Day() int

func (*Day5) Init

func (d *Day5) Init(filename string, options *Options) (err error)

Init loads in the input from the file and initializes the Day

func (*Day5) Run

func (d *Day5) Run(updates chan<- DayUpdate) error

type Day6

type Day6 struct {
	*Options
	// contains filtered or unexported fields
}

func (*Day6) Day

func (d *Day6) Day() int

func (*Day6) Init

func (d *Day6) Init(filename string, options *Options) (err error)

Init loads in the input from the file and initializes the Day

func (*Day6) Run

func (d *Day6) Run(updates chan<- DayUpdate) error

type Day7

type Day7 struct {
	*Options
	// contains filtered or unexported fields
}

func (*Day7) Day

func (d *Day7) Day() int

func (*Day7) Init

func (d *Day7) Init(filename string, options *Options) (err error)

Init loads in the input from the file and initializes the Day

func (*Day7) Run

func (d *Day7) Run(updates chan<- DayUpdate) error

type Day8

type Day8 struct {
	*Options
	// contains filtered or unexported fields
}

func (*Day8) Day

func (d *Day8) Day() int

func (*Day8) Init

func (d *Day8) Init(filename string, options *Options) (err error)

Init loads in the input from the file and initializes the Day

func (*Day8) Run

func (d *Day8) Run(updates chan<- DayUpdate) error

type Day9

type Day9 struct {
	*Options
	// contains filtered or unexported fields
}

func (*Day9) Day

func (d *Day9) Day() int

func (*Day9) Init

func (d *Day9) Init(filename string, options *Options) (err error)

Init loads in the input from the file and initializes the Day

func (*Day9) Run

func (d *Day9) Run(updates chan<- DayUpdate) error

type Day10

type Day10 struct {
	*Options
	// contains filtered or unexported fields
}

func (*Day10) Day

func (d *Day10) Day() int

func (*Day10) Init

func (d *Day10) Init(filename string, options *Options) (err error)

Init loads in the input from the file and initializes the Day

func (*Day10) Run

func (d *Day10) Run(updates chan<- DayUpdate) error

type Day11

type Day11 struct {
	*Options
	// contains filtered or unexported fields
}

func (*Day11) Day

func (d *Day11) Day() int

func (*Day11) Init

func (d *Day11) Init(filename string, options *Options) (err error)

Init loads in the input from the file and initializes the Day

func (*Day11) Run

func (d *Day11) Run(updates chan<- DayUpdate) error

type Day12

type Day12 struct {
	*Options
	// contains filtered or unexported fields
}

func (*Day12) Day

func (d *Day12) Day() int

func (*Day12) Init

func (d *Day12) Init(filename string, options *Options) (err error)

Init loads in the input from the file and initializes the Day

func (*Day12) Run

func (d *Day12) Run(updates chan<- DayUpdate) error

type DayN

type DayN struct {
	*Options
	// contains filtered or unexported fields
}

func (*DayN) Day

func (d *DayN) Day() int

func (*DayN) Init

func (d *DayN) Init(filename string, options *Options) (err error)

Init loads in the input from the file and initializes the Day

func (*DayN) Run

func (d *DayN) Run(updates chan<- DayUpdate) error

type DayUpdate

type DayUpdate struct {
	View     string
	Solution string
	Done     bool
}

type Direction

type Direction int

clockwise directions

const (
	DirectionUp Direction = iota
	DirectionRight
	DirectionDown
	DirectionLeft
	DirectionUpRight
	DirectionDownRight
	DirectionDownLeft
	DirectionUpLeft
)

func DirectionFromOffset

func DirectionFromOffset(offset Point) Direction

func (Direction) MinTurns

func (d Direction) MinTurns(other Direction) int

func (Direction) OffsetMultiplier

func (d Direction) OffsetMultiplier() (x, y int)

func (Direction) String

func (d Direction) String() string

type Matrix

type Matrix [][]byte

Matrix represents the board of cells on which the game is played.

func NewMatrix

func NewMatrix(height, width int) Matrix

NewMatrix creates a new Matrix with the given height and width. It returns an error if the height is less than 20 to allow for a buffer zone of 20 lines.

func (*Matrix) DeepCopy

func (m *Matrix) DeepCopy() *Matrix

type Option

type Option func(*Options)

Option is a functional option type that modifies the Options.

func WithDelay

func WithDelay(delay int) Option

WithDelay sets the Delay option.

func WithQuiet

func WithQuiet(quiet bool) Option

WithDelay sets the Delay option.

type Options

type Options struct {
	Delay int
	Quiet bool
}

Options holds the configurable parameters for a service or feature.

func NewRun

func NewRun(opts ...Option) *Options

type Point

type Point struct {
	X int
	Y int
}

func (Point) String

func (p Point) String() string

type PositionDirection

type PositionDirection struct {
	Point
	Direction Direction
}

type Tetrimino

type Tetrimino struct {
	// Value is the character identifier for the Tetrimino (I, O, T, S, Z, J, L).
	// This is used internally and may differ from the display representation.
	Value byte

	// Cells represents the shape of the Tetrimino as a 2D grid.
	// True indicates a Mino is present in the cell, false indicates empty space.
	Cells [][]bool

	// Position tracks the coordinate of the Tetrimino's top-left corner in the game matrix.
	// This serves as the reference point for all movement and rotation operations.
	Position Point
	// contains filtered or unexported fields
}

from https://github.com/Broderick-Westrope/tetrigo/blob/main/pkg/tetris/tetrimino.go A Tetrimino is a geometric Tetris piece formed by connecting four square blocks (Minos) along their edges. Each Tetrimino has a unique shape, position, rotation state, and rotation behavior defined by the Super Rotation System (SRS).

func (*Tetrimino) DeepCopy

func (t *Tetrimino) DeepCopy() *Tetrimino

DeepCopy creates a deep copy of the Tetrimino. This is useful when you need to modify a Tetrimino without affecting the original.

func (*Tetrimino) FillCount

func (t *Tetrimino) FillCount() int

count how many squares are filled

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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