adding 2015 & 2025 advents
This commit is contained in:
2
2015/02/example.txt
Normal file
2
2015/02/example.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
2x3x4
|
||||||
|
1x1x10
|
||||||
10
2015/02/golang/.vscode/settings.json
vendored
Normal file
10
2015/02/golang/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"[go]": {
|
||||||
|
"editor.insertSpaces": false,
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"editor.defaultFormatter": "golang.go",
|
||||||
|
"editor.codeActionsOnSave": {
|
||||||
|
"source.organizeImports": "explicit"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
2015/02/golang/go.mod
Normal file
3
2015/02/golang/go.mod
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module aoc/day-2
|
||||||
|
|
||||||
|
go 1.24.4
|
||||||
105
2015/02/golang/main.go
Normal file
105
2015/02/golang/main.go
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Dimension struct {
|
||||||
|
l, w, h int
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
input := readFile("../input.txt")
|
||||||
|
fmt.Println(part1(input))
|
||||||
|
fmt.Println(part2(input))
|
||||||
|
}
|
||||||
|
|
||||||
|
func part1(input string) int {
|
||||||
|
list := strings.Split(input, "\r\n")
|
||||||
|
total := 0
|
||||||
|
for _, p := range list {
|
||||||
|
total += calculateWrapSize(parseDimensions(p))
|
||||||
|
}
|
||||||
|
return total
|
||||||
|
}
|
||||||
|
|
||||||
|
func part2(input string) int {
|
||||||
|
list := strings.Split(input, "\r\n")
|
||||||
|
total := 0
|
||||||
|
for _, p := range list {
|
||||||
|
total += calculateBowSize(parseDimensions(p))
|
||||||
|
}
|
||||||
|
return total
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseDimensions(input string) Dimension {
|
||||||
|
splitValues := strings.Split(input, "x")
|
||||||
|
l, _ := strconv.Atoi(splitValues[0])
|
||||||
|
w, _ := strconv.Atoi(splitValues[1])
|
||||||
|
h, _ := strconv.Atoi(splitValues[2])
|
||||||
|
return Dimension{
|
||||||
|
l: l,
|
||||||
|
w: w,
|
||||||
|
h: h,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func calculateBowSize(dimensions Dimension) int {
|
||||||
|
sorted := quickSort([]int{dimensions.l, dimensions.w, dimensions.h})
|
||||||
|
first := sorted[0]
|
||||||
|
second := sorted[1]
|
||||||
|
ribbonLength := first*2 + second*2
|
||||||
|
extra := dimensions.l * dimensions.w * dimensions.h
|
||||||
|
return ribbonLength + extra
|
||||||
|
}
|
||||||
|
|
||||||
|
func calculateWrapSize(dimensions Dimension) int {
|
||||||
|
lw := dimensions.l * dimensions.w
|
||||||
|
wh := dimensions.w * dimensions.h
|
||||||
|
hl := dimensions.h * dimensions.l
|
||||||
|
smallest := min([]int{lw, wh, hl})
|
||||||
|
return 2*lw + 2*wh + 2*hl + smallest
|
||||||
|
}
|
||||||
|
|
||||||
|
func quickSort(arr []int) []int {
|
||||||
|
if len(arr) < 2 {
|
||||||
|
return arr
|
||||||
|
}
|
||||||
|
left, right := 0, len(arr)-1
|
||||||
|
// Choose the pivot (here, the last element)
|
||||||
|
pivot := arr[right]
|
||||||
|
// Partition: all elements less than pivot to the left
|
||||||
|
for i := range arr {
|
||||||
|
if arr[i] < pivot {
|
||||||
|
arr[i], arr[left] = arr[left], arr[i]
|
||||||
|
left++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Place the pivot after the last smaller element
|
||||||
|
arr[left], arr[right] = arr[right], arr[left]
|
||||||
|
// Recursively sort left and right parts
|
||||||
|
quickSort(arr[:left])
|
||||||
|
quickSort(arr[left+1:])
|
||||||
|
return arr
|
||||||
|
}
|
||||||
|
|
||||||
|
func min(list []int) int {
|
||||||
|
min := list[0]
|
||||||
|
for _, v := range list {
|
||||||
|
if v < min {
|
||||||
|
min = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return min
|
||||||
|
}
|
||||||
|
|
||||||
|
func readFile(filename string) string {
|
||||||
|
content, err := os.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return string(content)
|
||||||
|
}
|
||||||
1000
2015/02/input.txt
Normal file
1000
2015/02/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
1
2015/03/example.txt
Normal file
1
2015/03/example.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
^>v<
|
||||||
10
2015/03/golang/.vscode/settings.json
vendored
Normal file
10
2015/03/golang/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"[go]": {
|
||||||
|
"editor.insertSpaces": false,
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"editor.defaultFormatter": "golang.go",
|
||||||
|
"editor.codeActionsOnSave": {
|
||||||
|
"source.organizeImports": "explicit"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
2015/03/golang/go.mod
Normal file
3
2015/03/golang/go.mod
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module aoc/day-3
|
||||||
|
|
||||||
|
go 1.24.4
|
||||||
87
2015/03/golang/main.go
Normal file
87
2015/03/golang/main.go
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Point struct {
|
||||||
|
x, y int
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
input := readFile("../input.txt")
|
||||||
|
fmt.Println(input)
|
||||||
|
fmt.Println(part1(input))
|
||||||
|
fmt.Println(part2(input))
|
||||||
|
}
|
||||||
|
|
||||||
|
func part1(input string) int {
|
||||||
|
data := strings.Split(input, "")
|
||||||
|
locations := make(map[Point]int)
|
||||||
|
current := Point{x: 0, y: 0}
|
||||||
|
locations[current] = 1
|
||||||
|
for _, v := range data {
|
||||||
|
current = updateLocation(current, v)
|
||||||
|
l, exists := locations[current]
|
||||||
|
if exists {
|
||||||
|
locations[current] = l + 1
|
||||||
|
} else {
|
||||||
|
locations[current] = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return len(locations)
|
||||||
|
}
|
||||||
|
|
||||||
|
func part2(input string) int {
|
||||||
|
data := strings.Split(input, "")
|
||||||
|
locations := make(map[Point]int)
|
||||||
|
santa := Point{x: 0, y: 0}
|
||||||
|
robot := Point{x: 0, y: 0}
|
||||||
|
locations[santa] = 1
|
||||||
|
locations[robot] = 1
|
||||||
|
for i, v := range data {
|
||||||
|
if i%2 == 0 {
|
||||||
|
santa = updateLocation(santa, v)
|
||||||
|
l, exists := locations[santa]
|
||||||
|
if exists {
|
||||||
|
locations[santa] = l + 1
|
||||||
|
} else {
|
||||||
|
locations[santa] = 1
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
robot = updateLocation(robot, v)
|
||||||
|
l, exists := locations[robot]
|
||||||
|
if exists {
|
||||||
|
locations[robot] = l + 1
|
||||||
|
} else {
|
||||||
|
locations[robot] = 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return len(locations)
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateLocation(point Point, direction string) Point {
|
||||||
|
switch direction {
|
||||||
|
case "^":
|
||||||
|
return Point{point.x, point.y + 1}
|
||||||
|
case "v":
|
||||||
|
return Point{point.x, point.y - 1}
|
||||||
|
case ">":
|
||||||
|
return Point{point.x + 1, point.y}
|
||||||
|
case "<":
|
||||||
|
return Point{point.x - 1, point.y}
|
||||||
|
default:
|
||||||
|
return point
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func readFile(filename string) string {
|
||||||
|
content, err := os.ReadFile(filename)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return string(content)
|
||||||
|
}
|
||||||
1
2015/03/input.txt
Normal file
1
2015/03/input.txt
Normal file
File diff suppressed because one or more lines are too long
10
2015/04/golang/.vscode/settings.json
vendored
Normal file
10
2015/04/golang/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"[go]": {
|
||||||
|
"editor.insertSpaces": false,
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"editor.defaultFormatter": "golang.go",
|
||||||
|
"editor.codeActionsOnSave": {
|
||||||
|
"source.organizeImports": "explicit"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
2015/04/golang/go.mod
Normal file
3
2015/04/golang/go.mod
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
module aoc/day-4
|
||||||
|
|
||||||
|
go 1.24.4
|
||||||
29
2015/04/golang/main.go
Normal file
29
2015/04/golang/main.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
const key = "bgvyzdsv"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
i := 0
|
||||||
|
var found = false
|
||||||
|
for !found {
|
||||||
|
hash := genMD5Hash(key + strconv.Itoa(i))
|
||||||
|
if hash[0:6] == "000000" {
|
||||||
|
found = true
|
||||||
|
} else {
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println(i)
|
||||||
|
}
|
||||||
|
|
||||||
|
func genMD5Hash(text string) string {
|
||||||
|
hash := md5.Sum([]byte(text))
|
||||||
|
return hex.EncodeToString(hash[:])
|
||||||
|
}
|
||||||
5
2025/01/JS/deno.json
Normal file
5
2025/01/JS/deno.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"tasks": {
|
||||||
|
"dev": "deno run --watch main.ts"
|
||||||
|
}
|
||||||
|
}
|
||||||
10
2025/01/JS/example.txt
Normal file
10
2025/01/JS/example.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
L68
|
||||||
|
L30
|
||||||
|
R48
|
||||||
|
L5
|
||||||
|
R60
|
||||||
|
L55
|
||||||
|
L1
|
||||||
|
L99
|
||||||
|
R14
|
||||||
|
L82
|
||||||
4732
2025/01/JS/input.txt
Normal file
4732
2025/01/JS/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
43
2025/01/JS/main.ts
Normal file
43
2025/01/JS/main.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
const input = await Deno.readTextFile("input.txt");
|
||||||
|
const START = 50
|
||||||
|
const TOTAL = 100
|
||||||
|
|
||||||
|
function part1(){
|
||||||
|
let password = 0
|
||||||
|
let current = START
|
||||||
|
for (const rotation of input.split('\n')) {
|
||||||
|
const direction = rotation[0]
|
||||||
|
let amount = Number(rotation.slice(1))
|
||||||
|
if (direction === "L") {
|
||||||
|
amount *= -1
|
||||||
|
}
|
||||||
|
let change = current + amount
|
||||||
|
while (change < 0) {
|
||||||
|
change = TOTAL + change
|
||||||
|
}
|
||||||
|
current = change % TOTAL
|
||||||
|
if (current === 0) {
|
||||||
|
password += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(password)
|
||||||
|
}
|
||||||
|
|
||||||
|
function part2(){
|
||||||
|
let password = 0
|
||||||
|
let current = START
|
||||||
|
for (const rotation of input.split('\n')) {
|
||||||
|
const direction = rotation[0]
|
||||||
|
let amount = Number(rotation.slice(1))
|
||||||
|
if (direction === "L") {
|
||||||
|
const divisions = Math.floor((amount * -1) / TOTAL * -1)
|
||||||
|
password += divisions
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(password)
|
||||||
|
}
|
||||||
|
|
||||||
|
//part1()
|
||||||
|
part2()
|
||||||
Reference in New Issue
Block a user