Compare commits
5 Commits
main
...
7cd663278e
| Author | SHA1 | Date | |
|---|---|---|---|
| 7cd663278e | |||
| 903a151e4c | |||
| 9632022b82 | |||
| 15b6a0da55 | |||
| f69d4e14ad |
@@ -1 +0,0 @@
|
|||||||
3.13
|
|
||||||
@@ -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()
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
[project]
|
|
||||||
name = "python"
|
|
||||||
version = "0.1.0"
|
|
||||||
description = "Add your description here"
|
|
||||||
readme = "README.md"
|
|
||||||
requires-python = ">=3.13"
|
|
||||||
dependencies = []
|
|
||||||
8
2015/01/python/uv.lock
generated
8
2015/01/python/uv.lock
generated
@@ -1,8 +0,0 @@
|
|||||||
version = 1
|
|
||||||
revision = 2
|
|
||||||
requires-python = ">=3.13"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "python"
|
|
||||||
version = "0.1.0"
|
|
||||||
source = { virtual = "." }
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
2x3x4
|
|
||||||
1x1x10
|
|
||||||
10
2015/02/golang/.vscode/settings.json
vendored
10
2015/02/golang/.vscode/settings.json
vendored
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"[go]": {
|
|
||||||
"editor.insertSpaces": false,
|
|
||||||
"editor.formatOnSave": true,
|
|
||||||
"editor.defaultFormatter": "golang.go",
|
|
||||||
"editor.codeActionsOnSave": {
|
|
||||||
"source.organizeImports": "explicit"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
module aoc/day-2
|
|
||||||
|
|
||||||
go 1.24.4
|
|
||||||
@@ -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)
|
|
||||||
}
|
|
||||||
1000
2015/02/input.txt
1000
2015/02/input.txt
File diff suppressed because it is too large
Load Diff
@@ -1 +0,0 @@
|
|||||||
^>v<
|
|
||||||
10
2015/03/golang/.vscode/settings.json
vendored
10
2015/03/golang/.vscode/settings.json
vendored
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"[go]": {
|
|
||||||
"editor.insertSpaces": false,
|
|
||||||
"editor.formatOnSave": true,
|
|
||||||
"editor.defaultFormatter": "golang.go",
|
|
||||||
"editor.codeActionsOnSave": {
|
|
||||||
"source.organizeImports": "explicit"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
module aoc/day-3
|
|
||||||
|
|
||||||
go 1.24.4
|
|
||||||
@@ -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
10
2015/04/golang/.vscode/settings.json
vendored
10
2015/04/golang/.vscode/settings.json
vendored
@@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"[go]": {
|
|
||||||
"editor.insertSpaces": false,
|
|
||||||
"editor.formatOnSave": true,
|
|
||||||
"editor.defaultFormatter": "golang.go",
|
|
||||||
"editor.codeActionsOnSave": {
|
|
||||||
"source.organizeImports": "explicit"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
module aoc/day-4
|
|
||||||
|
|
||||||
go 1.24.4
|
|
||||||
@@ -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[:])
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"tasks": {
|
|
||||||
"dev": "deno run --watch main.ts"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
L68
|
|
||||||
L30
|
|
||||||
R48
|
|
||||||
L5
|
|
||||||
R60
|
|
||||||
L55
|
|
||||||
L1
|
|
||||||
L99
|
|
||||||
R14
|
|
||||||
L82
|
|
||||||
4732
2025/01/JS/input.txt
4732
2025/01/JS/input.txt
File diff suppressed because it is too large
Load Diff
@@ -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()
|
|
||||||
Reference in New Issue
Block a user