Compare commits

..

5 Commits

Author SHA1 Message Date
7cd663278e added 2024 part 2 2025-06-05 22:47:31 +02:00
903a151e4c added 2024 part 1 2025-06-05 22:47:31 +02:00
9632022b82 added year of 2023 2025-06-05 22:45:07 +02:00
15b6a0da55 renamed folder date 2025-06-05 22:44:47 +02:00
f69d4e14ad Implemtend Day 01 of 2025 with Golang 2025-06-05 10:52:18 +02:00
21 changed files with 0 additions and 6104 deletions

View File

@@ -1 +0,0 @@
3.13

View File

@@ -1,34 +0,0 @@
def main():
input = read_file("../input.txt")
data = list(input)
print(part1(data))
print(part2(data))
def part1(data: list[str]) -> int:
floor_level = 0
for c in data:
if c == "(":
floor_level += 1
else:
floor_level -= 1
return floor_level
def part2(data: list[str]) -> int:
floor_level = 0
location_index = 0
for i, c in enumerate(data):
if c == "(":
floor_level += 1
else:
floor_level -= 1
if floor_level == -1:
location_index = i
break
return location_index + 1
def read_file(filename: str) -> str:
with open(filename, 'r') as f:
return f.read()
if __name__ == "__main__":
main()

View File

@@ -1,7 +0,0 @@
[project]
name = "python"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.13"
dependencies = []

View File

@@ -1,8 +0,0 @@
version = 1
revision = 2
requires-python = ">=3.13"
[[package]]
name = "python"
version = "0.1.0"
source = { virtual = "." }

View File

@@ -1,2 +0,0 @@
2x3x4
1x1x10

View File

@@ -1,10 +0,0 @@
{
"[go]": {
"editor.insertSpaces": false,
"editor.formatOnSave": true,
"editor.defaultFormatter": "golang.go",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
}
}

View File

@@ -1,3 +0,0 @@
module aoc/day-2
go 1.24.4

View File

@@ -1,105 +0,0 @@
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)
}

File diff suppressed because it is too large Load Diff

View File

@@ -1 +0,0 @@
^>v<

View File

@@ -1,10 +0,0 @@
{
"[go]": {
"editor.insertSpaces": false,
"editor.formatOnSave": true,
"editor.defaultFormatter": "golang.go",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
}
}

View File

@@ -1,3 +0,0 @@
module aoc/day-3
go 1.24.4

View File

@@ -1,87 +0,0 @@
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)
}

File diff suppressed because one or more lines are too long

View File

@@ -1,10 +0,0 @@
{
"[go]": {
"editor.insertSpaces": false,
"editor.formatOnSave": true,
"editor.defaultFormatter": "golang.go",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
}
}

View File

@@ -1,3 +0,0 @@
module aoc/day-4
go 1.24.4

View File

@@ -1,29 +0,0 @@
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[:])
}

View File

@@ -1,5 +0,0 @@
{
"tasks": {
"dev": "deno run --watch main.ts"
}
}

View File

@@ -1,10 +0,0 @@
L68
L30
R48
L5
R60
L55
L1
L99
R14
L82

File diff suppressed because it is too large Load Diff

View File

@@ -1,43 +0,0 @@
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()