Documentation ¶
Index ¶
- Constants
- Variables
- func CountAffirmatives(groups []Group) int
- func CountDistinctPossibleArrangements(r io.Reader) int
- func CountEncounteredTrees(tm TrajectoryMap, slope location.Slope) int
- func CountValidPasswords(r io.Reader) int
- func CountValidPasswordsUpdatedPolicy(r io.Reader) int
- func DetermineAccumulatorValueBeforeLoop(commands []Command) int
- func DetermineEncryptionKey(r io.Reader) int
- func EvaluateExpression(e Expression) int
- func FindEarliestBus(i Itinerary) (int, int)
- func FindEarliestTimestampWithDepartureCadence(i Itinerary) int
- func FindEncryptionWeakness(values []int, target int) (int, int)
- func FindFirstEncodingError(r io.Reader, preambleLength, lookbackLength int) (int, []int)
- func FindJoltDifferences(r io.Reader) map[int]int
- func FindMaxSeatID(r io.Reader) int
- func FindMissingSeatID(r io.Reader) int
- func FindNthSpokenNumber(r io.Reader, n int) int
- func FindSeatLocation(boardingPass string) (int, int)
- func NewCardQueue(cards []Card) *cardQueue
- func ParseDecks(r io.Reader) (Deck, Deck)
- func RepairReport(r io.Reader) int
- func RepairReportTriplet(r io.Reader) int
- func Run(commands []Command) int
- func SerializeRound(firstPlayer, secondPlayer Deck) string
- type Action
- type BagRules
- type Bus
- type Card
- type CardQueue
- type Circle
- type Command
- type Computer
- type CoordinateQueue
- type Cube
- type CubeCell
- type CubeStatus
- type Deck
- type Door
- type Edge
- type Encryptor
- type Expression
- type Floor
- type Food
- type FoodListing
- type Group
- type HexDirection
- type Instruction
- type Itinerary
- type NavigationInstruction
- type NeighboringStrategy
- type Op
- type Operand
- type Operation
- type Operator
- type Orientation
- type Passport
- type PasswordDBEntry
- type PasswordPolicy
- type Pixel
- type PolicyType
- type Program
- type Queue
- type RangeValidator
- type RoomCard
- type Rule
- type Ruleset
- type Seat
- type SeatingArrangement
- type Ship
- type Side
- type Stack
- type State
- type TicketRules
- type Tile
- type Tileset
- type Token
- type TokenQueue
- type TokenStack
- type TrajectoryMap
- type Validator
- type Version
Constants ¶
View Source
const ( Northward HexDirection = "n" Northeast = "ne" Eastward = "e" Southeast = "se" Southward = "s" Southwest = "sw" Westward = "w" Northwest = "nw" )
Variables ¶
View Source
var FirstVisible = NeighboringStrategy(func(locale location.Coordinate, seatsByLocation map[location.Coordinate]Seat) []Seat { var maxRow, maxCol int for l := range seatsByLocation { if l.Row > maxRow { maxRow = l.Row } if l.Col > maxCol { maxCol = l.Col } } type modifier func(location.Coordinate) location.Coordinate upwardLeftDiagonal := modifier(func(l location.Coordinate) location.Coordinate { return location.Coordinate{l.Row - 1, l.Col - 1} }) upward := modifier(func(l location.Coordinate) location.Coordinate { return location.Coordinate{l.Row - 1, l.Col} }) upwardRightDiagonal := modifier(func(l location.Coordinate) location.Coordinate { return location.Coordinate{l.Row - 1, l.Col + 1} }) left := modifier(func(l location.Coordinate) location.Coordinate { return location.Coordinate{l.Row, l.Col - 1} }) right := modifier(func(l location.Coordinate) location.Coordinate { return location.Coordinate{l.Row, l.Col + 1} }) downwardLeftDiagonal := modifier(func(l location.Coordinate) location.Coordinate { return location.Coordinate{l.Row + 1, l.Col - 1} }) down := modifier(func(l location.Coordinate) location.Coordinate { return location.Coordinate{l.Row + 1, l.Col} }) downwardRightDiagonal := modifier(func(l location.Coordinate) location.Coordinate { return location.Coordinate{l.Row + 1, l.Col + 1} }) modifiers := []modifier{ upwardLeftDiagonal, upward, upwardRightDiagonal, left, right, downwardLeftDiagonal, down, downwardRightDiagonal, } visibleNeighbors := make(chan Seat, len(modifiers)) var wg sync.WaitGroup for _, m := range modifiers { wg.Add(1) go func(origin location.Coordinate, mod modifier, out chan<- Seat, waitGroup *sync.WaitGroup) { current := location.Coordinate{origin.Row, origin.Col} for { current = mod(current) if seat, present := seatsByLocation[current]; present { out <- seat break } if current.Row < 0 || current.Col < 0 || current.Row > maxRow || current.Col > maxCol { break } } waitGroup.Done() }(locale, m, visibleNeighbors, &wg) } wg.Wait() close(visibleNeighbors) collected := map[location.Coordinate]struct{}{} neighbors := []Seat{} for neighbor := range visibleNeighbors { if _, seen := collected[neighbor.Location]; !seen { neighbors = append(neighbors, neighbor) collected[neighbor.Location] = struct{}{} } } return neighbors })
View Source
var NearestNeighbor = NeighboringStrategy(func(locale location.Coordinate, seatsByLocation map[location.Coordinate]Seat) []Seat { var neighbors []Seat neighboringLocations := []location.Coordinate{ {locale.Row - 1, locale.Col - 1}, {locale.Row - 1, locale.Col}, {locale.Row - 1, locale.Col + 1}, {locale.Row, locale.Col - 1}, {locale.Row, locale.Col + 1}, {locale.Row + 1, locale.Col - 1}, {locale.Row + 1, locale.Col}, {locale.Row + 1, locale.Col + 1}, } for _, l := range neighboringLocations { if seat, present := seatsByLocation[l]; present { neighbors = append(neighbors, seat) } } return neighbors })
Functions ¶
func CountAffirmatives ¶
func CountEncounteredTrees ¶
func CountEncounteredTrees(tm TrajectoryMap, slope location.Slope) int
func CountValidPasswords ¶
func DetermineEncryptionKey ¶
func EvaluateExpression ¶
func EvaluateExpression(e Expression) int
func FindEarliestBus ¶
func FindFirstEncodingError ¶
func FindMaxSeatID ¶
func FindMissingSeatID ¶
func FindSeatLocation ¶
func NewCardQueue ¶
func NewCardQueue(cards []Card) *cardQueue
func RepairReport ¶
func RepairReportTriplet ¶
func SerializeRound ¶
Types ¶
type BagRules ¶
func ParseBagRules ¶
func (BagRules) FindAncestorsOf ¶
func (BagRules) TotalDescendantsOf ¶
type Circle ¶
func (*Circle) AddAdditionalCups ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
func ParseProgram ¶
func PatchProgram ¶
type CoordinateQueue ¶
type CoordinateQueue interface { Enqueue(location.Coordinate) Dequeue() (location.Coordinate, error) Peek() (location.Coordinate, error) Size() int }
func NewCoordinateQueue ¶
func NewCoordinateQueue(coordinates ...location.Coordinate) CoordinateQueue
type Cube ¶
func ParseConwayCube ¶
func (Cube) CellCountByStatus ¶
func (c Cube) CellCountByStatus(status CubeStatus) int
type CubeCell ¶
type CubeCell struct { Coordinate location.Point Status CubeStatus }
func (CubeCell) NeighborLocations ¶
type Deck ¶
type Deck struct { Player int Queue *cardQueue }
func RecursiveBattle ¶
func (*Deck) PlaceCards ¶
type Expression ¶
type Expression []Token
func ParseExpression ¶
func ParseExpression(s string) Expression
func ParseExpressions ¶
func ParseExpressions(r io.Reader) []Expression
type Floor ¶
type Floor struct { AllDirections [][]HexDirection // contains filtered or unexported fields }
func ParseAllDirections ¶
func (*Floor) Follow ¶
func (f *Floor) Follow(directions []HexDirection)
func (Floor) GetBlackCount ¶
type FoodListing ¶
type FoodListing []Food
func ParseFoodListing ¶
func ParseFoodListing(r io.Reader) FoodListing
func (FoodListing) CountOccurrencesFor ¶
func (f FoodListing) CountOccurrencesFor(ingredients []string) map[string]int
func (FoodListing) FindNonAllergenicIngredients ¶
func (f FoodListing) FindNonAllergenicIngredients() ([]string, []string)
type Group ¶
func ParseGroups ¶
type HexDirection ¶
type HexDirection string
func ParseDirections ¶
func ParseDirections(value string) []HexDirection
type Instruction ¶
func (Instruction) Apply ¶
func (i Instruction) Apply(c *Computer)
type Itinerary ¶
func ParseShuttleItinerary ¶
type NavigationInstruction ¶
type NavigationInstruction struct {}
func ParseNavigationInstructions ¶
func ParseNavigationInstructions(r io.Reader) []NavigationInstruction
type NeighboringStrategy ¶
type NeighboringStrategy func(location.Coordinate, map[location.Coordinate]Seat) []Seat
type Orientation ¶
type Orientation int
const ( Unknown Orientation = iota Northbound Eastbound Southbound Westbound )
type Passport ¶
type Passport struct {
BirthYear, IssueYear, ExpirationYear, Height string
HairColor, EyeColor, PassportID, CountryID string
}
func ParsePassports ¶
type PasswordDBEntry ¶
type PasswordDBEntry struct { Policy PasswordPolicy Password string }
func (PasswordDBEntry) IsValid ¶
func (p PasswordDBEntry) IsValid(policyType ...PolicyType) bool
type PasswordPolicy ¶
type Queue ¶
func NewStringQueue ¶
func NewStringQueue() Queue
type RangeValidator ¶
type RangeValidator struct {
LowerBound, UpperBound int
}
func (RangeValidator) Validate ¶
func (r RangeValidator) Validate(i int) bool
type Seat ¶
type Seat struct { Location location.Coordinate Status State }
func (Seat) GetNeighbors ¶
func (s Seat) GetNeighbors(strategy NeighboringStrategy, seatsByLocation map[location.Coordinate]Seat) []Seat
type SeatingArrangement ¶
type SeatingArrangement []Seat
func ParseSeatingArrangement ¶
func ParseSeatingArrangement(r io.Reader) SeatingArrangement
func (SeatingArrangement) Equals ¶
func (s SeatingArrangement) Equals(other SeatingArrangement) bool
func (SeatingArrangement) RunSeatingCycle ¶
func (s SeatingArrangement) RunSeatingCycle(occupancyThreshold int, strategies ...NeighboringStrategy) SeatingArrangement
func (SeatingArrangement) SeatsByState ¶
func (s SeatingArrangement) SeatsByState(state State) []Seat
type Ship ¶
type Ship struct { Location location.Point Orientation Orientation Waypoint location.Point }
func (*Ship) Navigate ¶
func (s *Ship) Navigate(instructions []NavigationInstruction)
func (*Ship) NavigateByWaypoint ¶
func (s *Ship) NavigateByWaypoint(instructions []NavigationInstruction)
type Stack ¶
func NewIntStack ¶
func NewIntStack() Stack
type TicketRules ¶
func ParseTicketRules ¶
func ParseTicketRules(r io.Reader) (TicketRules, [][]int)
func (TicketRules) DetermineFieldLocale ¶
func (t TicketRules) DetermineFieldLocale(tickets [][]int) map[string]int
func (TicketRules) FindErrorScanRate ¶
func (t TicketRules) FindErrorScanRate(tickets [][]int) (int, [][]int)
type Tileset ¶
type Tileset []Tile
func ParseImageTiles ¶
func (Tileset) FindCorners ¶
func (*Tileset) ProperlyArrange ¶
func (t *Tileset) ProperlyArrange()
type TokenQueue ¶
type TokenQueue interface { Enqueue(Token) Dequeue() (Token, error) Peek() (Token, error) Size() int }
func NewTokenQueue ¶
func NewTokenQueue() TokenQueue
type TokenStack ¶
func NewTokenStack ¶
func NewTokenStack() TokenStack
type TrajectoryMap ¶
type TrajectoryMap struct { Trees map[location.Coordinate]struct{} Rows, Columns int }
func NewTrajectoryMap ¶
func NewTrajectoryMap(r io.Reader) TrajectoryMap
Source Files ¶
- adapter.go
- allergens.go
- boardingpass.go
- combat.go
- combo.go
- conway.go
- cups.go
- customs.go
- docking.go
- encodingerror.go
- handheld.go
- haversacks.go
- jurassic.go
- lobby.go
- monster.go
- navigation.go
- operators.go
- passports.go
- passwords.go
- recitation.go
- reportrepair.go
- seating.go
- shuttle.go
- trajectory.go
- translation.go
Click to show internal directories.
Click to hide internal directories.