Compare commits
9 Commits
d2ce81647b
...
change-inp
| Author | SHA1 | Date | |
|---|---|---|---|
| df779eb510 | |||
| 79f63b0bf0 | |||
| 492d2a602a | |||
| fc9a332e63 | |||
| 134cb7aad1 | |||
| d36262eaf4 | |||
| e7a054c57f | |||
| 00815609cb | |||
| 14928230b8 |
8
.github/workflows/build.yml
vendored
8
.github/workflows/build.yml
vendored
@@ -10,8 +10,12 @@ jobs:
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: '1.21.x'
|
||||
- name: Build
|
||||
run: go build -v ./*/*.go
|
||||
- name: Build day one
|
||||
run: go build -v ./day01/*.go
|
||||
- name: Build day two
|
||||
run: go build -v ./day02/*.go
|
||||
- name: Run day one
|
||||
run: go run -v ./day01/*.go
|
||||
- name: Display Go version
|
||||
run: go version
|
||||
- name: List files in the repository
|
||||
|
||||
1
day01/inputs
Symbolic link
1
day01/inputs
Symbolic link
@@ -0,0 +1 @@
|
||||
../inputs
|
||||
@@ -109,7 +109,7 @@ func CombineIndexes(s string) int {
|
||||
}
|
||||
|
||||
func main() {
|
||||
file, err := os.Open("input")
|
||||
file, err := os.Open("./inputs/day01_input")
|
||||
check(err)
|
||||
defer file.Close()
|
||||
|
||||
|
||||
1
day02/inputs
Symbolic link
1
day02/inputs
Symbolic link
@@ -0,0 +1 @@
|
||||
../inputs
|
||||
@@ -26,6 +26,12 @@ type possibleGame struct {
|
||||
blueIsPossible bool
|
||||
}
|
||||
|
||||
type minimumSet struct {
|
||||
red int
|
||||
green int
|
||||
blue int
|
||||
}
|
||||
|
||||
func splitSets (s string) ([]string, int) {
|
||||
// Every set is divided by ;
|
||||
sets := strings.SplitN(s, ";", -1)
|
||||
@@ -62,13 +68,24 @@ func CheckGame(mySet map[string]int, p *possibleGame) {
|
||||
}
|
||||
}
|
||||
|
||||
func findMinimumSet(mySet map[string]int, m *minimumSet) {
|
||||
if (mySet["red"] > m.red) {
|
||||
m.red = mySet["red"]
|
||||
}
|
||||
if (mySet["green"] > m.green) {
|
||||
m.green = mySet["green"]
|
||||
}
|
||||
if (mySet["blue"] > m.blue) {
|
||||
m.blue = mySet["blue"]
|
||||
}
|
||||
}
|
||||
|
||||
func PossibleGamesSum(s string, gn int, gt *int) {
|
||||
var isPossible possibleGame
|
||||
// Initialize everything to true. If everything was set to false,
|
||||
// we would have to check in both directions for every pass
|
||||
isPossible.redIsPossible = true
|
||||
isPossible.greenIsPossible = true
|
||||
isPossible.blueIsPossible = true
|
||||
isPossible := possibleGame{redIsPossible: true,
|
||||
greenIsPossible: true,
|
||||
blueIsPossible: true}
|
||||
// We will pass a pointer so we can go one map at a time and
|
||||
// still maintain the results
|
||||
var isPossiblePoint *possibleGame
|
||||
@@ -94,13 +111,36 @@ func PossibleGamesSum(s string, gn int, gt *int) {
|
||||
}
|
||||
}
|
||||
|
||||
func PowerSetsSum(s string, pt *int) {
|
||||
// In this case, we need an array of integers
|
||||
minSet := minimumSet{red: 0, green: 0, blue: 0}
|
||||
|
||||
var minSetPoint *minimumSet
|
||||
minSetPoint = &minSet
|
||||
|
||||
// We receive a string with the sets, not split
|
||||
// We proceed to split
|
||||
sets, numSets := splitSets(s)
|
||||
// We received a []string with sets and the number of sets
|
||||
// Now it's time to create a map
|
||||
var mySet map[string]int
|
||||
// For every set we have in the current game
|
||||
for i := 0; i < numSets; i++ {
|
||||
// We create a map
|
||||
mySet = newGameSet(sets[i])
|
||||
// We find the minimum set
|
||||
findMinimumSet(mySet, minSetPoint)
|
||||
}
|
||||
*pt += (minSet.red * minSet.green * minSet.blue)
|
||||
}
|
||||
|
||||
func PrintAndWait[T any](x T) {
|
||||
fmt.Print(x)
|
||||
fmt.Scanln()
|
||||
}
|
||||
|
||||
func main() {
|
||||
file, err := os.Open("input")
|
||||
file, err := os.Open("./inputs/day02_input")
|
||||
check(err)
|
||||
defer file.Close()
|
||||
|
||||
@@ -110,7 +150,11 @@ func main() {
|
||||
var gameSumPoint *int
|
||||
gameSum := 0
|
||||
gameSumPoint = &gameSum
|
||||
|
||||
|
||||
// Variable for the sum of the power of the sets
|
||||
var power int = 0
|
||||
// Pointer to power, nice variable name
|
||||
var powerPoint *int = &power
|
||||
|
||||
_ = gameNum
|
||||
scanner := bufio.NewScanner(file)
|
||||
@@ -124,6 +168,8 @@ func main() {
|
||||
gameNum, _ = strconv.Atoi(strings.Replace(gameAndCubes[0], "Game ", "", 1))
|
||||
// Now, for every game, split the sets
|
||||
PossibleGamesSum(gameAndCubes[1], gameNum, gameSumPoint)
|
||||
PowerSetsSum(gameAndCubes[1], powerPoint)
|
||||
}
|
||||
fmt.Printf("The sum of possible games is: %d\n", gameSum)
|
||||
fmt.Printf("The sum of possible games is: %d\n", gameSum)
|
||||
fmt.Printf("The sum of the power of sets is: %d\n", power)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user