-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
285 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,74 @@ | ||
package day01 | ||
|
||
import ( | ||
"aoc-2023-go/helpers" | ||
"strings" | ||
"aoc-2023-go/helpers" | ||
"strings" | ||
) | ||
|
||
var inputFile string | ||
var digitStrings map[string]int | ||
|
||
func init() { | ||
inputFile = helpers.ReadInput() | ||
|
||
digitStrings = make(map[string]int) | ||
digitStrings["one"] = 1 | ||
digitStrings["two"] = 2 | ||
digitStrings["three"] = 3 | ||
digitStrings["four"] = 4 | ||
digitStrings["five"] = 5 | ||
digitStrings["six"] = 6 | ||
digitStrings["seven"] = 7 | ||
digitStrings["eight"] = 8 | ||
digitStrings["nine"] = 9 | ||
inputFile = helpers.ReadInput() | ||
|
||
digitStrings = make(map[string]int) | ||
digitStrings["one"] = 1 | ||
digitStrings["two"] = 2 | ||
digitStrings["three"] = 3 | ||
digitStrings["four"] = 4 | ||
digitStrings["five"] = 5 | ||
digitStrings["six"] = 6 | ||
digitStrings["seven"] = 7 | ||
digitStrings["eight"] = 8 | ||
digitStrings["nine"] = 9 | ||
} | ||
|
||
func Part1() int { | ||
return solve1(inputFile) | ||
return solve1(inputFile) | ||
} | ||
|
||
func Part2() int { | ||
return solve2(inputFile) | ||
return solve2(inputFile) | ||
} | ||
|
||
func solve1(input string) int { | ||
sum := 0 | ||
sum := 0 | ||
|
||
for _, line := range strings.Split(input, "\n") { | ||
digits := make([]int, 0) | ||
for _, line := range strings.Split(input, "\n") { | ||
digits := make([]int, 0) | ||
|
||
for _, c := range line { | ||
if c >= '0' && c <= '9' { | ||
digits = append(digits, int(c)-'0') | ||
} | ||
} | ||
for _, c := range line { | ||
if c >= '0' && c <= '9' { | ||
digits = append(digits, int(c)-'0') | ||
} | ||
} | ||
|
||
sum += digits[0]*10 + digits[len(digits)-1] | ||
} | ||
sum += digits[0]*10 + digits[len(digits)-1] | ||
} | ||
|
||
return sum | ||
return sum | ||
} | ||
|
||
func solve2(input string) int { | ||
sum := 0 | ||
sum := 0 | ||
|
||
for _, line := range strings.Split(input, "\n") { | ||
digits := make([]int, 0) | ||
for _, line := range strings.Split(input, "\n") { | ||
digits := make([]int, 0) | ||
|
||
for i, c := range line { | ||
if c >= '0' && c <= '9' { | ||
digits = append(digits, int(c)-'0') | ||
} | ||
for i, c := range line { | ||
if c >= '0' && c <= '9' { | ||
digits = append(digits, int(c)-'0') | ||
} | ||
|
||
for key, value := range digitStrings { | ||
if strings.HasPrefix(line[i:], key) { | ||
digits = append(digits, value) | ||
} | ||
} | ||
} | ||
for key, value := range digitStrings { | ||
if strings.HasPrefix(line[i:], key) { | ||
digits = append(digits, value) | ||
} | ||
} | ||
} | ||
|
||
sum += digits[0]*10 + digits[len(digits)-1] | ||
} | ||
sum += digits[0]*10 + digits[len(digits)-1] | ||
} | ||
|
||
return sum | ||
return sum | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,53 @@ | ||
package day02 | ||
|
||
import ( | ||
"aoc-2023-go/helpers" | ||
"aoc-2023-go/helpers" | ||
) | ||
|
||
var inputLines []string | ||
|
||
func init() { | ||
inputLines = helpers.ReadInputLines() | ||
inputLines = helpers.ReadInputLines() | ||
} | ||
|
||
func Part1() int { | ||
return solve1(inputLines) | ||
return solve1(inputLines) | ||
} | ||
|
||
func Part2() int { | ||
return solve2(inputLines) | ||
return solve2(inputLines) | ||
} | ||
|
||
func solve1(input []string) int { | ||
games := make([]Game, 0) | ||
games := make([]Game, 0) | ||
|
||
for _, line := range input { | ||
games = append(games, parseGame(line)) | ||
} | ||
for _, line := range input { | ||
games = append(games, parseGame(line)) | ||
} | ||
|
||
sum := 0 | ||
sum := 0 | ||
|
||
for _, game := range games { | ||
if game.isPossible() { | ||
sum += game.id | ||
} | ||
} | ||
for _, game := range games { | ||
if game.isPossible() { | ||
sum += game.id | ||
} | ||
} | ||
|
||
return sum | ||
return sum | ||
} | ||
|
||
func solve2(input []string) int { | ||
games := make([]Game, 0) | ||
games := make([]Game, 0) | ||
|
||
for _, line := range input { | ||
games = append(games, parseGame(line)) | ||
} | ||
for _, line := range input { | ||
games = append(games, parseGame(line)) | ||
} | ||
|
||
sum := 0 | ||
sum := 0 | ||
|
||
for _, game := range games { | ||
sum += game.power() | ||
} | ||
for _, game := range games { | ||
sum += game.power() | ||
} | ||
|
||
return sum | ||
return sum | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.