Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
7c4033a8d1
|
|||
060cfeb610
|
|||
46cb381e8d
|
|||
b29ea5d936
|
|||
20a7e892ab
|
|||
e289bd9f54
|
|||
dd5af1f2cc
|
|||
0b3cdc2331
|
|||
2d6150e318
|
|||
1784ab77c8
|
|||
9a4fb7c734
|
|||
52737dd7c3
|
@ -28,7 +28,7 @@ func (d *Day07) Part1() string {
|
||||
var highestVal int64
|
||||
var highestSequence []int64
|
||||
|
||||
allSequences := utilities.GetPermutations([]int64{0, 1, 2, 3, 4}...)
|
||||
allSequences := utilities.GetPermutations([]int64{0, 1, 2, 3, 4})
|
||||
for _, sequence := range allSequences {
|
||||
if len(sequence) != len(d.amps) {
|
||||
panic("input sequence does not match up to number of amplifiers")
|
||||
@ -68,7 +68,7 @@ func (d *Day07) Part2() string {
|
||||
var highestVal int64
|
||||
var highestSequence []int64
|
||||
|
||||
allSequences := utilities.GetPermutations([]int64{5, 6, 7, 8, 9}...)
|
||||
allSequences := utilities.GetPermutations([]int64{5, 6, 7, 8, 9})
|
||||
for _, sequence := range allSequences {
|
||||
if len(sequence) != len(d.amps) {
|
||||
panic("input sequence does not match up to number of amplifiers")
|
||||
|
60
days/14.go
60
days/14.go
@ -10,15 +10,18 @@ import (
|
||||
)
|
||||
|
||||
type reaction struct {
|
||||
inputs map[string]int64
|
||||
inputs map[string]int
|
||||
output u.Pair[string, int]
|
||||
}
|
||||
|
||||
type Day14 struct {
|
||||
reactions []reaction
|
||||
leftovers map[string]int
|
||||
}
|
||||
|
||||
func (d *Day14) Parse() {
|
||||
d.leftovers = make(map[string]int)
|
||||
|
||||
lines := u.GetStringLines("14p")
|
||||
d.reactions = make([]reaction, len(lines))
|
||||
for i, line := range lines {
|
||||
@ -29,10 +32,10 @@ func (d *Day14) Parse() {
|
||||
outPair := strings.Split(output, " ")
|
||||
outAmt, _ := strconv.Atoi(outPair[0])
|
||||
d.reactions[i].output = u.Pair[string, int]{First: outPair[1], Second: outAmt}
|
||||
d.reactions[i].inputs = make(map[string]int64)
|
||||
d.reactions[i].inputs = make(map[string]int)
|
||||
for _, input := range inputs {
|
||||
pair := strings.Split(input, " ")
|
||||
d.reactions[i].inputs[pair[1]], _ = strconv.ParseInt(pair[0], 10, 64)
|
||||
d.reactions[i].inputs[pair[1]], _ = strconv.Atoi(pair[0])
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -51,7 +54,7 @@ func (d Day14) Num() int {
|
||||
return 14
|
||||
}
|
||||
|
||||
func (d *Day14) getOreRequiredForFuel(qty int64) int64 {
|
||||
func (d *Day14) oreRequiredStock(qty int64) int64 {
|
||||
oreRequired := int64(0)
|
||||
needs := map[string]int64{
|
||||
"FUEL": qty,
|
||||
@ -59,36 +62,33 @@ func (d *Day14) getOreRequiredForFuel(qty int64) int64 {
|
||||
excess := make(map[string]int64)
|
||||
|
||||
getFromExcess := func(qty int64, chemical string) int64 {
|
||||
available := u.Min(excess[chemical], qty)
|
||||
excess[chemical] -= available
|
||||
return available
|
||||
inStock := excess[chemical]
|
||||
qty -= inStock
|
||||
excess[chemical] = int64(math.Min(math.Abs(float64(qty)), 0))
|
||||
return inStock - excess[chemical]
|
||||
}
|
||||
|
||||
for len(needs) > 0 {
|
||||
keys := u.MapKeys(needs)
|
||||
producing := keys[0]
|
||||
qtyRequired := needs[producing]
|
||||
delete(needs, producing)
|
||||
chemical := keys[len(keys)-1]
|
||||
qtyRequired := needs[chemical]
|
||||
delete(needs, chemical)
|
||||
|
||||
fromExcess := getFromExcess(qtyRequired, producing)
|
||||
if fromExcess == qtyRequired {
|
||||
continue
|
||||
}
|
||||
fromExcess := getFromExcess(qtyRequired, chemical)
|
||||
qtyRequired -= fromExcess
|
||||
|
||||
reaction := d.getReactionProducing(producing)
|
||||
|
||||
reaction := d.getReactionProducing(chemical)
|
||||
qtyProduced := int64(reaction.output.Second)
|
||||
reactionsNeeded := int64(math.Ceil(float64(qtyRequired) / float64(qtyProduced)))
|
||||
ingredients := reaction.inputs
|
||||
|
||||
excess[producing] = (qtyProduced * reactionsNeeded) - qtyRequired
|
||||
n := int64(math.Ceil(float64(qtyRequired) / float64(qtyProduced)))
|
||||
|
||||
for reagent, inputQty := range reaction.inputs {
|
||||
qtyNeeded := inputQty * reactionsNeeded
|
||||
if reagent == "ORE" {
|
||||
oreRequired += qtyNeeded
|
||||
excess[chemical] = (qtyProduced * n) - qtyRequired
|
||||
for ingredient, qtyIngredient := range ingredients {
|
||||
if ingredient == "ORE" {
|
||||
oreRequired += int64(int64(qtyIngredient) * n)
|
||||
} else {
|
||||
needs[reagent] += qtyNeeded
|
||||
needs[ingredient] += int64(qtyIngredient) * n
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -97,13 +97,13 @@ func (d *Day14) getOreRequiredForFuel(qty int64) int64 {
|
||||
}
|
||||
|
||||
func (d *Day14) Part1() string {
|
||||
neededOre := d.getOreRequiredForFuel(1)
|
||||
neededOre := d.oreRequiredStock(1)
|
||||
return fmt.Sprintf("%s%d%s", u.TextBold, neededOre, u.TextReset)
|
||||
}
|
||||
|
||||
func (d *Day14) Part2() string {
|
||||
oreAvailable := int64(1000000000000)
|
||||
estimate := oreAvailable / d.getOreRequiredForFuel(1)
|
||||
estimate := oreAvailable / d.oreRequiredStock(1)
|
||||
|
||||
high := estimate * 2
|
||||
low := estimate
|
||||
@ -112,17 +112,15 @@ func (d *Day14) Part2() string {
|
||||
lastFailure := high
|
||||
fuelProduced := low
|
||||
|
||||
for math.Abs(float64(lastFailure-lastSuccess)) > 1 {
|
||||
oreConsumed := d.getOreRequiredForFuel(fuelProduced)
|
||||
adjustment := (lastFailure - lastSuccess) / 2
|
||||
for math.Abs(float64(lastFailure)-float64(lastSuccess)) > 1 {
|
||||
oreConsumed := d.oreRequiredStock(fuelProduced)
|
||||
if oreConsumed < oreAvailable {
|
||||
lastSuccess = fuelProduced
|
||||
fuelProduced += (lastFailure - lastSuccess) / 2
|
||||
} else {
|
||||
lastFailure = fuelProduced
|
||||
adjustment = -adjustment
|
||||
fuelProduced -= (lastFailure - lastSuccess) / 2
|
||||
}
|
||||
|
||||
fuelProduced += adjustment
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%s%d%s", u.TextBold, lastSuccess, u.TextReset)
|
||||
|
332
days/15.go
332
days/15.go
@ -1,332 +0,0 @@
|
||||
package days
|
||||
|
||||
//go:generate stringer -type=cellStatus,responseType,dirType -output=15_types_string.go
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
"sort"
|
||||
|
||||
u "parnic.com/aoc2019/utilities"
|
||||
)
|
||||
|
||||
type point u.Pair[int, int]
|
||||
type cellStatus int
|
||||
type responseType int
|
||||
type dirType int
|
||||
|
||||
const (
|
||||
cellStatusUnknown cellStatus = iota
|
||||
cellStatusWall
|
||||
cellStatusOpen
|
||||
cellStatusGoal
|
||||
)
|
||||
|
||||
const (
|
||||
responseWall responseType = iota
|
||||
responseSuccess
|
||||
responseFoundGoal
|
||||
)
|
||||
|
||||
const maxVisited = 3
|
||||
|
||||
const (
|
||||
dirNorth dirType = iota + 1
|
||||
dirSouth
|
||||
dirWest
|
||||
dirEast
|
||||
|
||||
dirFirst = dirNorth
|
||||
dirLast = dirEast
|
||||
)
|
||||
|
||||
var dirOrders = [][]dirType{
|
||||
{dirNorth, dirSouth, dirWest, dirEast},
|
||||
{dirSouth, dirWest, dirEast, dirNorth},
|
||||
{dirWest, dirEast, dirNorth, dirSouth},
|
||||
{dirEast, dirNorth, dirSouth, dirWest},
|
||||
}
|
||||
|
||||
// turned out to be unnecessary on multiple datasets i tried. increases the iterations 6x
|
||||
// var dirOrders = u.GetPermutations(dirNorth, dirSouth, dirWest, dirEast)
|
||||
|
||||
type visitedStatus struct {
|
||||
timesVisited int
|
||||
distanceFromStart int
|
||||
}
|
||||
|
||||
type Day15 struct {
|
||||
program u.IntcodeProgram
|
||||
grid map[point]cellStatus
|
||||
visited map[point]*visitedStatus
|
||||
shortestPath []point
|
||||
pos point
|
||||
goalPos point
|
||||
}
|
||||
|
||||
func (d *Day15) Parse() {
|
||||
d.program = u.LoadIntcodeProgram("15p")
|
||||
d.grid = map[point]cellStatus{
|
||||
{First: 0, Second: 0}: cellStatusOpen,
|
||||
}
|
||||
d.visited = map[point]*visitedStatus{
|
||||
{First: 0, Second: 0}: {timesVisited: 1},
|
||||
}
|
||||
d.shortestPath = []point{{}}
|
||||
}
|
||||
|
||||
func (d Day15) Num() int {
|
||||
return 15
|
||||
}
|
||||
|
||||
func (d Day15) getPointInDirection(pos point, dir dirType) point {
|
||||
target := pos
|
||||
switch dir {
|
||||
case dirNorth:
|
||||
target.First--
|
||||
case dirSouth:
|
||||
target.First++
|
||||
case dirWest:
|
||||
target.Second--
|
||||
case dirEast:
|
||||
target.Second++
|
||||
}
|
||||
|
||||
return target
|
||||
}
|
||||
|
||||
func (d Day15) getCellTypeInDirection(pos point, dir dirType) (cellStatus, point) {
|
||||
target := d.getPointInDirection(pos, dir)
|
||||
return d.grid[target], target
|
||||
}
|
||||
|
||||
func (d Day15) getAdjacentCellsOfType(pos point, cellType cellStatus) []point {
|
||||
points := make([]point, 0, 4)
|
||||
for i := dirFirst; i <= dirLast; i++ {
|
||||
adjacentCell := d.getPointInDirection(pos, i)
|
||||
if d.grid[adjacentCell] == cellType {
|
||||
points = append(points, adjacentCell)
|
||||
}
|
||||
}
|
||||
return points
|
||||
}
|
||||
|
||||
func (d Day15) getDirToNextCellType(pos point, t cellStatus, maxNumVisited int, dirs []dirType) (dirType, point, error) {
|
||||
for _, dir := range dirs {
|
||||
cellInDirection, targetCell := d.getCellTypeInDirection(pos, dir)
|
||||
if cellInDirection == t {
|
||||
_, visitedTargetExists := d.visited[targetCell]
|
||||
foundUnknown := t == cellStatusUnknown && !visitedTargetExists
|
||||
foundOther := t != cellStatusUnknown && visitedTargetExists && d.visited[targetCell].timesVisited <= maxNumVisited
|
||||
if foundUnknown || foundOther {
|
||||
return dir, targetCell, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dirFirst, point{}, fmt.Errorf("no %v tiles around %v", t, pos)
|
||||
}
|
||||
|
||||
func (d *Day15) Draw() {
|
||||
min := point{First: math.MaxInt, Second: math.MaxInt}
|
||||
max := point{First: math.MinInt, Second: math.MinInt}
|
||||
for p := range d.grid {
|
||||
if p.First < min.First {
|
||||
min.First = p.First
|
||||
}
|
||||
if p.First > max.First {
|
||||
max.First = p.First
|
||||
}
|
||||
if p.Second < min.Second {
|
||||
min.Second = p.Second
|
||||
}
|
||||
if p.Second > max.Second {
|
||||
max.Second = p.Second
|
||||
}
|
||||
}
|
||||
|
||||
for x := min.First; x <= max.First; x++ {
|
||||
for y := min.Second; y <= max.Second; y++ {
|
||||
p := point{First: x, Second: y}
|
||||
switch d.grid[p] {
|
||||
case cellStatusGoal:
|
||||
fmt.Printf("%s@%s", u.ColorBrightGreen, u.TextReset)
|
||||
case cellStatusOpen:
|
||||
if p == d.pos {
|
||||
fmt.Print(u.BackgroundBrightRed)
|
||||
} else if x == 0 && y == 0 {
|
||||
fmt.Print(u.BackgroundYellow)
|
||||
} else if u.ArrayContains(d.shortestPath, p) {
|
||||
fmt.Print(u.BackgroundGreen)
|
||||
} else if d.visited[p] != nil && d.visited[p].timesVisited > maxVisited {
|
||||
fmt.Print(u.ColorYellow)
|
||||
fmt.Print(u.BackgroundBlack)
|
||||
} else if d.visited[p] != nil && d.visited[p].timesVisited > 1 {
|
||||
fmt.Print(u.BackgroundMagenta)
|
||||
} else {
|
||||
fmt.Print(u.BackgroundBlue)
|
||||
}
|
||||
fmt.Printf(".%s", u.TextReset)
|
||||
case cellStatusWall:
|
||||
fmt.Print("█")
|
||||
case cellStatusUnknown:
|
||||
fmt.Print(" ")
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Day15) markShortestPath() {
|
||||
pos := d.goalPos
|
||||
checkOffsets := []point{
|
||||
{First: -1, Second: 0},
|
||||
{First: 1, Second: 0},
|
||||
{First: 0, Second: -1},
|
||||
{First: 0, Second: 1},
|
||||
}
|
||||
|
||||
checkPt := func(pt point) (bool, int) {
|
||||
if v, exists := d.visited[pt]; exists && d.grid[pt] == cellStatusOpen {
|
||||
return true, v.distanceFromStart
|
||||
}
|
||||
return false, math.MaxInt
|
||||
}
|
||||
|
||||
d.shortestPath = []point{d.goalPos}
|
||||
|
||||
for pos.First != 0 || pos.Second != 0 {
|
||||
lowestDist := math.MaxInt
|
||||
lowestPoint := point{}
|
||||
for _, pt := range checkOffsets {
|
||||
newPt := point{First: pos.First + pt.First, Second: pos.Second + pt.Second}
|
||||
if found, dist := checkPt(newPt); found && dist < lowestDist {
|
||||
lowestDist = dist
|
||||
lowestPoint = newPt
|
||||
}
|
||||
}
|
||||
|
||||
d.shortestPath = append(d.shortestPath, lowestPoint)
|
||||
pos = lowestPoint
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Day15) exploreFullMap() map[point]*visitedStatus {
|
||||
grids := make([]map[point]cellStatus, 0, len(dirOrders))
|
||||
goalVisited := d.visited
|
||||
|
||||
for _, dirOrder := range dirOrders {
|
||||
d.program.Reset()
|
||||
|
||||
targetPos := point{}
|
||||
nextDir := dirFirst
|
||||
distFromStart := 0
|
||||
|
||||
d.pos = point{}
|
||||
d.visited = map[point]*visitedStatus{
|
||||
{First: 0, Second: 0}: {timesVisited: 1},
|
||||
}
|
||||
d.grid = map[point]cellStatus{
|
||||
{First: 0, Second: 0}: cellStatusOpen,
|
||||
}
|
||||
d.program.RunIn(func(inputStep int) int64 {
|
||||
var err error
|
||||
nextDir, targetPos, err = d.getDirToNextCellType(d.pos, cellStatusUnknown, 0, dirOrder)
|
||||
if err != nil {
|
||||
// ensure we never try to go back into the trapped spot
|
||||
d.visited[d.pos].timesVisited = maxVisited + 1
|
||||
for x := 1; x <= maxVisited && err != nil; x++ {
|
||||
nextDir, targetPos, err = d.getDirToNextCellType(d.pos, cellStatusOpen, x, dirOrder)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
// d.Draw()
|
||||
// panic(err)
|
||||
d.program.Stop()
|
||||
}
|
||||
|
||||
return int64(nextDir)
|
||||
}, func(val int64, state u.IntcodeProgramState) {
|
||||
rVal := responseType(val)
|
||||
|
||||
p := d.getPointInDirection(d.pos, nextDir)
|
||||
shouldMove := true
|
||||
switch rVal {
|
||||
case responseWall:
|
||||
d.grid[p] = cellStatusWall
|
||||
shouldMove = false
|
||||
case responseSuccess:
|
||||
d.grid[p] = cellStatusOpen
|
||||
case responseFoundGoal:
|
||||
d.grid[p] = cellStatusGoal
|
||||
}
|
||||
|
||||
if shouldMove {
|
||||
d.pos = targetPos
|
||||
if d.visited[d.pos] == nil {
|
||||
d.visited[d.pos] = &visitedStatus{}
|
||||
distFromStart++
|
||||
} else {
|
||||
distFromStart--
|
||||
}
|
||||
d.visited[d.pos].timesVisited++
|
||||
d.visited[d.pos].distanceFromStart = distFromStart
|
||||
}
|
||||
|
||||
if rVal == responseFoundGoal {
|
||||
// d.Draw()
|
||||
d.goalPos = targetPos
|
||||
goalVisited = d.visited
|
||||
}
|
||||
})
|
||||
|
||||
grids = append(grids, d.grid)
|
||||
}
|
||||
|
||||
d.grid = map[point]cellStatus{
|
||||
{First: 0, Second: 0}: cellStatusOpen,
|
||||
}
|
||||
for _, grid := range grids {
|
||||
keys := u.MapKeys(grid)
|
||||
for _, key := range keys {
|
||||
d.grid[key] = grid[key]
|
||||
}
|
||||
}
|
||||
|
||||
return goalVisited
|
||||
}
|
||||
|
||||
func (d *Day15) tagDistanceRecursive(pos, last point, dist int, distances map[point]int) {
|
||||
distances[pos] = dist
|
||||
for _, cell := range d.getAdjacentCellsOfType(pos, cellStatusOpen) {
|
||||
if cell == last {
|
||||
continue
|
||||
}
|
||||
d.tagDistanceRecursive(cell, pos, dist+1, distances)
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Day15) Part1() string {
|
||||
d.visited = d.exploreFullMap()
|
||||
d.markShortestPath()
|
||||
|
||||
for _, visited := range d.visited {
|
||||
visited.timesVisited = 1
|
||||
}
|
||||
d.pos = point{}
|
||||
d.Draw()
|
||||
|
||||
return fmt.Sprintf("Moves required to reach target: %s%d%s", u.TextBold, d.visited[d.goalPos].distanceFromStart, u.TextReset)
|
||||
}
|
||||
|
||||
func (d *Day15) Part2() string {
|
||||
startLoc := d.goalPos
|
||||
distanceMap := map[point]int{startLoc: 0}
|
||||
|
||||
d.tagDistanceRecursive(startLoc, point{}, 0, distanceMap)
|
||||
|
||||
cellDistances := u.MapValues(distanceMap)
|
||||
sort.Slice(cellDistances, func(i, j int) bool { return cellDistances[i] > cellDistances[j] })
|
||||
|
||||
return fmt.Sprintf("%s%d%s", u.TextBold, cellDistances[0], u.TextReset)
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
// Code generated by "stringer -type=cellStatus,responseType,dirType -output=15_types_string.go"; DO NOT EDIT.
|
||||
|
||||
package days
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[cellStatusUnknown-0]
|
||||
_ = x[cellStatusWall-1]
|
||||
_ = x[cellStatusOpen-2]
|
||||
_ = x[cellStatusGoal-3]
|
||||
}
|
||||
|
||||
const _cellStatus_name = "cellStatusUnknowncellStatusWallcellStatusOpencellStatusGoal"
|
||||
|
||||
var _cellStatus_index = [...]uint8{0, 17, 31, 45, 59}
|
||||
|
||||
func (i cellStatus) String() string {
|
||||
if i < 0 || i >= cellStatus(len(_cellStatus_index)-1) {
|
||||
return "cellStatus(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _cellStatus_name[_cellStatus_index[i]:_cellStatus_index[i+1]]
|
||||
}
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[responseWall-0]
|
||||
_ = x[responseSuccess-1]
|
||||
_ = x[responseFoundGoal-2]
|
||||
}
|
||||
|
||||
const _responseType_name = "responseWallresponseSuccessresponseFoundGoal"
|
||||
|
||||
var _responseType_index = [...]uint8{0, 12, 27, 44}
|
||||
|
||||
func (i responseType) String() string {
|
||||
if i < 0 || i >= responseType(len(_responseType_index)-1) {
|
||||
return "responseType(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _responseType_name[_responseType_index[i]:_responseType_index[i+1]]
|
||||
}
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[dirNorth-1]
|
||||
_ = x[dirSouth-2]
|
||||
_ = x[dirWest-3]
|
||||
_ = x[dirEast-4]
|
||||
}
|
||||
|
||||
const _dirType_name = "dirNorthdirSouthdirWestdirEast"
|
||||
|
||||
var _dirType_index = [...]uint8{0, 8, 16, 23, 30}
|
||||
|
||||
func (i dirType) String() string {
|
||||
i -= 1
|
||||
if i < 0 || i >= dirType(len(_dirType_index)-1) {
|
||||
return "dirType(" + strconv.FormatInt(int64(i+1), 10) + ")"
|
||||
}
|
||||
return _dirType_name[_dirType_index[i]:_dirType_index[i+1]]
|
||||
}
|
@ -1,16 +1,14 @@
|
||||
package days
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
u "parnic.com/aoc2019/utilities"
|
||||
"parnic.com/aoc2019/utilities"
|
||||
)
|
||||
|
||||
type DayTemplate struct {
|
||||
}
|
||||
|
||||
func (d *DayTemplate) Parse() {
|
||||
u.GetIntLines("Templatep")
|
||||
utilities.GetIntLines("Templatep")
|
||||
}
|
||||
|
||||
func (d DayTemplate) Num() int {
|
||||
@ -18,9 +16,9 @@ func (d DayTemplate) Num() int {
|
||||
}
|
||||
|
||||
func (d *DayTemplate) Part1() string {
|
||||
return fmt.Sprintf("%s%d%s", u.TextBold, 0, u.TextReset)
|
||||
return ""
|
||||
}
|
||||
|
||||
func (d *DayTemplate) Part2() string {
|
||||
return fmt.Sprintf("%s%d%s", u.TextBold, 0, u.TextReset)
|
||||
return ""
|
||||
}
|
||||
|
116
inputs/14p.txt
116
inputs/14p.txt
@ -1,56 +1,60 @@
|
||||
6 WBVJ, 16 CDVNK => 2 PJBZT
|
||||
135 ORE => 8 MWDXJ
|
||||
27 NBRHT, 2 NSWK, 2 CMHMQ, 29 NFCB, 11 KNGJ, 12 MGCKC, 56 NHTKL, 7 WNFSV => 1 FUEL
|
||||
1 SFJFX, 3 MXNK => 4 NLSBZ
|
||||
2 PFKRW, 1 VXFRX, 22 QDJCL => 6 GBDG
|
||||
7 TSTF, 4 ZLJN => 7 DMWS
|
||||
5 KPCF, 1 DLMDJ, 1 FNWGH => 6 TSTF
|
||||
8 DTWKS, 1 GBDG => 4 CGZQ
|
||||
26 CNWZM, 4 KPCF => 3 DTWKS
|
||||
1 JVLHM, 7 DTWKS, 7 PJBZT => 8 MRPHV
|
||||
2 MWDXJ => 3 VHFPC
|
||||
1 WXNW, 6 PFKRW => 7 ZVGVP
|
||||
2 ZVGVP => 1 CMHMQ
|
||||
8 JVLHM, 11 XRKN, 1 HCGKZ => 8 CHZLX
|
||||
20 TSTF => 4 XDZMZ
|
||||
3 CMHMQ, 7 ZVGVP, 10 XRKN => 9 FNWGH
|
||||
12 HCGKZ, 4 NLSBZ, 15 RWRDP, 4 MRPHV, 31 KRDV, 6 PMXK, 2 NFVZ => 7 KNGJ
|
||||
1 TXZCM => 9 BMPJ
|
||||
2 ZFXQ => 3 NBRHT
|
||||
13 JVLHM, 1 VHFPC => 3 PBJPZ
|
||||
7 HCGKZ => 7 PMXK
|
||||
2 RWRDP, 3 VSTQ, 12 PMXK => 7 MXNK
|
||||
1 PJBZT, 3 QRSK => 1 KRDV
|
||||
1 MGCKC, 6 CMHMQ => 6 PQTVS
|
||||
1 TNHCS, 24 ZLJN => 4 RWRDP
|
||||
5 MWDXJ, 1 WXNW => 9 QBCLF
|
||||
1 ZFXQ, 1 DLMDJ => 4 DJXRM
|
||||
1 ZFXQ => 2 CNWZM
|
||||
1 KPCF => 6 ZXDVF
|
||||
2 MRPHV => 1 GSTG
|
||||
5 BMPJ, 2 ZLJN => 8 XQJZ
|
||||
1 MWDXJ, 1 ZVGVP => 3 CDVNK
|
||||
3 NFCB, 3 CMHMQ, 1 MWDXJ => 4 XRKN
|
||||
1 WXNW, 1 TXZCM => 5 ZLJN
|
||||
4 ZXDVF => 4 WBVJ
|
||||
2 GBDG => 4 KPCF
|
||||
4 CHZLX, 7 ZFXQ, 14 PQTVS => 9 VSTQ
|
||||
3 TXZCM, 7 ZLJN, 7 ZXDVF => 9 JVLHM
|
||||
1 DMWS, 3 TSTF => 5 HCGKZ
|
||||
2 CGZQ => 4 NFVZ
|
||||
2 PQTVS, 9 VMNJ => 9 TXZCM
|
||||
3 KPCF => 4 DLMDJ
|
||||
7 VMNJ, 24 XQJZ, 7 GSTG, 8 NLSBZ, 10 MGCKC, 2 SFJFX, 18 BMPJ => 1 NSWK
|
||||
41 CNWZM, 5 DJXRM, 1 QRSK, 1 KPCF, 15 XDZMZ, 3 MRPHV, 1 NLSBZ, 9 KRDV => 2 WNFSV
|
||||
10 PBJPZ, 29 BMPJ, 2 PMXK => 7 SFJFX
|
||||
116 ORE => 4 WXNW
|
||||
2 CNWZM => 2 TNHCS
|
||||
10 QBCLF => 7 NFCB
|
||||
1 QBCLF => 2 ZFXQ
|
||||
15 ZLJN => 7 QRSK
|
||||
183 ORE => 3 QDJCL
|
||||
11 GBDG => 5 VMNJ
|
||||
4 DMWS, 3 QRSK => 3 NHTKL
|
||||
124 ORE => 6 VXFRX
|
||||
1 MWDXJ => 6 MGCKC
|
||||
108 ORE => 9 PFKRW
|
||||
11 RVCS => 8 CBMDT
|
||||
29 QXPB, 8 QRGRH => 8 LGMKD
|
||||
3 VPRVD => 6 PMFZG
|
||||
1 CNWNQ, 11 MJVXS => 6 SPLM
|
||||
13 SPDRZ, 13 PMFZG => 2 BLFM
|
||||
8 QWPFN => 7 LWVB
|
||||
1 SPLM => 8 TKWQ
|
||||
2 QRGRH, 6 CNWNQ => 7 DTZW
|
||||
2 DMLT, 1 SPLM, 1 TMDK => 9 NKNS
|
||||
1 MJVXS, 1 HLBV => 7 PQCQH
|
||||
1 JZHZP, 9 LWVB => 7 MJSCQ
|
||||
29 DGFR => 7 QRGRH
|
||||
14 XFLKQ, 2 NKNS, 4 KMNJF, 3 MLZGQ, 7 TKWQ, 24 WTDW, 11 CBMDT => 4 GJKX
|
||||
4 TKWQ, 1 WLCFR => 4 PDKGT
|
||||
2 NKNS => 4 GDKL
|
||||
4 WRZST => 9 XFLKQ
|
||||
19 DGFR => 4 VPRVD
|
||||
10 MJSCQ, 4 QWPFN, 4 QXPB => 2 MLZGQ
|
||||
1 JZHZP => 7 QWPFN
|
||||
1 XFLKQ => 9 FQGVL
|
||||
3 GQGXC => 9 VHGP
|
||||
3 NQZTV, 1 JZHZP => 2 NVZWL
|
||||
38 WLCFR, 15 GJKX, 44 LGMKD, 2 CBVXG, 2 GDKL, 77 FQGVL, 10 MKRCZ, 29 WJQD, 33 BWXGC, 19 PQCQH, 24 BKXD => 1 FUEL
|
||||
102 ORE => 5 DGFR
|
||||
17 NWKLB, 1 SBPLK => 5 HRQM
|
||||
3 BWXGC => 8 TQDP
|
||||
1 TQDP => 2 PSZDZ
|
||||
2 MJVXS => 9 WNXG
|
||||
2 NBTW, 1 HRQM => 2 SVHBH
|
||||
8 CNWNQ, 1 DTZW => 4 RVCS
|
||||
4 VHGP, 20 WNXG, 2 SVHBH => 3 SPDRZ
|
||||
110 ORE => 5 TXMC
|
||||
10 QRGRH => 5 NWKLB
|
||||
1 SBPLK => 3 MJVXS
|
||||
9 DGFR => 5 RFSRL
|
||||
5 LBTV => 3 DMLT
|
||||
1 NWKLB, 1 KMNJF, 1 HDQXB, 6 LBTV, 2 PSZDZ, 34 PMFZG, 2 SVHBH => 2 WJQD
|
||||
1 RVCS => 5 MKRCZ
|
||||
14 NQZTV, 3 FPLT, 1 SJMS => 2 GQGXC
|
||||
18 RFSRL, 13 VHGP, 23 NBTW => 5 WTDW
|
||||
1 VHGP, 6 TKWQ => 7 QXPB
|
||||
1 JZHZP, 1 CNWNQ => 5 KMNJF
|
||||
109 ORE => 9 BWXGC
|
||||
2 CNWNQ, 1 PDKGT, 2 KMNJF => 5 HDQXB
|
||||
1 PDKGT, 18 WRZST, 9 MJSCQ, 3 VHGP, 1 BLFM, 1 LGMKD, 7 WLCFR => 2 BKXD
|
||||
11 MLJK => 6 FPLT
|
||||
8 DGFR, 2 TXMC, 3 WJRC => 9 SJMS
|
||||
2 SBPLK => 1 LBTV
|
||||
22 QWPFN => 4 WRZST
|
||||
5 WRZST, 22 WNXG, 1 VHGP => 7 NBTW
|
||||
7 RVCS => 9 TMDK
|
||||
1 DGFR, 14 TXMC => 5 JZHZP
|
||||
2 JZHZP => 3 SBPLK
|
||||
19 PDKGT => 8 HLBV
|
||||
195 ORE => 6 WJRC
|
||||
6 GQGXC => 8 CNWNQ
|
||||
1 NVZWL, 4 GQGXC => 2 CBVXG
|
||||
1 NVZWL, 1 KMNJF => 8 WLCFR
|
||||
153 ORE => 4 MLJK
|
||||
1 BWXGC => 6 NQZTV
|
@ -1 +0,0 @@
|
||||
3,1033,1008,1033,1,1032,1005,1032,31,1008,1033,2,1032,1005,1032,58,1008,1033,3,1032,1005,1032,81,1008,1033,4,1032,1005,1032,104,99,1002,1034,1,1039,1001,1036,0,1041,1001,1035,-1,1040,1008,1038,0,1043,102,-1,1043,1032,1,1037,1032,1042,1105,1,124,102,1,1034,1039,1001,1036,0,1041,1001,1035,1,1040,1008,1038,0,1043,1,1037,1038,1042,1106,0,124,1001,1034,-1,1039,1008,1036,0,1041,1002,1035,1,1040,1002,1038,1,1043,101,0,1037,1042,1106,0,124,1001,1034,1,1039,1008,1036,0,1041,101,0,1035,1040,1002,1038,1,1043,101,0,1037,1042,1006,1039,217,1006,1040,217,1008,1039,40,1032,1005,1032,217,1008,1040,40,1032,1005,1032,217,1008,1039,37,1032,1006,1032,165,1008,1040,9,1032,1006,1032,165,1101,2,0,1044,1105,1,224,2,1041,1043,1032,1006,1032,179,1101,1,0,1044,1106,0,224,1,1041,1043,1032,1006,1032,217,1,1042,1043,1032,1001,1032,-1,1032,1002,1032,39,1032,1,1032,1039,1032,101,-1,1032,1032,101,252,1032,211,1007,0,50,1044,1106,0,224,1102,0,1,1044,1105,1,224,1006,1044,247,1001,1039,0,1034,102,1,1040,1035,102,1,1041,1036,101,0,1043,1038,102,1,1042,1037,4,1044,1106,0,0,37,22,74,27,37,99,30,8,72,31,49,29,51,32,85,21,39,72,2,2,43,94,31,11,76,43,95,21,38,8,90,13,39,97,54,47,14,6,20,49,5,30,97,9,99,64,71,24,36,87,52,94,36,18,52,42,83,38,98,53,26,87,69,32,18,94,2,93,97,15,65,65,21,40,99,19,91,13,4,89,38,70,65,41,73,49,62,54,37,46,14,49,88,86,13,89,23,89,10,3,48,57,92,43,65,4,35,97,48,10,19,64,3,79,38,87,6,13,71,49,74,43,92,8,4,71,6,35,85,98,94,6,38,59,80,65,46,62,63,62,49,61,68,6,7,64,66,40,56,82,59,30,85,45,57,36,86,70,25,83,31,96,65,19,16,67,55,36,49,54,29,75,69,3,3,37,75,49,23,65,22,6,52,75,31,7,87,85,19,48,97,65,51,78,10,35,40,59,54,14,85,6,30,94,68,42,87,46,75,26,82,36,21,65,90,16,59,14,76,55,37,41,99,80,9,79,12,59,17,75,2,40,52,45,76,45,16,82,13,55,61,14,11,49,97,81,99,38,35,20,98,51,64,13,24,85,94,38,25,87,1,42,89,18,32,54,55,17,15,84,98,25,31,21,55,44,57,59,11,78,49,72,87,20,7,33,91,80,75,18,33,37,52,7,26,87,65,36,52,92,6,8,95,89,37,38,57,25,23,71,75,47,20,87,90,37,54,38,77,32,39,67,16,69,62,15,96,47,91,95,18,96,24,45,21,64,9,72,2,54,65,39,36,54,23,71,74,18,26,97,35,44,29,87,54,48,31,55,33,85,74,13,99,82,39,35,97,43,20,62,58,86,98,41,47,92,79,74,10,85,28,66,86,18,35,5,84,67,13,91,47,44,1,84,56,32,96,7,77,21,88,92,38,31,65,82,87,45,55,4,60,58,64,49,53,3,63,32,52,43,10,66,75,96,53,11,95,44,36,16,65,91,47,32,9,3,73,29,25,93,29,18,88,45,41,46,12,94,13,89,5,36,94,88,33,10,10,2,52,90,19,63,26,84,12,76,16,42,75,63,39,32,72,72,84,70,2,63,33,74,43,68,38,84,72,44,89,18,24,78,69,4,80,41,54,75,72,4,16,91,5,48,30,64,38,4,52,38,30,95,99,32,38,52,35,58,71,38,89,86,25,84,88,41,39,32,56,79,12,52,19,80,46,66,38,32,69,67,6,87,88,36,59,51,5,33,46,45,82,15,57,80,91,12,86,29,34,15,61,19,73,46,82,60,73,13,52,36,67,3,49,87,39,12,98,58,87,32,82,47,65,6,87,71,13,17,65,69,14,34,42,82,42,1,77,63,10,63,28,90,24,13,99,19,38,68,62,44,2,65,81,95,7,54,24,58,16,58,48,95,9,80,9,51,73,23,96,49,64,58,1,6,72,69,39,2,10,63,36,9,85,59,90,41,2,72,77,23,23,80,75,33,6,20,18,59,39,36,89,35,89,42,42,22,37,24,30,51,53,43,78,48,27,76,84,22,81,72,25,95,28,15,51,58,48,7,1,90,72,19,37,52,60,39,81,20,70,6,39,82,26,77,14,96,52,30,84,33,66,80,5,52,15,72,46,55,2,21,8,97,79,43,8,91,27,67,5,18,74,71,34,51,6,83,25,52,92,5,15,85,11,72,33,85,30,59,6,84,29,51,77,99,43,95,44,83,95,89,27,54,16,85,90,82,34,98,59,87,12,73,25,74,29,95,82,51,5,81,46,51,0,0,21,21,1,10,1,0,0,0,0,0,0
|
1
main.go
1
main.go
@ -45,7 +45,6 @@ var dayMap = []day{
|
||||
&days.Day12{},
|
||||
&days.Day13{},
|
||||
&days.Day14{},
|
||||
&days.Day15{},
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -24,10 +24,9 @@ const (
|
||||
)
|
||||
|
||||
type IntcodeProgram struct {
|
||||
memory []int64
|
||||
program []int64
|
||||
relativeBase int
|
||||
haltRequested bool
|
||||
memory []int64
|
||||
program []int64
|
||||
relativeBase int
|
||||
}
|
||||
|
||||
type IntcodeProgramState struct {
|
||||
@ -142,7 +141,7 @@ func (p *IntcodeProgram) RunIn(inputFunc ProvideInputFunc, outputFunc ReceiveOut
|
||||
p.init()
|
||||
|
||||
inputsRequested := 0
|
||||
for instructionPointer := 0; instructionPointer < len(p.program) && !p.haltRequested; {
|
||||
for instructionPointer := 0; instructionPointer < len(p.program); {
|
||||
instruction := p.GetMemory(instructionPointer)
|
||||
instructionPointer++
|
||||
|
||||
@ -248,10 +247,4 @@ func (p *IntcodeProgram) RunIn(inputFunc ProvideInputFunc, outputFunc ReceiveOut
|
||||
panic(fmt.Sprintf("exception executing program - unhandled opcode %d", opcode))
|
||||
}
|
||||
}
|
||||
|
||||
p.haltRequested = false
|
||||
}
|
||||
|
||||
func (p *IntcodeProgram) Stop() {
|
||||
p.haltRequested = true
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package utilities
|
||||
|
||||
import "math"
|
||||
|
||||
func GCD[T Integer](a, b T) T {
|
||||
if b == 0 {
|
||||
return a
|
||||
@ -27,23 +25,3 @@ func LCM[T Integer](nums ...T) uint64 {
|
||||
func lcm[T Integer](a, b T) uint64 {
|
||||
return uint64(a*b) / uint64(GCD(a, b))
|
||||
}
|
||||
|
||||
func Min[T Number](nums ...T) T {
|
||||
numNums := len(nums)
|
||||
if numNums == 2 {
|
||||
return T(math.Min(float64(nums[0]), float64(nums[1])))
|
||||
}
|
||||
|
||||
if numNums == 0 {
|
||||
return 0
|
||||
}
|
||||
|
||||
least := nums[0]
|
||||
for i := 1; i < numNums; i++ {
|
||||
if nums[i] < least {
|
||||
least = nums[i]
|
||||
}
|
||||
}
|
||||
|
||||
return least
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ type Permutable interface {
|
||||
~int | ~int8 | ~int16 | ~int32 | ~int64 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64
|
||||
}
|
||||
|
||||
func GetPermutations[T Permutable](arr ...T) [][]T {
|
||||
func GetPermutations[T Permutable](arr []T) [][]T {
|
||||
var helper func([]T, int)
|
||||
res := [][]T{}
|
||||
|
||||
|
Reference in New Issue
Block a user