!changed mathutil package to mathy, removed int/string casting from mathy

This commit is contained in:
alexchao26
2020-12-27 17:21:33 -05:00
parent 57fff6d829
commit 666518f507
114 changed files with 780 additions and 287 deletions
+3 -3
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -35,7 +35,7 @@ func part1(input string) int {
totalSqFt += x * y * 2
totalSqFt += x * z * 2
totalSqFt += z * y * 2
totalSqFt += mathutil.MinInt(x*y, y*z, x*z) // slack in wrapping paper...
totalSqFt += mathy.MinInt(x*y, y*z, x*z) // slack in wrapping paper...
}
return totalSqFt
@@ -56,7 +56,7 @@ func part2(input string) int {
2 * (y + z),
2 * (x + z),
}
totalLen += mathutil.MinInt(sides...)
totalLen += mathy.MinInt(sides...)
}
return totalLen
}
-1
View File
@@ -8,7 +8,6 @@ import (
"strings"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
+5 -6
View File
@@ -5,9 +5,8 @@ import (
"math"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -23,8 +22,8 @@ func travelingSalesman(input string) (int, int) {
max := 0
for k := range graph {
dfsMin, dfsMax := dfsTotalDistance(graph, k, map[string]bool{k: true})
min = mathutil.MinInt(min, dfsMin)
max = mathutil.MaxInt(max, dfsMax)
min = mathy.MinInt(min, dfsMin)
max = mathy.MaxInt(max, dfsMax)
}
return min, max
@@ -45,8 +44,8 @@ func dfsTotalDistance(graph mapGraph, entry string, visited map[string]bool) (mi
weight := graph[entry][k]
minRecurse, maxRecurse := dfsTotalDistance(graph, k, visited)
minDistance = mathutil.MinInt(minDistance, weight+minRecurse)
maxDistance = mathutil.MaxInt(maxDistance, weight+maxRecurse)
minDistance = mathy.MinInt(minDistance, weight+minRecurse)
maxDistance = mathy.MaxInt(maxDistance, weight+maxRecurse)
// backtrack
// delete to so length of visited is accurate
-1
View File
@@ -7,7 +7,6 @@ import (
"strings"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
-1
View File
@@ -8,7 +8,6 @@ import (
"strings"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
+2 -2
View File
@@ -7,7 +7,7 @@ import (
"strings"
"github.com/alexchao26/advent-of-code-go/algos"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -40,7 +40,7 @@ func knightsOfTheDinnerTable(input string, part int) int {
maxDiff := math.MinInt32
for _, p := range perms {
maxDiff = mathutil.MaxInt(maxDiff, calcHappinessDiff(graph, p))
maxDiff = mathy.MaxInt(maxDiff, calcHappinessDiff(graph, p))
}
return maxDiff
+3 -4
View File
@@ -5,8 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -56,7 +55,7 @@ func reindeerOlympics(input string, part int) int {
if part == 1 {
var furthest int
for _, distSli := range reindeerToDistanceMap {
furthest = mathutil.MaxInt(distSli[2503], furthest)
furthest = mathy.MaxInt(distSli[2503], furthest)
}
return furthest
}
@@ -82,7 +81,7 @@ func reindeerOlympics(input string, part int) int {
var bestScore int
for _, v := range reindeerScores {
bestScore = mathutil.MaxInt(bestScore, v)
bestScore = mathy.MaxInt(bestScore, v)
}
return bestScore
+7 -7
View File
@@ -4,7 +4,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -46,17 +46,17 @@ func cookieScience(input string) (int, int) {
// make negatives zero, without this two negative scores could
// make a very large positive
cap = mathutil.MaxInt(0, cap)
dur = mathutil.MaxInt(0, dur)
fla = mathutil.MaxInt(0, fla)
tex = mathutil.MaxInt(0, tex)
cap = mathy.MaxInt(0, cap)
dur = mathy.MaxInt(0, dur)
fla = mathy.MaxInt(0, fla)
tex = mathy.MaxInt(0, tex)
score := cap * dur * fla * tex
if cal == 500 {
best500CalScore = mathutil.MaxInt(best500CalScore, score)
best500CalScore = mathy.MaxInt(best500CalScore, score)
}
bestScore = mathutil.MaxInt(bestScore, score)
bestScore = mathy.MaxInt(bestScore, score)
}
}
}
+2 -2
View File
@@ -7,7 +7,7 @@ import (
"strings"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -36,7 +36,7 @@ func eggnogCombinations(input string, target int, part int) int {
// part 2, get the number of combinations w/ the lowest length
minLen := math.MaxInt32
for _, comb := range allIndexCombinations {
minLen = mathutil.MinInt(minLen, len(comb))
minLen = mathy.MinInt(minLen, len(comb))
}
var count int
-1
View File
@@ -6,7 +6,6 @@ import (
"math"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
+145
View File
@@ -0,0 +1,145 @@
package main
import (
"fmt"
"math"
"strings"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
ans1, ans2 := rpgSimulator(util.ReadFile("./input.txt"))
fmt.Printf("Part1: %d\nPart2: %d\n", ans1, ans2)
}
func rpgSimulator(input string) (rpgSimulator, part2 int) {
bossHP, bossDamage, bossArmor, shopWeapons, shopArmor, shopRings := parseInput(input)
// all attacks do at least 1 damage
// damage equal to attack - defenders armor
// armor is optional, limit 1
// 0-2 rings allowed
// player attacks first
// must buy exactly 1 weapon
var combinations [][]item
for weapon := 0; weapon < len(shopWeapons); weapon++ {
for armor := -1; armor < len(shopArmor); armor++ {
for ring1 := -1; ring1 < len(shopRings); ring1++ {
for ring2 := -1; ring2 < len(shopRings); ring2++ {
comb := []item{shopWeapons[weapon]}
if armor != -1 {
comb = append(comb, shopArmor[armor])
}
if ring1 != -1 {
comb = append(comb, shopRings[ring1])
}
if ring2 != -1 && ring2 != ring1 {
comb = append(comb, shopRings[ring2])
}
combinations = append(combinations, comb)
}
}
}
}
minCost := math.MaxInt32
var maxCost int
for _, comb := range combinations {
myHP := 100
var myDamage, myArmor, cost int
for _, it := range comb {
myDamage += it.damage
myArmor += it.armor
cost += it.cost
}
playerWins := simulateBattle(bossHP, bossDamage, bossArmor, myHP, myDamage, myArmor)
if playerWins {
// part 1, min cost to win
minCost = mathy.MinInt(minCost, cost)
} else {
// part 2, max cost to still lose
maxCost = mathy.MaxInt(maxCost, cost)
}
}
return minCost, maxCost
}
func simulateBattle(bossHP, bossDamage, bossArmor, myHP, myDamage, myArmor int) (playerWins bool) {
attackOnBoss := myDamage - bossArmor
attackOnPlayer := bossDamage - myArmor
attackOnBoss = mathy.MaxInt(attackOnBoss, 1)
attackOnPlayer = mathy.MaxInt(attackOnPlayer, 1)
for bossHP > 0 && myHP > 0 {
bossHP -= attackOnBoss
myHP -= attackOnPlayer
}
// the boss takes damage first, so if it hit zero or less, then the player
// won the round (potentially with very little HP left)
return bossHP <= 0
}
type item struct {
name string
cost, damage, armor int
}
var shop = `Weapons: Cost Damage Armor
Dagger 8 4 0
Shortsword 10 5 0
Warhammer 25 6 0
Longsword 40 7 0
Greataxe 74 8 0
Armor: Cost Damage Armor
Leather 13 0 1
Chainmail 31 0 2
Splintmail 53 0 3
Bandedmail 75 0 4
Platemail 102 0 5
Rings: Cost Damage Armor
Damage +1 25 1 0
Damage +2 50 2 0
Damage +3 100 3 0
Defense +1 20 0 1
Defense +2 40 0 2
Defense +3 80 0 3`
func parseInput(input string) (hp, damage, armor int, shopWeapons, shopArmor, shopRings []item) {
lines := strings.Split(input, "\n")
hp = cast.ToInt(strings.Split(lines[0], ": ")[1])
damage = cast.ToInt(strings.Split(lines[1], ": ")[1])
armor = cast.ToInt(strings.Split(lines[2], ": ")[1])
shopBlocks := strings.Split(shop, "\n\n")
for blockIndex := range shopBlocks {
for _, line := range strings.Split(shopBlocks[blockIndex], "\n")[1:] {
it := item{}
if blockIndex == 2 {
// gross, have to get rid of whitespace in name for the rings
line = strings.ReplaceAll(line, "e +", "e+")
}
_, err := fmt.Sscanf(line, "%s %d %d %d", &it.name, &it.cost, &it.damage, &it.armor)
if err != nil {
panic(err)
}
switch blockIndex {
case 0:
shopWeapons = append(shopWeapons, it)
case 1:
shopArmor = append(shopArmor, it)
case 2:
shopRings = append(shopRings, it)
}
}
}
return hp, damage, armor, shopWeapons, shopArmor, shopRings
}
+29
View File
@@ -0,0 +1,29 @@
package main
import (
"testing"
"github.com/alexchao26/advent-of-code-go/util"
)
func Test_rpgSimulator(t *testing.T) {
tests := []struct {
name string
input string
want1 int
want2 int
}{
{"actual", util.ReadFile("input.txt"), 121, 201},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got1, got2 := rpgSimulator(tt.input)
if got1 != tt.want1 {
t.Errorf("rpgSimulator() = %v, want1 %v", got1, tt.want1)
}
if got2 != tt.want2 {
t.Errorf("rpgSimulator() = %v, want2 %v", got2, tt.want2)
}
})
}
}
+46
View File
@@ -0,0 +1,46 @@
package main
import (
"flag"
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
var part int
flag.IntVar(&part, "part", 1, "part 1 or 2")
flag.Parse()
fmt.Println("Running part", part)
if part == 1 {
ans := part1(util.ReadFile("./input.txt"))
util.CopyToClipboard(fmt.Sprintf("%v", ans))
fmt.Println("Output:", ans)
} else {
ans := part2(util.ReadFile("./input.txt"))
util.CopyToClipboard(fmt.Sprintf("%v", ans))
fmt.Println("Output:", ans)
}
}
func part1(input string) int {
parsed := parseInput(input)
_ = parsed
return 0
}
func part2(input string) int {
return 0
}
func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, cast.ToInt(l))
}
return ans
}
+39
View File
@@ -0,0 +1,39 @@
package main
import (
"testing"
)
func Test_part1(t *testing.T) {
tests := []struct {
name string
input string
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part1(tt.input); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
}
})
}
}
func Test_part2(t *testing.T) {
tests := []struct {
name string
input string
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
}
})
}
}
+46
View File
@@ -0,0 +1,46 @@
package main
import (
"flag"
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
var part int
flag.IntVar(&part, "part", 1, "part 1 or 2")
flag.Parse()
fmt.Println("Running part", part)
if part == 1 {
ans := part1(util.ReadFile("./input.txt"))
util.CopyToClipboard(fmt.Sprintf("%v", ans))
fmt.Println("Output:", ans)
} else {
ans := part2(util.ReadFile("./input.txt"))
util.CopyToClipboard(fmt.Sprintf("%v", ans))
fmt.Println("Output:", ans)
}
}
func part1(input string) int {
parsed := parseInput(input)
_ = parsed
return 0
}
func part2(input string) int {
return 0
}
func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, cast.ToInt(l))
}
return ans
}
+39
View File
@@ -0,0 +1,39 @@
package main
import (
"testing"
)
func Test_part1(t *testing.T) {
tests := []struct {
name string
input string
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part1(tt.input); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
}
})
}
}
func Test_part2(t *testing.T) {
tests := []struct {
name string
input string
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
}
})
}
}
+46
View File
@@ -0,0 +1,46 @@
package main
import (
"flag"
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
var part int
flag.IntVar(&part, "part", 1, "part 1 or 2")
flag.Parse()
fmt.Println("Running part", part)
if part == 1 {
ans := part1(util.ReadFile("./input.txt"))
util.CopyToClipboard(fmt.Sprintf("%v", ans))
fmt.Println("Output:", ans)
} else {
ans := part2(util.ReadFile("./input.txt"))
util.CopyToClipboard(fmt.Sprintf("%v", ans))
fmt.Println("Output:", ans)
}
}
func part1(input string) int {
parsed := parseInput(input)
_ = parsed
return 0
}
func part2(input string) int {
return 0
}
func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, cast.ToInt(l))
}
return ans
}
+39
View File
@@ -0,0 +1,39 @@
package main
import (
"testing"
)
func Test_part1(t *testing.T) {
tests := []struct {
name string
input string
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part1(tt.input); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
}
})
}
}
func Test_part2(t *testing.T) {
tests := []struct {
name string
input string
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
}
})
}
}
+46
View File
@@ -0,0 +1,46 @@
package main
import (
"flag"
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
var part int
flag.IntVar(&part, "part", 1, "part 1 or 2")
flag.Parse()
fmt.Println("Running part", part)
if part == 1 {
ans := part1(util.ReadFile("./input.txt"))
util.CopyToClipboard(fmt.Sprintf("%v", ans))
fmt.Println("Output:", ans)
} else {
ans := part2(util.ReadFile("./input.txt"))
util.CopyToClipboard(fmt.Sprintf("%v", ans))
fmt.Println("Output:", ans)
}
}
func part1(input string) int {
parsed := parseInput(input)
_ = parsed
return 0
}
func part2(input string) int {
return 0
}
func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, cast.ToInt(l))
}
return ans
}
+39
View File
@@ -0,0 +1,39 @@
package main
import (
"testing"
)
func Test_part1(t *testing.T) {
tests := []struct {
name string
input string
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part1(tt.input); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
}
})
}
}
func Test_part2(t *testing.T) {
tests := []struct {
name string
input string
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
}
})
}
}
+3 -4
View File
@@ -5,8 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -52,11 +51,11 @@ func taxicab(input string, part int) int {
row += dirs[dirIndex][0]
col += dirs[dirIndex][1]
if visited[[2]int{row, col}] && part == 2 {
return mathutil.ManhattanDistance(0, 0, row, col)
return mathy.ManhattanDistance(0, 0, row, col)
}
visited[[2]int{row, col}] = true
}
}
return mathutil.ManhattanDistance(0, 0, row, col)
return mathy.ManhattanDistance(0, 0, row, col)
}
+4
View File
@@ -1,6 +1,7 @@
package main
import (
"strings"
"testing"
"github.com/alexchao26/advent-of-code-go/util"
@@ -20,6 +21,9 @@ func Test_part1(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if strings.Contains(tt.name, "part2") && testing.Short() {
t.Skip("Skipping long test, 2016/day14, a lot of MD5 hashes")
}
if got := oneTimePad(tt.input, tt.part); got != tt.want {
t.Errorf("part1() = %v, want %v", got, tt.want)
}
+2 -2
View File
@@ -7,7 +7,7 @@ import (
"sort"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -40,7 +40,7 @@ func firewall(input string, part int) int {
for _, r := range allBlockedRanges {
endOfLastRange := merged[len(merged)-1][1]
if endOfLastRange >= r[0]-1 {
merged[len(merged)-1][1] = mathutil.MaxInt(endOfLastRange, r[1])
merged[len(merged)-1][1] = mathy.MaxInt(endOfLastRange, r[1])
} else {
merged = append(merged, r)
}
+3 -3
View File
@@ -6,7 +6,7 @@ import (
"regexp"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -54,8 +54,8 @@ func part2(input string) int {
var maxX, maxY int
var x, y int
for c, n := range nodes {
maxX = mathutil.MaxInt(c[0], maxX)
maxY = mathutil.MaxInt(c[1], maxY)
maxX = mathy.MaxInt(c[0], maxX)
maxY = mathy.MaxInt(c[1], maxY)
// getting the starting node, i.e. has zero used space
if n.used == 0 {
x = n.coord[1]
+2 -2
View File
@@ -8,7 +8,7 @@ import (
"strings"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -127,7 +127,7 @@ func dfs(graph [][]int, entryIndex int, visited map[int]bool, returnToZero bool)
visited[i] = true
dist := val + dfs(graph, i, visited, returnToZero)
minDistance = mathutil.MinInt(minDistance, dist)
minDistance = mathy.MinInt(minDistance, dist)
delete(visited, i)
}
-17
View File
@@ -20,20 +20,3 @@ func Test_part1(t *testing.T) {
})
}
}
func Test_part2(t *testing.T) {
tests := []struct {
name string
input string
want int
}{
// {"actual", util.ReadFile("input.txt"), ACTUAL_ANSWER},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := part2(tt.input); got != tt.want {
t.Errorf("part2() = %v, want %v", got, tt.want)
}
})
}
}
+2 -2
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -49,7 +49,7 @@ func part2(input string) int {
func parseInput(input string) (ans []int) {
for _, num := range strings.Split(input, "") {
ans = append(ans, mathutil.StrToInt(num))
ans = append(ans, cast.ToInt(num))
}
return ans
}
+4 -3
View File
@@ -5,7 +5,8 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -28,7 +29,7 @@ func part1(input string) int {
rows := parseInput(input)
var checksum int
for _, r := range rows {
checksum += mathutil.MaxInt(r...) - mathutil.MinInt(r...)
checksum += mathy.MaxInt(r...) - mathy.MinInt(r...)
}
return checksum
}
@@ -58,7 +59,7 @@ func parseInput(input string) (ans [][]int) {
ans = append(ans, []int{})
// split by tabs
for _, num := range strings.Split(l, "\t") {
ans[i] = append(ans[i], mathutil.StrToInt(num))
ans[i] = append(ans[i], cast.ToInt(num))
}
}
return ans
+5 -4
View File
@@ -4,7 +4,8 @@ import (
"flag"
"fmt"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -24,7 +25,7 @@ func main() {
}
func part1(input string) int {
inputNum := mathutil.StrToInt(input)
inputNum := cast.ToInt(input)
directions := [][2]int{
{0, 1}, // right
@@ -60,11 +61,11 @@ func part1(input string) int {
number++ // increment number
}
return mathutil.ManhattanDistance(0, 0, row, col)
return mathy.ManhattanDistance(0, 0, row, col)
}
func part2(input string) int {
inputNum := mathutil.StrToInt(input)
inputNum := cast.ToInt(input)
directions := [][2]int{
{0, 1}, // right
+2 -2
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -58,7 +58,7 @@ func part2(input string) int {
func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, mathutil.StrToInt(l))
ans = append(ans, cast.ToInt(l))
}
return ans
}
+2 -2
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -71,7 +71,7 @@ func memoryReallocation(input string, part int) int {
func parseInput(input string) (ans [16]int) {
nums := strings.Split(input, "\t")
for i, num := range nums {
ans[i] = mathutil.StrToInt(num)
ans[i] = cast.ToInt(num)
}
return ans
}
+3 -3
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -41,7 +41,7 @@ func part1(input string) string {
}
if len(allNames) != 1 {
panic("Expected one name left, got" + mathutil.IntToStr(len(allNames)))
panic("Expected one name left, got" + cast.ToString(len(allNames)))
}
// have to iterate over graph to get remaining name
@@ -138,7 +138,7 @@ func parseInput(input string) map[string]graphNode {
leftParts := strings.Split(parts[0], " ")
name := leftParts[0]
weight := mathutil.StrToInt(leftParts[1][1 : len(leftParts[1])-1])
weight := cast.ToInt(leftParts[1][1 : len(leftParts[1])-1])
var edges []string
if len(parts) == 2 {
+6 -6
View File
@@ -6,8 +6,8 @@ import (
"math"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -29,7 +29,7 @@ func calcRegisters(input string, part int) int {
var highestEverRegister int // for part 2
for _, inst := range instructions {
registerVal := registers[inst.conditional[0]]
compareVal := mathutil.StrToInt(inst.conditional[2])
compareVal := cast.ToInt(inst.conditional[2])
var conditionalResult bool
switch inst.conditional[1] {
case "==":
@@ -50,12 +50,12 @@ func calcRegisters(input string, part int) int {
if conditionalResult {
registers[inst.registerName] += inst.diff
}
highestEverRegister = mathutil.MaxInt(highestEverRegister, registers[inst.registerName])
highestEverRegister = mathy.MaxInt(highestEverRegister, registers[inst.registerName])
}
largestFinalRegister := -math.MaxInt32
for _, v := range registers {
largestFinalRegister = mathutil.MaxInt(largestFinalRegister, v)
largestFinalRegister = mathy.MaxInt(largestFinalRegister, v)
}
if part == 1 {
@@ -82,7 +82,7 @@ func parseInput(input string) []instruction {
}
inst := instruction{
registerName: parts[0],
diff: mathutil.StrToInt(parts[2]),
diff: cast.ToInt(parts[2]),
conditional: [3]string{parts[4], parts[5], parts[6]},
}
if parts[1] == "dec" {
+2 -2
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -101,7 +101,7 @@ func reverse(nums []int, left, right int) []int {
func parseInput(input string) (ans []int) {
nums := strings.Split(input, ",")
for _, num := range nums {
ans = append(ans, mathutil.StrToInt(num))
ans = append(ans, cast.ToInt(num))
}
return ans
}
+5 -6
View File
@@ -5,8 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -36,7 +35,7 @@ func hexEd(input string, part int) int {
for _, step := range steps {
tallyDirections[dirIndices[step]]++
distanceFromStart := getDistanceFromOrigin(tallyDirections)
furthest = mathutil.MaxInt(furthest, distanceFromStart)
furthest = mathy.MaxInt(furthest, distanceFromStart)
}
if part == 1 {
@@ -51,7 +50,7 @@ func getDistanceFromOrigin(tally []int) int {
for i := range tally {
if tally[i] != 0 {
oppositeIndex := (i + 3) % 6
smaller := mathutil.MinInt(tally[oppositeIndex], tally[i])
smaller := mathy.MinInt(tally[oppositeIndex], tally[i])
tally[oppositeIndex] -= smaller
tally[i] -= smaller
}
@@ -63,14 +62,14 @@ func getDistanceFromOrigin(tally []int) int {
toLeft := (i + 5) % 6
toRight := (i + 1) % 6
if tally[toLeft] > 0 && tally[toRight] > 0 {
smaller := mathutil.MinInt(tally[toLeft], tally[toRight])
smaller := mathy.MinInt(tally[toLeft], tally[toRight])
tally[toLeft] -= smaller
tally[toRight] -= smaller
tally[i] += smaller
}
}
distanceFromOrigin := mathutil.SumIntSlice(tally)
distanceFromOrigin := mathy.SumIntSlice(tally)
return distanceFromOrigin
}
+3 -3
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -89,9 +89,9 @@ func makeGraphFromInput(input string) map[int][]int {
graph := make(map[int][]int, len(lines))
for _, l := range lines {
parts := strings.Split(l, " <-> ")
ID := mathutil.StrToInt(parts[0])
ID := cast.ToInt(parts[0])
for _, child := range strings.Split(parts[1], ", ") {
graph[ID] = append(graph[ID], mathutil.StrToInt(child))
graph[ID] = append(graph[ID], cast.ToInt(child))
}
}
return graph
+2 -2
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -73,7 +73,7 @@ func parseInput(input string) (ans []int) {
lines := strings.Split(input, "\n")
for _, l := range lines {
split := strings.Split(l, " starts with ")
ans = append(ans, mathutil.StrToInt(split[1]))
ans = append(ans, cast.ToInt(split[1]))
}
return ans
}
+2 -3
View File
@@ -5,8 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -43,7 +42,7 @@ func permPromenade(input string, part int) string {
for _, step := range steps {
switch step[0] {
case 's':
countToSpin := mathutil.StrToInt(step[1:])
countToSpin := cast.ToInt(step[1:])
fromEnd := programs[len(programs)-countToSpin:]
fromFront := programs[:len(programs)-countToSpin]
programs = append(fromEnd, fromFront...)
+3 -2
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"log"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -26,7 +26,7 @@ type llNode struct {
}
func spinlock(input string, part int) int {
steps := mathutil.StrToInt(input)
steps := cast.ToInt(input)
lastNumToAdd := 2017
if part == 2 {
@@ -48,6 +48,7 @@ func spinlock(input string, part int) int {
current = current.next
// progress log for part 2 brute force...
// todo optimize this slow pos
if i%1000000 == 0 {
log.Println(i, "steps done")
}
+7 -1
View File
@@ -1,6 +1,7 @@
package main
import (
"fmt"
"testing"
"github.com/alexchao26/advent-of-code-go/util"
@@ -21,7 +22,12 @@ func Test_spinlock(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
t.Logf("Running %s", tt.name)
if tt.name == "actual_part2" {
t.Log("This one could take a while, it has 50 million steps to run")
// Print using fmt b/c it will be messaged to the terminal regardless
// of verbose flag. To warn (me) that this test takes forever...
fmt.Println("WARNING: REALLY LONG TEST, 50 million steps to run")
if testing.Short() {
t.Skip("Skipping long test in short mode")
}
}
if got := spinlock(tt.input, tt.part); got != tt.want {
t.Errorf("spinlock() = %v, want %v", got, tt.want)
+2 -3
View File
@@ -7,8 +7,7 @@ import (
"sort"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -53,7 +52,7 @@ func part1(input string) int {
}
func sumAbs(nums [3]int) int {
return mathutil.AbsInt(nums[0]) + mathutil.AbsInt(nums[1]) + mathutil.AbsInt(nums[2])
return mathy.AbsInt(nums[0]) + mathy.AbsInt(nums[1]) + mathy.AbsInt(nums[2])
}
func part2(input string) int {
+2 -2
View File
@@ -4,7 +4,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -34,7 +34,7 @@ func part1(input string) int {
currentStateName = rulesToFollow.nextState
}
return mathutil.SumIntSlice(bigArray)
return mathy.SumIntSlice(bigArray)
}
type ruleset struct {
+2 -1
View File
@@ -1,10 +1,11 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,10 +1,11 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,9 +1,10 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,9 +1,10 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
// brute force it...
+2 -1
View File
@@ -1,10 +1,11 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,10 +1,11 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,11 +1,12 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"sort"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,11 +1,12 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"sort"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+6 -5
View File
@@ -6,7 +6,8 @@ import (
"math"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -39,7 +40,7 @@ func part1(input string) int {
var coordsToBest [2]int
distCounts := map[int]int{} // dedeupe equidistant cells
for _, coord := range coords {
man := mathutil.ManhattanDistance(r, c, coord[0], coord[1])
man := mathy.ManhattanDistance(r, c, coord[0], coord[1])
if man <= bestManhattan {
bestManhattan = man
coordsToBest = coord
@@ -82,7 +83,7 @@ func part2(input string, dist int) int {
for c := boundLeft; c <= boundRight; c++ {
point := [2]int{r, c}
for _, coord := range coords {
coordsToTotalDist[point] += mathutil.ManhattanDistance(point[0], point[1], coord[0], coord[1])
coordsToTotalDist[point] += mathy.ManhattanDistance(point[0], point[1], coord[0], coord[1])
}
if coordsToTotalDist[point] < dist {
area++
@@ -100,8 +101,8 @@ func parseInputCoords(input string) [][2]int {
c := strings.Split(l, ", ")
if len(c) == 2 {
coords = append(coords, [2]int{
mathutil.StrToInt(c[0]),
mathutil.StrToInt(c[1]),
cast.ToInt(c[0]),
cast.ToInt(c[1]),
})
}
}
+2 -2
View File
@@ -7,7 +7,7 @@ import (
"sort"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -101,7 +101,7 @@ func part2(input string, workers, fudgeTime int) int {
if len(prereqsCompletionTimes) == 0 {
readySteps = append(readySteps, name)
} else {
earliestScheduleTime := mathutil.MaxInt(prereqsCompletionTimes...)
earliestScheduleTime := mathy.MaxInt(prereqsCompletionTimes...)
if earliestScheduleTime <= time {
readySteps = append(readySteps, name)
}
+2 -2
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -51,7 +51,7 @@ func parseInput(input string) []int {
parsed := make([]int, len(split))
for i, v := range split {
parsed[i] = mathutil.StrToInt(v)
parsed[i] = cast.ToInt(v)
}
return parsed
+5 -4
View File
@@ -6,7 +6,8 @@ import (
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -54,13 +55,13 @@ func part1(input string) int {
playerTurn %= players
}
return mathutil.MaxInt(playerScores...)
return mathy.MaxInt(playerScores...)
}
func part2(input string) int {
// lazily modify input...
split := strings.Split(input, " ")
steps := mathutil.StrToInt(split[6]) * 100
steps := cast.ToInt(split[6]) * 100
split[6] = strconv.Itoa(steps)
return part1(strings.Join(split, " "))
@@ -68,7 +69,7 @@ func part2(input string) int {
func parseInput(input string) (players int, lastPoints int) {
split := strings.Split(input, " ")
return mathutil.StrToInt(split[0]), mathutil.StrToInt(split[6])
return cast.ToInt(split[0]), cast.ToInt(split[6])
}
type CircularLinkedListNode struct {
+3 -3
View File
@@ -7,7 +7,7 @@ import (
"strings"
"time"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -63,8 +63,8 @@ func parseInputs(input string) (positions [][2]int, velocities [][2]int) {
posY := strings.TrimSpace(l[18:24])
velX := strings.TrimSpace(l[36:38])
velY := strings.TrimSpace(l[40:42])
positions = append(positions, [2]int{mathutil.StrToInt(posX), mathutil.StrToInt(posY)})
velocities = append(velocities, [2]int{mathutil.StrToInt(velX), mathutil.StrToInt(velY)})
positions = append(positions, [2]int{cast.ToInt(posX), cast.ToInt(posY)})
velocities = append(velocities, [2]int{cast.ToInt(velX), cast.ToInt(velY)})
}
return positions, velocities
+2 -2
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -89,7 +89,7 @@ func part2(input string) string {
}
func parseInputs(input string) int {
return mathutil.StrToInt(strings.TrimSpace(input))
return cast.ToInt(strings.TrimSpace(input))
}
func generateGrid(gridSN int) [][]int {
+2 -2
View File
@@ -6,7 +6,7 @@ import (
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -66,7 +66,7 @@ func part2(input string) int {
func parseInput(input string) int {
lines := strings.Split(input, "\n")
return mathutil.StrToInt(lines[0])
return cast.ToInt(lines[0])
}
func step(recipes []int, elf1, elf2 int) ([]int, int, int) {
+2 -1
View File
@@ -1,10 +1,11 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,10 +1,11 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,11 +1,12 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"math"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,11 +1,12 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"math"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,11 +1,12 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"log"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,11 +1,12 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"log"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,9 +1,10 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,9 +1,10 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,9 +1,10 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,9 +1,10 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,9 +1,10 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -2
View File
@@ -15,7 +15,7 @@ import (
"strings"
"github.com/alexchao26/advent-of-code-go/algos"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -82,7 +82,7 @@ func Draw(mapCoordsToColor map[string]int) string {
}
// Determine the bounds of the grid
edgeLength := 2 * mathutil.MaxInt(-lowY, -lowX, highY, highX)
edgeLength := 2 * mathy.MaxInt(-lowY, -lowX, highY, highX)
grid := make([][]string, edgeLength)
for i := 0; i < edgeLength; i++ {
+2 -1
View File
@@ -1,10 +1,11 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
// Moon stores coordinates and velocities of a moon
+2 -1
View File
@@ -1,10 +1,11 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
// Moon stores coordinates and velocities of a moon
+2 -1
View File
@@ -9,11 +9,12 @@ Draw function generates a string to display in terminal
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"log"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -10,11 +10,12 @@ NOTE: The "hold for an input" value was changed from -1 to -2 in the Intcode com
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"log"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,10 +1,11 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,10 +1,11 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
// const will be comparable to any int type?
+2 -10
View File
@@ -1,11 +1,3 @@
/*
Intcode struct is defined within this file
Robot struct houses an Intcode computer and its RecursiveMove method populates a map of
coordinates to the floor type (-1: wall, 1: hallway, 2: O2 tank, 5: origin)
That map is converted into a 2D grid (slice)
2D slice is passed to a backtracking & searching algorithm to find the shortest path
*/
package main
import (
@@ -16,7 +8,7 @@ import (
"strings"
"github.com/alexchao26/advent-of-code-go/algos"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -336,7 +328,7 @@ func Draw(mapCoordsToType map[string]int) [][]int {
}
// Determine the bounds of the grid
edgeLength := 2 * mathutil.MaxInt(-lowY, -lowX, highY, highX)
edgeLength := 2 * mathy.MaxInt(-lowY, -lowX, highY, highX)
grid := make([][]int, edgeLength)
for i := 0; i < edgeLength; i++ {
+2 -2
View File
@@ -18,7 +18,7 @@ import (
"strings"
"github.com/alexchao26/advent-of-code-go/algos"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -390,7 +390,7 @@ func Draw(mapCoordsToType map[string]int) [][]int {
}
// Determine the bounds of the grid
edgeLength := 2 * mathutil.MaxInt(-lowY, -lowX, highY, highX)
edgeLength := 2 * mathy.MaxInt(-lowY, -lowX, highY, highX)
grid := make([][]int, edgeLength)
for i := 0; i < edgeLength; i++ {
+2 -1
View File
@@ -1,11 +1,12 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"log"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,11 +1,12 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strconv"
"strings"
"time"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -8
View File
@@ -1,18 +1,12 @@
/*
Intcode struct is defined within this file
Robot struct houses an Intcode computer and a method to initialize the floor details
- an algorithm in the main function traverses all tiles and checks all of its neighbors
- for all intersections that are found, their alignment parameters are calculated & added to a sum
*/
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"log"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -6
View File
@@ -1,17 +1,13 @@
/*
Intcode struct is defined within this file
Robot struct houses an Intcode computer and a method to initialize the floor details
*/
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"log"
"strconv"
"strings"
"time"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,11 +1,12 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"math"
"strings"
"time"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,11 +1,12 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"math"
"sort"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -7
View File
@@ -1,17 +1,12 @@
/*
Intcode struct is defined within this file
- Every drone needs its own computer made, I let them get garbage collected as often
as possible, not sure how extendable this is going to be to part 2
*/
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"log"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -7
View File
@@ -1,17 +1,12 @@
/*
Intcode struct is defined within this file
- Every drone needs its own computer made, I let them get garbage collected as often
as possible, not sure how extendable this is going to be to part 2
*/
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"log"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,10 +1,11 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"math"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,10 +1,11 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"math"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -6
View File
@@ -1,16 +1,12 @@
/*
Intcode struct is defined within this file
*/
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"log"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -7
View File
@@ -1,17 +1,12 @@
/*
Intcode struct is defined within this file
Helper function that converts strings to ASCII codes to be written to the computer
it could all be combined together into a new computer...
*/
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"log"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,10 +1,11 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
type instruction struct {
+2 -1
View File
@@ -6,11 +6,12 @@ Intcode struct is defined within this file
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"log"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -7,11 +7,12 @@ Network struct to store 50 instances of Intcode computers and 50 queues for thei
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"log"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,9 +1,10 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,9 +1,10 @@
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
// RecursiveWorld stores a big 3D matrix & will have associated methods
+2 -6
View File
@@ -1,18 +1,14 @@
/*
Intcode struct is defined within this file
Helper function that converts strings to ASCII codes to be written to the computer
*/
package main
import (
"github.com/alexchao26/advent-of-code-go/util"
"bufio"
"fmt"
"log"
"os"
"strconv"
"strings"
"github.com/alexchao26/advent-of-code-go/util"
)
func main() {
+2 -1
View File
@@ -1,6 +1,7 @@
package main
import "fmt"
func main() {
fmt.Println("There is no part2, the 50th star is the sun!")
}
+2 -2
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -61,7 +61,7 @@ func parseInputs(input string) []int {
nums := []int{}
for _, n := range split {
nums = append(nums, mathutil.StrToInt(n))
nums = append(nums, cast.ToInt(n))
}
return nums
+2 -2
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -59,7 +59,7 @@ func parseInput(input string) map[string]map[string]int {
continue
}
parts := strings.Split(content, " ")
graph[color][parts[1]+" "+parts[2]] = mathutil.StrToInt(parts[0])
graph[color][parts[1]+" "+parts[2]] = cast.ToInt(parts[0])
}
}
return graph
+8 -7
View File
@@ -6,7 +6,8 @@ import (
"sort"
"strings"
"github.com/alexchao26/advent-of-code-go/algo"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -29,7 +30,7 @@ func main() {
func part1(input string) int {
nums := parseInput(input)
nums = append(nums, mathutil.MaxInt(nums...)+3)
nums = append(nums, mathy.MaxInt(nums...)+3)
sort.Ints(nums)
var oneDiff, threeDiff int
@@ -51,7 +52,7 @@ func part1(input string) int {
func part2(input string) int {
nums := parseInput(input)
nums = append(nums, mathutil.MaxInt(nums...)+3)
nums = append(nums, mathy.MaxInt(nums...)+3)
sort.Ints(nums)
// return dynamicProgramming(input)
@@ -63,7 +64,7 @@ func parseInput(input string) []int {
lines := strings.Split(input, "\n")
for _, l := range lines {
ans = append(ans, mathutil.StrToInt(l))
ans = append(ans, cast.ToInt(l))
}
return ans
@@ -100,16 +101,16 @@ func memoCountPossibilities(nums []int, lastJolt int) int {
return count
}
func makeMemoKey(nums []int, lastJolt int) string {
ans := algo.IntToStr(lastJolt) + "x"
ans := cast.ToString(lastJolt) + "x"
for _, v := range nums {
ans += algo.IntToStr(v)
ans += cast.ToString(v)
}
return ans
}
func dynamicProgramming(input string) int {
nums := parseInput(input)
nums = append(nums, mathutil.MaxInt(nums...)+3, 0)
nums = append(nums, mathy.MaxInt(nums...)+3, 0)
sort.Ints(nums)
// initialize table with "1 way" to get to zero jolts
+5 -4
View File
@@ -5,7 +5,8 @@ import (
"fmt"
"strings"
"github.com/alexchao26/advent-of-code-go/mathutil"
"github.com/alexchao26/advent-of-code-go/cast"
"github.com/alexchao26/advent-of-code-go/mathy"
"github.com/alexchao26/advent-of-code-go/util"
)
@@ -67,7 +68,7 @@ func part1(input string) int {
}
}
return mathutil.ManhattanDistance(0, 0, shipX, shipY)
return mathy.ManhattanDistance(0, 0, shipX, shipY)
}
func part2(input string) int {
@@ -111,7 +112,7 @@ func part2(input string) int {
}
}
return mathutil.ManhattanDistance(0, 0, shipX, shipY)
return mathy.ManhattanDistance(0, 0, shipX, shipY)
}
type instruction struct {
@@ -126,7 +127,7 @@ func parseInput(input string) []instruction {
for _, l := range lines {
inst := instruction{
action: l[:1],
value: mathutil.StrToInt(l[1:]),
value: cast.ToInt(l[1:]),
}
ans = append(ans, inst)
}

Some files were not shown because too many files have changed in this diff Show More