feat: init commit. added all prior solutions

master
artist 2024-12-24 18:58:46 -06:00
commit 44af947ccf
6 changed files with 152 additions and 0 deletions

33
day1/day1.go 100644
View File

@ -0,0 +1,33 @@
package main
import (
"fmt"
"sort"
)
func abs(num int) int {
if (num < 0) {
return -num
} else {
return num
}
}
func main() {
var list1 = []int{3,4,2,1,3,3}
var list2 = []int{4,3,5,3,9,3}
var distanceTotal int = 0
sort.Ints(list1)
sort.Ints(list2)
// finding the difference between each number
if len(list1) == len(list2) {
for i := range list1 {
distanceTotal += abs(list1[i]-list2[i])
}
}
fmt.Println(list1)
fmt.Println(list2)
fmt.Println(distanceTotal)
}

3
day1/go.mod 100644
View File

@ -0,0 +1,3 @@
module day1
go 1.23.0

60
day2/day2.go 100644
View File

@ -0,0 +1,60 @@
package main
import (
"fmt"
)
// https://adventofcode.com/2024/day/2
// 7 6 4 2 1
// 1 2 7 8 9
// 9 7 6 2 1
// 1 3 2 4 5
// 8 6 4 4 1
// 1 3 6 7 9
var reports = [][]int{{7,6,4,2,1},
{1,2,7,8,9},
{9,7,6,2,1},
{1,3,2,4,5},
{8,6,4,4,1},
{1,3,6,7,9}}
func abs(num int) int {
if (num < 0) {
return -num
} else {
return num
}
}
// lvl == level
func compareLevels(report []int) (bool) {
var isReportSafe bool = false
var incrOrDecr bool = report[1] > report[0] // incr: true | decr: false
for i := 0; i < len(report)-1; i++ {
var lvlDifference int = abs(report[i]-report[i+1])
if lvlDifference > 3 || lvlDifference == 0 {
return false
} else if incrOrDecr != (report[i+1] > report[i]) {
return false
} else {
isReportSafe = true
continue
}
}
return isReportSafe
}
func main() {
var safeReportCount int
for _, report := range reports {
isReportSafe := compareLevels(report)
if isReportSafe {
safeReportCount++
}
}
fmt.Printf("List of reports: %v\n", reports)
fmt.Printf("Number of safe reports: %v\n", safeReportCount)
}

3
day2/go.mod 100644
View File

@ -0,0 +1,3 @@
module day2
go 1.23.0

50
day4/day4.go 100644
View File

@ -0,0 +1,50 @@
package main
import (
"fmt"
)
var wordSearch = [][]string{{"M","M","M","S","X","X","M","A","S","M"},
{"M","S","A","M","X","M","S","M","S","A"},
{"A","M","X","S","X","M","A","A","M","M"},
{"M","S","A","M","A","S","M","S","M","X"},
{"X","M","A","S","A","M","X","A","M","M"},
{"X","X","A","M","M","X","X","A","M","A"},
{"S","M","S","M","S","A","S","X","S","S"},
{"S","A","X","A","M","A","S","A","A","A"},
{"M","A","M","M","M","X","M","M","M","M"},
{"M","X","M","X","A","X","M","A","S","X"}}
// func letterSearch(wordSearch string) (string, bool) {
// }
func main() {
fmt.Println(wordSearch)
for y, letterRow := range wordSearch {
for x, letter := range letterRow {
if letter == "X" {
/*
+----------+----------+----------+
| y-1, x-1 | y-1, x | y-1, x+1 |
+----------+----------+----------+
| y, x-1 | letter | y, x+1 |
+----------+----------+----------+
| y+1, x-1 | y+1, x | y+1, x+1 |
+----------+----------+----------+
*/
// var letterNeighbors []string
// letterNeighbors[0] = board[y-1][x-1]
// letterNeighbors[1] = board[y-1][x]
// letterNeighbors[2] = board[y-1][x+1]
// letterNeighbors[3] = board[y][x-1]
// letterNeighbors[4] = board[y][x+1]
// letterNeighbors[5] = board[y+1][x-1]
// letterNeighbors[6] = board[y+1][x]
// letterNeighbors[7] = board[y+1][x+1]
}
fmt.Println(letter)
}
}
}

3
day4/go.mod 100644
View File

@ -0,0 +1,3 @@
module day4
go 1.23.0