From 2b0dad9d87b2b663ddc008876a4dbc3d17993d27 Mon Sep 17 00:00:00 2001 From: hachem Date: Tue, 25 Aug 2026 11:26:54 +0200 Subject: chore: refactor repository --- .gitignore | 6 +- Dockerfile | 9 +- LICENSE | 2 +- Makefile | 89 +- README.md | 43 +- aoc-2025/day1.asm | 314 +++ aoc-2025/day2.asm | 410 ++++ aoc-2025/day3.asm | 301 +++ aoc-2025/day4.asm | 25 + docker-entrypoint.sh | 26 - input/day1.txt | 4664 ------------------------------------------ input/day2.txt | 1 - input/day3.txt | 200 -- input/test-day1.txt | 10 - input/test-day2.txt | 1 - input/test-day3.txt | 4 - scripts/docker-entrypoint.sh | 26 + src/Day1.asm | 314 --- src/Day2.asm | 410 ---- src/Day3.asm | 301 --- src/Day4.asm | 25 - 21 files changed, 1154 insertions(+), 6027 deletions(-) create mode 100644 aoc-2025/day1.asm create mode 100644 aoc-2025/day2.asm create mode 100644 aoc-2025/day3.asm create mode 100644 aoc-2025/day4.asm delete mode 100644 docker-entrypoint.sh delete mode 100644 input/day1.txt delete mode 100644 input/day2.txt delete mode 100644 input/day3.txt delete mode 100644 input/test-day1.txt delete mode 100644 input/test-day2.txt delete mode 100644 input/test-day3.txt create mode 100644 scripts/docker-entrypoint.sh delete mode 100644 src/Day1.asm delete mode 100644 src/Day2.asm delete mode 100644 src/Day3.asm delete mode 100644 src/Day4.asm diff --git a/.gitignore b/.gitignore index fcb6a2f..c3de721 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ -build +build/ +inputs/ +**/inputs + +*.txt diff --git a/Dockerfile b/Dockerfile index ead2a68..6001385 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,14 +10,11 @@ RUN apt-get update \ WORKDIR /app COPY Makefile ./ -COPY src ./src -COPY input ./input +COPY aoc-* ./ COPY README.md LICENSE ./ -COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh +COPY scripts/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh -RUN chmod +x /usr/local/bin/docker-entrypoint.sh \ - && mkdir -p build +RUN chmod +x /usr/local/bin/docker-entrypoint.sh ENTRYPOINT ["docker-entrypoint.sh"] CMD ["list"] - diff --git a/LICENSE b/LICENSE index 20c9dc6..3837db2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2025 𝔥𝔞𝔠𝔥𝔢𝔪 +Copyright (c) 2025 hachem Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile index 9faa0fb..817247b 100644 --- a/Makefile +++ b/Makefile @@ -1,37 +1,52 @@ -NASM ?= nasm -LD ?= ld - -SRC_DIR := src -BUILD_DIR := build - -NASMFLAGS ?= -f elf64 -LDFLAGS ?= -m elf_x86_64 - -DAYS := Day1 Day2 Day3 Day4 Day5 Day6 \ - Day7 Day8 Day9 Day10 Day11 Day12 -BINARIES := $(addprefix $(BUILD_DIR)/,$(DAYS)) - -.PHONY: all clean list -.PHONY: day% run-day% - -all: $(BINARIES) - -$(BUILD_DIR): - @mkdir -p $(BUILD_DIR) - -$(BUILD_DIR)/Day%.o: $(SRC_DIR)/Day%.asm | $(BUILD_DIR) - @$(NASM) $(NASMFLAGS) $< -o $@ - -$(BUILD_DIR)/Day%: $(BUILD_DIR)/Day%.o - @$(LD) $(LDFLAGS) -o $@ $< - -day%: $(BUILD_DIR)/Day% -run-day%: $(BUILD_DIR)/Day% - @./$< - -list: - @printf "Available days:\n" - @for day in $(DAYS); do echo " $$day"; done - -clean: - rm -rf $(BUILD_DIR) +NASM ?= nasm +LD ?= ld + +YEAR ?= 2025 +DAY ?= + +SRC_DIR := aoc-$(YEAR) +BUILD_DIR := build/aoc-$(YEAR) + +NASMFLAGS ?= -f elf64 +LDFLAGS ?= -m elf_x86_64 + +DAYS := $(basename $(notdir $(wildcard $(SRC_DIR)/day*.asm))) +BINARIES := $(addprefix $(BUILD_DIR)/,$(DAYS)) + +.PHONY: all clean list run + +all: $(BINARIES) + +$(BUILD_DIR): + @mkdir -p $@ + +$(BUILD_DIR)/%.o: $(SRC_DIR)/%.asm | $(BUILD_DIR) + @$(NASM) $(NASMFLAGS) $< -o $@ + +$(BUILD_DIR)/%: $(BUILD_DIR)/%.o + @$(LD) $(LDFLAGS) -o $@ $< + +run: +ifndef DAY + $(error DAY is required, e.g. make run DAY=3) +endif + @$(MAKE) --no-print-directory $(BUILD_DIR)/day$(DAY) + @./$(BUILD_DIR)/day$(DAY) + +list: + @printf "\033[1;36mAdvent of Code %s\033[0m\n\n" "$(YEAR)" + @count=0; \ + for day in $(DAYS); do \ + number=$${day#day}; \ + printf " \033[1;33mDay %02d\033[0m" "$$number"; \ + count=$$((count + 1)); \ + if [ $$((count % 5)) -eq 0 ]; then \ + printf "\n"; \ + else \ + printf " "; \ + fi; \ + done + @printf "\n" + +clean: + rm -rf build diff --git a/README.md b/README.md index f2572bf..e57f776 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,29 @@ -# Advent of Code - 2025 -Yes, I started late. -Yes, I wrote it in x86_64 assembly. -No, there is no absolutely no good reason for this. -No, I'm not okay. +# aoc +My [AoC](https://adventofcode.com) solutions, written in x86-64 assembly. There is absolutely no good reason to pick assembly for this. I could have gone with C, C++, Rust, or pretty much anything else, but where's the fun in that? I'm doing this because I was bored, needed a reason to procrastinate, and, in any case, I don't have that many excuses to write assembly these days anymore, so these let me stay up to spec. Since assembly is beyond annoying to deal with between machines, I provide a Dockerfile with all the tools you might need to build and run the solutions. -### Why assembly? -Because I was really bored and I wanted more of an excuse to procrastinate. +I don't particularly care about the AoC leaderboard. December is usually a pretty busy time for me, so I often don't have the time (or energy) to sit down and solve every puzzle on the day it comes out. As a result, some solutions may be uploaded days, weeks, or potentially much later than the actual puzzle release. That's intentional. I'm doing these primarily because I enjoy solving the problems and because they're a fun excuse to write increasingly questionable amounts of assembly. Getting a good leaderboard position isn't really the point for me. If a solution appears suspiciously late, that's probably why. -also: **aura**. - -## Building & Running -```sh -$ make run-day[1-12] -# example: -$ make run-day1 -$ make run-day2 -``` -If you just want to build the binaries without running them do `make day[1-12]`. +AoC gives each user their own puzzle input. I keep my inputs locally and do not commit them to this repository. If you're running these solutions yourself, you'll need to provide your own inputs in whatever format the corresponding solution expects. ## Docker -If you do not have `nasm`/`ld` locally, build the container: +To build the Docker image, run this from the repository root: + ```sh -$ docker build -t aoc-2025 . +docker build -t aoc . ``` -Run a specific puzzle directly + +To run a specific day: + ```sh -$ docker run aoc-2025 day4 -$ docker run aoc-2025 day5 +docker run --rm aoc YEAR=2025 DAY=5 ``` -Running with no arguments (`docker run aoc-2025`) will list the available targets. If you only want to build a binary, use `build-day[1-12]`. -When you're done, delete the image: + +When you're done, remove the image with: + ```sh -$ docker rmi aoc-2025 +docker rmi aoc ``` ## License -[MIT](LICENSE), because you want this code, you need more help than permission. +[MIT](LICENSE), because if you actually want to use this code, you clearly need more help than permission. + diff --git a/aoc-2025/day1.asm b/aoc-2025/day1.asm new file mode 100644 index 0000000..8ba8f0e --- /dev/null +++ b/aoc-2025/day1.asm @@ -0,0 +1,314 @@ +; Advent of Code 2025 - Day 1 + +bits 64 +default rel + +global _start + +%define SYS_EXIT 60 +%define SYS_READ 0 +%define SYS_WRITE 1 +%define SYS_OPEN 2 +%define SYS_CLOSE 3 + +%define O_RDONLY 0 +%define STDOUT 1 + +section .data + inputPath db "input/day1.txt", 0 + newline db 10 + + label1 db "Password 1: ", 0 + label2 db "Password 2: ", 0 + + angle1 dd 50 + angle2 dd 50 + + password1 dd 0 + password2 dd 0 + +section .bss + buffer resb 4096 + lineBuffer resb 256 + numberBuffer resb 16 + lineLen resd 1 + +section .text + +_start: + ; open file + mov rax, SYS_OPEN + mov rdi, inputPath + mov rsi, O_RDONLY + xor rdx, rdx + syscall + + mov r12, rax ; fd in R12 + mov dword [lineLen], 0 ; no chars in current line yet + +ReadLoop: + ; read up to 4096 bytes + mov rax, SYS_READ + mov rdi, r12 + mov rsi, buffer + mov rdx, 4096 + syscall + + cmp rax, 0 + jle EOF ; <=0 -> EOF or error + + mov rdi, buffer ; scan pointer + mov rbp, rax ; bytes remaining in this chunk + +ScanChunk: + cmp rbp, 0 + je ReadLoop ; chunk done, read next + + mov al, [rdi] + + ; windows can be a fucking bitch + ; handle (CR) -> just skip + cmp al, 13 + je SkipCR + + ; handle LF (10) -> end of line + cmp al, 10 + je EndOfLine + + ; normal character -> append to lineBuffer if space left + mov edx, [lineLen] + cmp edx, 255 ; leave 1 byte for NULL + jae SkipStore ; ignore extra characters if too long + mov [lineBuffer+rdx], al + inc edx + mov [lineLen], edx + +SkipStore: + inc rdi + dec rbp + jmp ScanChunk + +SkipCR: + inc rdi + dec rbp + jmp ScanChunk + +EndOfLine: + ; terminate current line + mov edx, [lineLen] + mov byte [lineBuffer+rdx], 0 + + ; if line isn't empty, process it + cmp edx, 0 + je LineDone + + push rdi + mov rsi, lineBuffer + call HandleLine + pop rdi + +LineDone: + mov dword [lineLen], 0 ; reset line length + inc rdi + dec rbp + jmp ScanChunk + +; process last line if not newline-terminated, then print result +EOF: + ; if there is a partial line at EOF, process it + mov edx, [lineLen] + cmp edx, 0 + jle PrintResults + mov byte [lineBuffer+rdx], 0 + + mov rsi, lineBuffer + call HandleLine + +PrintResults: + mov rcx, label1 + call PrintString + mov eax, [password1] + call PrintInt + + ; newline + mov rax, SYS_WRITE + mov rdi, STDOUT + mov rsi, newline + mov rdx, 1 + syscall + + mov rcx, label2 + call PrintString + mov eax, [password2] + call PrintInt + + ; new linhe + mov rax, SYS_WRITE + mov rdi, STDOUT + mov rsi, newline + mov rdx, 1 + syscall + + mov rax, SYS_CLOSE + mov rdi, r12 + syscall + mov rax, SYS_EXIT + xor rdi, rdi + syscall + +; Handle one line: RSI -> "L123" or "R45" +HandleLine: + mov al, [rsi] + cmp al, 'L' + je .left + mov ebx, 1 ; direction = +1 for 'R' or anything else + jmp .after +.left: + mov ebx, -1 ; direction = -1 for 'L' +.after: + inc rsi ; skip 'L' or 'R' + call ParseInt ; EAX = steps + mov ecx, eax + +; Part 1 +P1_Start: + mov eax, ecx + imul eax, ebx + add eax, [angle1] + call NormalizeAngle + mov [angle1], eax + cmp eax, 0 + jne P2_Start + mov rdi, password1 + mov edx, [rdi] + inc edx + mov [rdi], edx + +; Part 2 +P2_Start: + mov rdi, password2 +.loop: + test ecx, ecx + jle P2_Exit + dec ecx + + mov eax, [angle2] + call UpdateAngleCount + mov [angle2], eax + + jmp .loop +P2_Exit: + ret + +; normalize eax to 0..99 +NormalizeAngle: + cmp eax, 0 + jl .add + cmp eax, 100 + jl .done + sub eax, 100 + jmp NormalizeAngle +.add: + add eax, 100 + jmp NormalizeAngle +.done: + ret + +; eax = angle, ebx = direction, rdi = password counter addr +UpdateAngleCount: + add eax, ebx + call NormalizeAngle + + cmp eax, 0 + jne .done + mov edx, [rdi] + inc edx + mov [rdi], edx +.done: + ret + +; parse ASCII integer into EAX +ParseInt: + xor eax, eax ; result = 0 +.parseLoop: + mov dl, [rsi] + cmp dl, '0' + jl .done + cmp dl, '9' + jg .done + + sub dl, '0' ; digit value 0..9 + movzx edx, dl + + imul eax, eax, 10 ; result *= 10 + add eax, edx ; result += digit + + inc rsi + jmp .parseLoop +.done: + ret + +PrintInt: + mov edi, numberBuffer+15 ; write digits from the end + mov byte [rdi], 0 ; terminator + dec rdi + + cmp eax, 0 + jne .convert + mov byte [rdi], '0' + jmp .finish +.convert: + ; we will repeatedly compute: + ; q = eax / 10 + ; r = eax % 10 + ; using only subtraction +.nextDigit: + mov edx, eax ; tmp = current value + mov ecx, 0 ; q = 0 + + cmp edx, 10 ; if < 0, q=0, r=edx + jb .lastDigit +.subLoop: + sub edx, 10 + inc ecx ; q++ + cmp edx, 10 + jae .subLoop ; while tmp >= 10 +.lastDigit: + ; now: + ; ecx = quotient + ; edx = remainder (0..9) + add dl, '0' + mov [rdi], dl ; store digit + dec rdi + mov eax, ecx ; eax = quotient + test eax, eax + jnz .nextDigit ; more digits to extract? + + inc rdi ; move to first digit +.finish: + mov rax, SYS_WRITE + mov rsi, rdi ; buffer pointer + mov rdi, STDOUT + mov rdx, numberBuffer+15 + sub rdx, rsi ; length + syscall + ret + +PrintString: + push rcx + push rdx + mov rdx, 0 +.count: + cmp byte [rcx+rdx], 0 + je .doneCount + inc rdx + jmp .count +.doneCount: + mov rax, SYS_WRITE + mov rdi, STDOUT + mov rsi, rcx + syscall + + pop rdx + pop rcx + ret diff --git a/aoc-2025/day2.asm b/aoc-2025/day2.asm new file mode 100644 index 0000000..dfbfb38 --- /dev/null +++ b/aoc-2025/day2.asm @@ -0,0 +1,410 @@ +; Advent of Code 2025 – Day 2 + +bits 64 +default rel + +global _start + +%define SYS_EXIT 60 +%define SYS_READ 0 +%define SYS_WRITE 1 +%define SYS_OPEN 2 +%define SYS_CLOSE 3 + +%define O_RDONLY 0 +%define STDOUT 1 + +section .data + inputPath db "input/day2.txt", 0 + newline db 10 + + label1 db "Part 1: ", 0 + label2 db "Part 2: ", 0 + +section .bss + buffer resb 4096 + lineBuffer resb 65536 + lineLen resd 1 + + sum1 resq 1 + sum2 resq 1 + + numberBuffer resb 32 ; for printing and NumberToString + +section .text + +_start: + mov rax, SYS_OPEN + mov rdi, inputPath + mov rsi, O_RDONLY + xor rdx, rdx + syscall + + mov r12, rax ; file descriptor + mov dword [lineLen], 0 + +ReadLoop: + mov rax, SYS_READ + mov rdi, r12 + mov rsi, buffer + mov rdx, 4096 + syscall + + cmp rax, 0 + jle EOF + + mov rdi, buffer + mov rbp, rax + +ScanChunk: + cmp rbp, 0 + je ReadLoop + + mov al, [rdi] + + cmp al, 13 + je SkipCR + + cmp al, 10 + je EndLine + + mov edx, [lineLen] + cmp edx, 65535 + jae SkipStore + mov [lineBuffer+rdx], al + inc edx + mov [lineLen], edx + +SkipStore: + inc rdi + dec rbp + jmp ScanChunk + +SkipCR: + inc rdi + dec rbp + jmp ScanChunk + +EndLine: + mov edx, [lineLen] + mov byte [lineBuffer+rdx], 0 + + cmp edx, 0 + je ClearLine + + push rdi + mov rsi, lineBuffer + call HandleLine + pop rdi + +ClearLine: + mov dword [lineLen], 0 + inc rdi + dec rbp + jmp ScanChunk + +EOF: + ; process final partial line if needed + mov edx, [lineLen] + cmp edx, 0 + jle PrintResults + + mov byte [lineBuffer+rdx], 0 + mov rsi, lineBuffer + call HandleLine + +PrintResults: + mov rcx, label1 + call PrintString + mov rax, [sum1] + call PrintInt64 + call Newline + + mov rcx, label2 + call PrintString + mov rax, [sum2] + call PrintInt64 + call Newline + + mov rax, SYS_CLOSE + mov rdi, r12 + syscall + + mov rax, SYS_EXIT + xor rdi, rdi + syscall + +; parse "A-B,C-D,..."l, RSI = pointer to line +; uses r13 = current ID, r14 = end of range +HandleLine: +NextRange: + ; parse start + call ParseInt64 + mov r13, rax + + cmp byte [rsi], '-' + jne DoneLine + inc rsi + + ; parse end + call ParseInt64 + mov r14, rax + +RangeLoop: + cmp r13, r14 + jg AfterRange + + ; Save RSI (line pointer) across the checks, + ; because NumberToString / CheckInvalid* use RSI + push rsi + + ; Part 1: exact AA + mov rax, r13 + call CheckInvalid1 + test rax, rax + jz .skipP1 + add qword [sum1], r13 +.skipP1: + ; Part 2: any repeating block >= 2 + mov rax, r13 + call CheckInvalid2 + test rax, rax + jz .skipP2 + add qword [sum2], r13 +.skipP2: + pop rsi ; restore line pointer + + inc r13 + jmp RangeLoop + +AfterRange: + cmp byte [rsi], ',' + jne DoneLine + inc rsi + jmp NextRange + +DoneLine: + ret + +; RSI points at decimal digits; stops on first non-digit +ParseInt64: + xor rax, rax +.parse: + mov dl, [rsi] + cmp dl, '0' + jl .done + cmp dl, '9' + jg .done + + sub dl, '0' + movzx rdx, dl + imul rax, rax, 10 + add rax, rdx + + inc rsi + jmp .parse +.done: + ret + +; NumberToString: convert RAX to decimal ASCII, MSB-first +; Output: +; RSI = pointer to first digit +; ECX = length +NumberToString: + mov rdi, numberBuffer+31 + mov byte [rdi], 0 ; terminator (for convenience) + dec rdi + + cmp rax, 0 + jne .conv + + ; handle zero + mov byte [rdi], '0' + mov rsi, rdi + mov ecx, 1 + ret + +.conv: + mov rbx, 10 +.nextDigit: + xor rdx, rdx + div rbx ; RAX = quotient, RDX = remainder + add dl, '0' + mov [rdi], dl + dec rdi + test rax, rax + jnz .nextDigit + + inc rdi ; now RDI points to first digit + mov rsi, rdi + mov rdx, numberBuffer+31 + sub rdx, rsi ; RDX = length + mov ecx, edx + ret + +; CheckInvalid1: "AA" pattern +; RAX = number +; Returns RAX = 1 if digits == A A, else 0 +CheckInvalid1: + push rbx + push rdx + + call NumberToString ; RSI=string, ECX=len + mov eax, ecx ; EAX = len + + cmp eax, 2 + jl .no1 + + test eax, 1 + jnz .no1 ; odd length => cannot be AA + + shr eax, 1 ; half = len/2 + mov r8d, eax ; half + xor r9d, r9d ; i = 0 + +.loop1: + cmp r9d, r8d + jge .yes1 + + ; s[i] + mov rdx, r9 + movzx eax, byte [rsi + rdx] + + ; s[i+half] + mov rdx, r9 + add rdx, r8 + movzx ebx, byte [rsi + rdx] + + cmp eax, ebx + jne .no1 + + inc r9d + jmp .loop1 + +.yes1: + mov rax, 1 + jmp .ret1 + +.no1: + xor rax, rax + +.ret1: + pop rdx + pop rbx + ret + +; CheckInvalid2: any repeating block >= 2 +; RAX = number +; Returns RAX = 1 if string is some A repeated k>=2 times +CheckInvalid2: + push rbx + push rdx + + call NumberToString ; RSI=string, ECX=len + mov r11d, ecx ; n = length + + cmp r11d, 2 + jb .no2 + + mov r8d, 1 ; m = 1 (candidate period) +.outer: + cmp r8d, r11d + jge .no2 + + ; if n % m != 0 => cannot tile + mov eax, r11d + xor edx, edx + div r8d ; EAX=q, EDX=r + test edx, edx + jnz .next_m + + mov r9d, r11d + sub r9d, r8d ; limit = n - m + xor r10d, r10d ; i = 0 +.inner: + cmp r10d, r9d + jge .yes2 ; all positions checked + + ; s[i] + mov rdx, r10 + movzx eax, byte [rsi + rdx] + + ; s[i+m] + mov rdx, r10 + add rdx, r8 + movzx ebx, byte [rsi + rdx] + + cmp eax, ebx + jne .next_m + + inc r10d + jmp .inner +.yes2: + mov rax, 1 + jmp .ret2 +.next_m: + inc r8d + jmp .outer +.no2: + xor rax, rax +.ret2: + pop rdx + pop rbx + ret + +Newline: + mov rax, SYS_WRITE + mov rdi, STDOUT + mov rsi, newline + mov rdx, 1 + syscall + ret + +PrintInt64: + mov rdi, numberBuffer+31 + mov byte [rdi], 0 + dec rdi + + cmp rax, 0 + jne .conv + + mov byte [rdi], '0' + jmp .done +.conv: + mov rbx, 10 +.next: + xor rdx, rdx + div rbx + add dl, '0' + mov [rdi], dl + dec rdi + test rax, rax + jnz .next + + inc rdi +.done: + mov rax, SYS_WRITE + mov rsi, rdi + mov rdi, STDOUT + mov rdx, numberBuffer+31 + sub rdx, rsi + syscall + ret + +PrintString: + push rcx + push rdx + mov rdx, 0 +.length: + cmp byte [rcx+rdx], 0 + je .submit + inc rdx + jmp .length +.submit: + mov rax, SYS_WRITE + mov rdi, STDOUT + mov rsi, rcx + syscall + pop rdx + pop rcx + ret diff --git a/aoc-2025/day3.asm b/aoc-2025/day3.asm new file mode 100644 index 0000000..e547475 --- /dev/null +++ b/aoc-2025/day3.asm @@ -0,0 +1,301 @@ +; Advent of Code 2025 - Day 3 + +bits 64 +default rel + +global _start + +%define SYS_EXIT 60 +%define SYS_READ 0 +%define SYS_WRITE 1 +%define SYS_OPEN 2 +%define SYS_CLOSE 3 + +%define O_RDONLY 0 +%define STDOUT 1 + +section .data + inputPath db "input/day3.txt", 0 + + newline db 10 + + label1 db "Part 1: ", 0 + label2 db "Part 2: ", 0 + +section .bss + buffer resb 4096 + lineBuffer resb 65536 + lineLen resd 1 + + sum1 resq 1 + sum2 resq 1 + + workDigits resb 64 ; stack for greedy subsequence + numberBuffer resb 32 ; for printing + +section .text + +_start: + mov rax, SYS_OPEN + mov rdi, inputPath + mov rsi, O_RDONLY + xor rdx, rdx + syscall + + mov r12, rax ; fd + mov dword [lineLen], 0 + +ReadLoop: + mov rax, SYS_READ + mov rdi, r12 + mov rsi, buffer + mov rdx, 4096 + syscall + + cmp rax, 0 + jle EOF + + mov rdi, buffer + mov rbp, rax + +ScanChunk: + cmp rbp, 0 + je ReadLoop + + mov al, [rdi] + + cmp al, 13 + je SkipCR + + cmp al, 10 + je EndLine + + mov edx, [lineLen] + cmp edx, 65535 + jae SkipStore + mov [lineBuffer+rdx], al + inc edx + mov [lineLen], edx + +SkipStore: + inc rdi + dec rbp + jmp ScanChunk + +SkipCR: + inc rdi + dec rbp + jmp ScanChunk + +EndLine: + mov edx, [lineLen] + mov byte [lineBuffer+edx], 0 + + cmp edx, 0 + je ClearLine + + push rdi + mov rsi, lineBuffer + call HandleLine + pop rdi + +ClearLine: + mov dword [lineLen], 0 + inc rdi + dec rbp + jmp ScanChunk + +EOF: + ; possible last partial line + mov edx, [lineLen] + cmp edx, 0 + jle PrintResults + + mov byte [lineBuffer+edx], 0 + mov rsi, lineBuffer + call HandleLine + +PrintResults: + mov rcx, label1 + call PrintString + mov rax, [sum1] + call PrintInt64 + call Newline + + mov rcx, label2 + call PrintString + mov rax, [sum2] + call PrintInt64 + call Newline + + mov rax, SYS_CLOSE + mov rdi, r12 + syscall + + mov rax, SYS_EXIT + xor rdi, rdi + syscall + +HandleLine: + mov rdi, rsi + xor ecx, ecx ; ECX = 0 +.lengthLoop: + mov al, [rdi+rcx] + cmp al, 0 + je .lengthDone + inc ecx + jmp .lengthLoop +.lengthDone: + mov r15d, ecx ; r15d = n + + ; part 1: k = 2 + mov ecx, r15d ; ECX = n + mov edi, 2 ; K = 2 + call GetMaxForK ; RAX = best 2-digit value + add qword [sum1], rax + + ; part 2: k = 12, only if n >= 12 + cmp r15d, 12 + jl .skipPart2 + + mov ecx, r15d + mov edi, 12 + call GetMaxForK ; RAX = best 12-digit value + add qword [sum2], rax + +.skipPart2: + ret + +; Greedy lexicographically largest subsequence of length K +; +; Input: +; RSI -> digits string +; ECX = n (length) +; EDI = k +; Output: +; RAX = numeric value of chosen k digits +; Clobbers: R8..R11, EAX, EDX +GetMaxForK: + ; dropsRemaining = n - k + mov eax, ecx + sub eax, edi + mov r8d, eax ; r8d = drops + + xor r9d, r9d ; r9d = stackSize + xor r10d, r10d ; r10d = i + +.loop: + cmp r10d, ecx + jge .after_input + + ; current digit in AL + mov r11, r10 + mov al, [rsi + r11] + +.pop: + cmp r9d, 0 + jle .push + cmp r8d, 0 + jle .push + + mov edx, r9d + dec edx + mov r11d, edx + mov bl, [workDigits + r11] + + cmp bl, al + jge .push + + dec r9d + dec r8d + jmp .pop +.push: + mov r11d, r9d + mov [workDigits + r11], al + inc r9d + inc r10d + jmp .loop + +.after_input: + ; trim if stackSize > k +.trim: + cmp r9d, edi + jle .convert + dec r9d + jmp .trim +.convert: + xor rax, rax + xor r11d, r11d +.convertLoop: + cmp r11d, edi + jge .done + + mov rdx, r11 + mov dl, [workDigits + rdx] + sub dl, '0' + movzx rdx, dl + + imul rax, rax, 10 + add rax, rdx + + inc r11d + jmp .convertLoop +.done: + ret + +Newline: + mov rax, SYS_WRITE + mov rdi, STDOUT + mov rsi, newline + mov rdx, 1 + syscall + ret + +PrintInt64: + mov rdi, numberBuffer+31 + mov byte [rdi], 0 + dec rdi + + cmp rax, 0 + jne .conv + + mov byte [rdi], '0' + jmp .done +.conv: + mov rbx, 10 +.next: + xor rdx, rdx + div rbx + add dl, '0' + mov [rdi], dl + dec rdi + test rax, rax + jnz .next + + inc rdi +.done: + mov rax, SYS_WRITE + mov rsi, rdi + mov rdi, STDOUT + mov rdx, numberBuffer+31 + sub rdx, rsi + syscall + ret + +PrintString: + push rcx + push rdx + mov rdx, 0 +.length: + cmp byte [rcx+rdx], 0 + je .submit + inc rdx + jmp .length +.submit: + mov rax, SYS_WRITE + mov rdi, STDOUT + mov rsi, rcx + syscall + pop rdx + pop rcx + ret diff --git a/aoc-2025/day4.asm b/aoc-2025/day4.asm new file mode 100644 index 0000000..475f2ef --- /dev/null +++ b/aoc-2025/day4.asm @@ -0,0 +1,25 @@ +bits 64 +default rel + +global _start + +%define SYS_EXIT 60 +%define SYS_WRITE 1 + +%define STDOUT 1 + +section .data + message db "Hello Day 4!", 0xA + length equ $-message + +section .text +_start: + mov rax, SYS_WRITE + mov rdi, STDOUT + mov rsi, message + mov rdx, length + syscall + + mov rax, SYS_EXIT + xor rdi, rdi + syscall diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh deleted file mode 100644 index 1344e85..0000000 --- a/docker-entrypoint.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -set -eu - -if [ "$#" -eq 0 ]; then - set -- list -fi - -target="$1" -shift - -case "$target" in - day[0-9]*) - target="run-$target" - ;; - build-day[0-9]*) - target="${target#build-}" - ;; - run-day[0-9]*) - ;; - *) - # allow raw make targets - ;; -esac - -exec make "$target" "$@" - diff --git a/input/day1.txt b/input/day1.txt deleted file mode 100644 index ecc104f..0000000 --- a/input/day1.txt +++ /dev/null @@ -1,4664 +0,0 @@ -L25 -L8 -L44 -L6 -R1 -R26 -R9 -L47 -R16 -R25 -R12 -L42 -R35 -L24 -R31 -R19 -L43 -L33 -L23 -R9 -L17 -R38 -R42 -L3 -L39 -R35 -L50 -L40 -R4 -L13 -R42 -L16 -L26 -L26 -R5 -R4 -L2 -R36 -L23 -L35 -L46 -L26 -L10 -R45 -R32 -L12 -L8 -L25 -R49 -R71 -L24 -R58 -R63 -R38 -R41 -L60 -L40 -R93 -R33 -R62 -R12 -L97 -R25 -R15 -R4 -R88 -R65 -R3 -R76 -L79 -L85 -L32 -L25 -L14 -L2 -L67 -R25 -L35 -R47 -L40 -R28 -R46 -L46 -L62 -R83 -R93 -L17 -L92 -R78 -R17 -R34 -R23 -R43 -R20 -L35 -L66 -R42 -L28 -R81 -R86 -L775 -R22 -L47 -L17 -L83 -L47 -R24 -R8 -R315 -R59 -R65 -R32 -R63 -R376 -R44 -R77 -R342 -R80 -R86 -L24 -R28 -L28 -L87 -L13 -L29 -L39 -L67 -L37 -L88 -L177 -L623 -L40 -L66 -R49 -L74 -R391 -R518 -L418 -R498 -L98 -R19 -R96 -L39 -L79 -R19 -L87 -R71 -L62 -L42 -R4 -R449 -L49 -R44 -L3 -R72 -R87 -R65 -L65 -R88 -R196 -L728 -R544 -R66 -L49 -L17 -L8 -L92 -L45 -L89 -L66 -L25 -R99 -L74 -R72 -R25 -R59 -R64 -L20 -L62 -R92 -L30 -L89 -R89 -R30 -L74 -L42 -R86 -R978 -L36 -L42 -L172 -R72 -L46 -R46 -L75 -L25 -L31 -L88 -L81 -L498 -L2 -L951 -R51 -R41 -L641 -L49 -L73 -L77 -L8 -L36 -L99 -R15 -L20 -L653 -L29 -R90 -R66 -L3 -L24 -R87 -R25 -R72 -R24 -R22 -R33 -L11 -L665 -L63 -R3 -R83 -L9 -R41 -R59 -L79 -R88 -L10 -R61 -R22 -L83 -L76 -R68 -L382 -L873 -R684 -R79 -L979 -L77 -L44 -L31 -R761 -L30 -R859 -L59 -L55 -R455 -L649 -R39 -L390 -L25 -L775 -L381 -R810 -R571 -L70 -L25 -L42 -R37 -R22 -R99 -L34 -L36 -L23 -R44 -R24 -L35 -R28 -L89 -L98 -R84 -L86 -R54 -R81 -R35 -L62 -L62 -R8 -R4 -R42 -L19 -L23 -L10 -L98 -R37 -L76 -R91 -R598 -R67 -L764 -R97 -L2 -L98 -R90 -L17 -R62 -R273 -R763 -L68 -L903 -L498 -L2 -R95 -R4 -R319 -R82 -R198 -L98 -R83 -L983 -R782 -R18 -R490 -L83 -R893 -L965 -L35 -R72 -L50 -L22 -L335 -R30 -R60 -R272 -L12 -R933 -R52 -R3 -R119 -R78 -R26 -R94 -L20 -R39 -L39 -R724 -R35 -R41 -L28 -L55 -R73 -L90 -R27 -L66 -L61 -R61 -R39 -R519 -R81 -R565 -R51 -R97 -L72 -L402 -L39 -L61 -L10 -R58 -L39 -R52 -L366 -R66 -R365 -R83 -R28 -L779 -L597 -L13 -R613 -L657 -R18 -L22 -L62 -L77 -L84 -R55 -R29 -R535 -R56 -R28 -L7 -L12 -R37 -R63 -R81 -L81 -L31 -L69 -R84 -R716 -L40 -R40 -L6 -R6 -R53 -R247 -R34 -L10 -R76 -L52 -L48 -L37 -R64 -L44 -L21 -R38 -L41 -L8 -R16 -R54 -L82 -L30 -R91 -L55 -R54 -L99 -R45 -R59 -R31 -R686 -L69 -L52 -L2 -R46 -L609 -R57 -L1 -R9 -L796 -R76 -L28 -L16 -R6 -L42 -R2 -L39 -L49 -R843 -R64 -R61 -R99 -R19 -L165 -R65 -L37 -L12 -L51 -L145 -L55 -R56 -R56 -R54 -R226 -R8 -L91 -R91 -L92 -R892 -R3 -L3 -L57 -R457 -R81 -R18 -R62 -L39 -R578 -R43 -R957 -L14 -R51 -R84 -R43 -R7 -L11 -R1 -R39 -L94 -L6 -R52 -L37 -R48 -R37 -L10 -R51 -R44 -L85 -L6 -L6 -R68 -L54 -L41 -R79 -L63 -L77 -R11 -R33 -L4 -R280 -L20 -R24 -L524 -R41 -L41 -L71 -L29 -R49 -L92 -L97 -L60 -R13 -L57 -L56 -R89 -R11 -L75 -R375 -L23 -L575 -R34 -L258 -L655 -R765 -L88 -R29 -R56 -L338 -R60 -L96 -L11 -L27 -R495 -L10 -L58 -L85 -L6 -R65 -R52 -L449 -R330 -L75 -L77 -R98 -L53 -L23 -R23 -R23 -R17 -L40 -L49 -R92 -L10 -L562 -L20 -L51 -R475 -L40 -R589 -R13 -L50 -R91 -L70 -R195 -L203 -L74 -L99 -L27 -R95 -R8 -L71 -R62 -R78 -L37 -R65 -R67 -L29 -L38 -L58 -L81 -R31 -R15 -R99 -R694 -R86 -R62 -L36 -R56 -L80 -R7 -R41 -L22 -R86 -L70 -L15 -L77 -L138 -L48 -L75 -L46 -R169 -R41 -R547 -L88 -R388 -L443 -L45 -L134 -R34 -L92 -L708 -L68 -R911 -L93 -L50 -R14 -R73 -L80 -L7 -R85 -R42 -R673 -R80 -R40 -L87 -R34 -L77 -R39 -R32 -L28 -L33 -L89 -R89 -R76 -L76 -R46 -L946 -R44 -L44 -R20 -R80 -L92 -L8 -R49 -R44 -R96 -L4 -L85 -L84 -L16 -R512 -L7 -L5 -L68 -L832 -L20 -R220 -L69 -L96 -R66 -R53 -R37 -R9 -R211 -L11 -R19 -L419 -R10 -R266 -R20 -L96 -L67 -R67 -L6 -L22 -L75 -L17 -L32 -L583 -R83 -L448 -L35 -L47 -L78 -L73 -L367 -R519 -R81 -L887 -L51 -L62 -R47 -L96 -L935 -R73 -R62 -L51 -R21 -L85 -R49 -L285 -L37 -R47 -R69 -L42 -R72 -R65 -L81 -R67 -R292 -R16 -L68 -R28 -L82 -L46 -L98 -R98 -L318 -R18 -L43 -R31 -L88 -R94 -L292 -R5 -R93 -R66 -L70 -R4 -L29 -L98 -L39 -R266 -L903 -L21 -L40 -R64 -L735 -L19 -R54 -R563 -R737 -R454 -R55 -L70 -L39 -R39 -L7 -R71 -L3 -L13 -R1 -R153 -L88 -L53 -L45 -L55 -R397 -R97 -L536 -L58 -R847 -R52 -L299 -R91 -R9 -R49 -R51 -R67 -L51 -L79 -L490 -R96 -L243 -R45 -R73 -L63 -L23 -R968 -R27 -R173 -L7 -L35 -R58 -R84 -R11 -R89 -R81 -L20 -L95 -L66 -L326 -L74 -R70 -R30 -L152 -R52 -R559 -R341 -R96 -L687 -L9 -L28 -R373 -R73 -R91 -R102 -L22 -R211 -R97 -L835 -L62 -L4 -L69 -L68 -L85 -R397 -L54 -L17 -L2 -L98 -R34 -R366 -R61 -L61 -R15 -L81 -R3 -L645 -L16 -R24 -L263 -R63 -R44 -R56 -R43 -L43 -L59 -L309 -R68 -R73 -R62 -R97 -R68 -R2 -L2 -L65 -L80 -L69 -R14 -L7 -L93 -R47 -L58 -R245 -R66 -L12 -L88 -L67 -L47 -L586 -R90 -L9 -L797 -L84 -R920 -R80 -R836 -R64 -R99 -L799 -R394 -L294 -R69 -L569 -L26 -R26 -L66 -R7 -L16 -L251 -R21 -R5 -L56 -L144 -L52 -R99 -L93 -L54 -L31 -R31 -L99 -L401 -L8 -R18 -L10 -L8 -R47 -L39 -L37 -R37 -L519 -R69 -R77 -L69 -L90 -R49 -L17 -R49 -R43 -R8 -L38 -L19 -R57 -R35 -L35 -L347 -L2 -L217 -R661 -L562 -L317 -R3 -R36 -L52 -R6 -R48 -L38 -L36 -R85 -L22 -L46 -L9 -R9 -R1 -R61 -R29 -R85 -L476 -R68 -R58 -L226 -R728 -R72 -L67 -L33 -R80 -L33 -R53 -R34 -L165 -L69 -L60 -L40 -L61 -R10 -R61 -L15 -L29 -L66 -L459 -R959 -L12 -L95 -L93 -R96 -R54 -R67 -R83 -R515 -L15 -R325 -L25 -L66 -L634 -R51 -R449 -R52 -R11 -L63 -L35 -R48 -R50 -R78 -R2 -L19 -R253 -R19 -L12 -R16 -L28 -L72 -L29 -L71 -L81 -L19 -R72 -R28 -R99 -R92 -R81 -R28 -R246 -R79 -R24 -L4 -L45 -R31 -L12 -L294 -L25 -R665 -R35 -L42 -L55 -R47 -L904 -L2 -R56 -R43 -R88 -L31 -L2 -R382 -L80 -L3 -R98 -L21 -R484 -L44 -L14 -L57 -L15 -R61 -L89 -R34 -L334 -L93 -L507 -L55 -L45 -R63 -R28 -L891 -R37 -L921 -R93 -L87 -L922 -L4 -L96 -R63 -L63 -L11 -L259 -L30 -L40 -L6 -R84 -R62 -R65 -L46 -R73 -L93 -L99 -L37 -R26 -L37 -L12 -L40 -R61 -L61 -L40 -L28 -R170 -R692 -L5 -L8 -L26 -R17 -L88 -L16 -L68 -L60 -R48 -R12 -R79 -L42 -L37 -R44 -R56 -R232 -R18 -L67 -L98 -L79 -R827 -R773 -R584 -R10 -L42 -L65 -R85 -R522 -L618 -L82 -L76 -L24 -L74 -R35 -L65 -R4 -R60 -R339 -L72 -R23 -R50 -L76 -L19 -R57 -R155 -R29 -L15 -R4 -L53 -R631 -R73 -R14 -R90 -R52 -L7 -L35 -R46 -R54 -R85 -L80 -R48 -R47 -R646 -R364 -L10 -R86 -L86 -L47 -R86 -L39 -L993 -R91 -L46 -L52 -R10 -R83 -L92 -L44 -R74 -R69 -L53 -R53 -L86 -R86 -R52 -L15 -R63 -R38 -L35 -R40 -R548 -L95 -L988 -R192 -L7 -R66 -R41 -R85 -R7 -L77 -L51 -R88 -R48 -L36 -R44 -R630 -L38 -R729 -R264 -R126 -L74 -L98 -L23 -R80 -R196 -R6 -R94 -L51 -R51 -L85 -R2 -L17 -R85 -L89 -L96 -L3 -L49 -L845 -R62 -L60 -L811 -L208 -R6 -R22 -R20 -R62 -L92 -R96 -R362 -L493 -R10 -R21 -R61 -L861 -L1 -R53 -L852 -L80 -L20 -R90 -L597 -R807 -L14 -L33 -L40 -R87 -R60 -R96 -R44 -R3 -L59 -R820 -L95 -L169 -R65 -R1 -L37 -L48 -L638 -R31 -R51 -R10 -L35 -L96 -R57 -R39 -L29 -R29 -R80 -L67 -L46 -R33 -L19 -R19 -L950 -L130 -L39 -R92 -L1 -L30 -L72 -L70 -R202 -R98 -R29 -L90 -R61 -R152 -L25 -L28 -L99 -L15 -R90 -R38 -L13 -R810 -R90 -L50 -L2 -R15 -L63 -L20 -R20 -L3 -L97 -R98 -R70 -R31 -R16 -L84 -L3 -R72 -L57 -R957 -R5 -R8 -L84 -R71 -R70 -R62 -R84 -R84 -L50 -R30 -R548 -R272 -R295 -L370 -L59 -L66 -R80 -L91 -R81 -L66 -R536 -L40 -L99 -L291 -L94 -R46 -R86 -L46 -R98 -L7 -R5 -R231 -L265 -R33 -L78 -L71 -L44 -R55 -L51 -R61 -R31 -L81 -L80 -R39 -L51 -R58 -R87 -R10 -R915 -L911 -L86 -L338 -R48 -R77 -R41 -L72 -R97 -R758 -L64 -R571 -R82 -L13 -L15 -R28 -L69 -L31 -L93 -R83 -R57 -R53 -R55 -R620 -L75 -L79 -R75 -R4 -R83 -L15 -L337 -L31 -R50 -L50 -R596 -R571 -R292 -R72 -L15 -L316 -L99 -L95 -L6 -R35 -R65 -R37 -L37 -L36 -L16 -L3 -L93 -R48 -L26 -L15 -L173 -L17 -L69 -L8 -L131 -L88 -R45 -L41 -R195 -R31 -L63 -R96 -L9 -R96 -L23 -R90 -R10 -R11 -R26 -L20 -L92 -R469 -L76 -L18 -L863 -R63 -L84 -L16 -L7 -L18 -L37 -L138 -L76 -L557 -L67 -R41 -L70 -R76 -L93 -L352 -L489 -R11 -L96 -L528 -R97 -R39 -L36 -L729 -R29 -L760 -R60 -L61 -R72 -R589 -L28 -R228 -L14 -L78 -R492 -L73 -L70 -R35 -L38 -L96 -R15 -R76 -L8 -R59 -R45 -L45 -L68 -L33 -R24 -L30 -R307 -L54 -L646 -R93 -L85 -L55 -L53 -L62 -L55 -R91 -R226 -R4 -L1 -R197 -L23 -L312 -R95 -R487 -L47 -L17 -R517 -L76 -R931 -R83 -L21 -L63 -L43 -R89 -L27 -R27 -R1 -R69 -R30 -R94 -R72 -R78 -L52 -L40 -R48 -R52 -L52 -R5 -R95 -L98 -R98 -L55 -R555 -L76 -R23 -L847 -L99 -R590 -L91 -R58 -L58 -R24 -L419 -R805 -L44 -L226 -L40 -R39 -R62 -L75 -L16 -R86 -R4 -L530 -L15 -L55 -L937 -R97 -R603 -R83 -R54 -L715 -R15 -R75 -R82 -L57 -L633 -L88 -L504 -R25 -R184 -R617 -R350 -L92 -R241 -L28 -L47 -R55 -L80 -L17 -R17 -L385 -R35 -R66 -L216 -R191 -L79 -R53 -L15 -R72 -R207 -R25 -L77 -L83 -R49 -L95 -L468 -R90 -L70 -L201 -L199 -R22 -L22 -R58 -L30 -L7 -L21 -R657 -R774 -L56 -L275 -L13 -R613 -L29 -R29 -L3 -R36 -R46 -L79 -R126 -L70 -R44 -L64 -R73 -L809 -R860 -L74 -R46 -R68 -L82 -R82 -L3 -L657 -L40 -L60 -R60 -R5 -L5 -L72 -R35 -R74 -R63 -L276 -R76 -R33 -R945 -L78 -L38 -R89 -L51 -L45 -L195 -R476 -L98 -R770 -L8 -R93 -L93 -L937 -R52 -R96 -L11 -R29 -L29 -L79 -R285 -R94 -R67 -R33 -R60 -R70 -R19 -R51 -R816 -L16 -L896 -L89 -L15 -R43 -R57 -L6 -L94 -L99 -L25 -L5 -R29 -L81 -R97 -L16 -L93 -L43 -R7 -R329 -R70 -R82 -L52 -L37 -L81 -L82 -R56 -L56 -R67 -L24 -R57 -L36 -L95 -R31 -R24 -L384 -R24 -R27 -L88 -L248 -L55 -L810 -L34 -R85 -R25 -R99 -R780 -R55 -R80 -L5 -R25 -R47 -R337 -L58 -L99 -R53 -R20 -R85 -R31 -L60 -R3 -R74 -L463 -R30 -R13 -L13 -L73 -L27 -L58 -R48 -L872 -L118 -R99 -R1 -L75 -R95 -L93 -L5 -R981 -L3 -R5 -L60 -L85 -R16 -L84 -R948 -R60 -L73 -R84 -R89 -L33 -L491 -L23 -R71 -L405 -L9 -R37 -L29 -R53 -R29 -L92 -R392 -L48 -R48 -L30 -R16 -L49 -L37 -L30 -R50 -R71 -R9 -R64 -R36 -L39 -R23 -R35 -R5 -L12 -L922 -R18 -L37 -R29 -R51 -L24 -L42 -L85 -R95 -R22 -R807 -R185 -L19 -R910 -R69 -L476 -R91 -L40 -L44 -R97 -R96 -L386 -L7 -L21 -L79 -R30 -L30 -R36 -L17 -L15 -L41 -R93 -L256 -L705 -R76 -L43 -L89 -R35 -L47 -L27 -L40 -L52 -L80 -L26 -R856 -L265 -R7 -R95 -R38 -L71 -L62 -R98 -R65 -R19 -L939 -R52 -L46 -R89 -L38 -L29 -R629 -R92 -L192 -L43 -R90 -L53 -L32 -L62 -L83 -R70 -R84 -R129 -R315 -L61 -R643 -R59 -R47 -R57 -L80 -R86 -L998 -L44 -L5 -R64 -R217 -L50 -L35 -R11 -R344 -L77 -R75 -R816 -L32 -R648 -L10 -R17 -R29 -R80 -L18 -L92 -R880 -R896 -L52 -L111 -R388 -L7 -L28 -R65 -L86 -R67 -R65 -R27 -L94 -R75 -R12 -L66 -L69 -R57 -L54 -L11 -L21 -L39 -R85 -L30 -L27 -R25 -L16 -L15 -L22 -L33 -L27 -R26 -L77 -L4 -L285 -L29 -R24 -R34 -L26 -L903 -L64 -L36 -L85 -R141 -R27 -R40 -L23 -R74 -R5 -L3 -L76 -L15 -L41 -R30 -R26 -L567 -L733 -L761 -R98 -L37 -R162 -L75 -R78 -R35 -R57 -R51 -R92 -R79 -L79 -R4 -L15 -L89 -L474 -R74 -L9 -R82 -L42 -R27 -L58 -R63 -R37 -L73 -L42 -R115 -L49 -R49 -R88 -R12 -R89 -L89 -L38 -L49 -R87 -R602 -L902 -L77 -L43 -R20 -R333 -R94 -L627 -L23 -L540 -R91 -L50 -L12 -L9 -L25 -L62 -R30 -R132 -R13 -R39 -R816 -R57 -L51 -R31 -R669 -R94 -L37 -R29 -R90 -L94 -L12 -L81 -R405 -L68 -R2 -R66 -L57 -R57 -L12 -L71 -R41 -R42 -R67 -R16 -L35 -R71 -L939 -L6 -L36 -R662 -L82 -L78 -L29 -R743 -L36 -L18 -L261 -R881 -R80 -L16 -R416 -L22 -R22 -R90 -R92 -R18 -R59 -L59 -R487 -L87 -L69 -R35 -L25 -L62 -R21 -L63 -R63 -R523 -R77 -L2 -L98 -L661 -R61 -L42 -L58 -L50 -R45 -L25 -R84 -L654 -L22 -L36 -R30 -R288 -L28 -L69 -R37 -L55 -R55 -R317 -R21 -R36 -R26 -R24 -R94 -R84 -L79 -R77 -L496 -L52 -R73 -L23 -R21 -L323 -L72 -R72 -L12 -R36 -R533 -L25 -L10 -L706 -L16 -R7 -L73 -R66 -L26 -R37 -R89 -L54 -R79 -R475 -L547 -L53 -L60 -R70 -R935 -L9 -R462 -R56 -L24 -R56 -L586 -R63 -L36 -R39 -R68 -L40 -L94 -L642 -L258 -R70 -L95 -R41 -R84 -R13 -L562 -R49 -L96 -L20 -R30 -R68 -L309 -R65 -R61 -R1 -R73 -L10 -L58 -R3 -R92 -R565 -L24 -R59 -L29 -R29 -R61 -R33 -L94 -R146 -L323 -L24 -L99 -L920 -R20 -L50 -L50 -R19 -R32 -L268 -R550 -L71 -R38 -R3 -L3 -R59 -L59 -R44 -L24 -L94 -L14 -R12 -L14 -L62 -R52 -R13 -R87 -L94 -L704 -R25 -L29 -L88 -R44 -R50 -L4 -L271 -L507 -R272 -L61 -L33 -R27 -L212 -L815 -R80 -L15 -L127 -R98 -L16 -L440 -L80 -L23 -R63 -R60 -R591 -R9 -L91 -R859 -L68 -R52 -R728 -L43 -L47 -R29 -R981 -L704 -R25 -R179 -L73 -R73 -R58 -L50 -L8 -R139 -L39 -R65 -L95 -L43 -L60 -R95 -L61 -R865 -L158 -L51 -R93 -L235 -R84 -R31 -R70 -L21 -L756 -R77 -R3 -R45 -R52 -R77 -R56 -R101 -R73 -R4 -R89 -R50 -R50 -L35 -R64 -R9 -L12 -L77 -R205 -L54 -L47 -L853 -R70 -L42 -L9 -L19 -R26 -L96 -R24 -R94 -R252 -L39 -L20 -L73 -L68 -R51 -R84 -R79 -R86 -R58 -L58 -L74 -L22 -R67 -L95 -L26 -R694 -R18 -R180 -L142 -L119 -R19 -R153 -R47 -R73 -L10 -R76 -L52 -L575 -R88 -L475 -R58 -L3 -R769 -R82 -R27 -R56 -R70 -R87 -L32 -R68 -R93 -L81 -L47 -L72 -R84 -R70 -L65 -R11 -R79 -L79 -L87 -L10 -L8 -L795 -L21 -L221 -L58 -R48 -R950 -R2 -R391 -L88 -L88 -L915 -R54 -R94 -R61 -L70 -R61 -R47 -L447 -R572 -R28 -R410 -L24 -L72 -L41 -L259 -L66 -R34 -L39 -L291 -R24 -R24 -L711 -L5 -L80 -R27 -L31 -L69 -L31 -L43 -R802 -L322 -L37 -L728 -L52 -R80 -L703 -R529 -R588 -L14 -L64 -R753 -L61 -R47 -R4 -L489 -L90 -L80 -L90 -L52 -L78 -L424 -L76 -R86 -R23 -L71 -L38 -R508 -L508 -R96 -R234 -R67 -R69 -L92 -R124 -L46 -R47 -R4 -R97 -R64 -L64 -R3 -L38 -L4 -L79 -R18 -L8 -L82 -R90 -L32 -L13 -R245 -L12 -L88 -R92 -L748 -L44 -L74 -R6 -R68 -R14 -L8 -R963 -L769 -R217 -L17 -L58 -L42 -L94 -L6 -L94 -R94 -L58 -L542 -R41 -R585 -R36 -R2 -R536 -L13 -R88 -L67 -L13 -L90 -R95 -R57 -R621 -R90 -R23 -R88 -R51 -R70 -L25 -R913 -L88 -L22 -L578 -R65 -L865 -L965 -L23 -R97 -L29 -R52 -R68 -L63 -L639 -L779 -R27 -R62 -R803 -R52 -R37 -R27 -R973 -L56 -R56 -L17 -R96 -L408 -R31 -L63 -R55 -R6 -R29 -R9 -R4 -R11 -R47 -R28 -R84 -R88 -R31 -L54 -R47 -R27 -L251 -R30 -R170 -R83 -R417 -L10 -L90 -L976 -R55 -R221 -R32 -R74 -L42 -R36 -L417 -R704 -R52 -R628 -L730 -R87 -L22 -L2 -L16 -R40 -R23 -R34 -L74 -L45 -L47 -R38 -R20 -L73 -R37 -L860 -L77 -L50 -L220 -L31 -R43 -R58 -L40 -L60 -R33 -L33 -L70 -R38 -L60 -R78 -R53 -L39 -L5 -L95 -L55 -L28 -R84 -L1 -R47 -R53 -L523 -R13 -L90 -R3 -L803 -L3 -R26 -R77 -L30 -R56 -L69 -L157 -R10 -R11 -L175 -R54 -R375 -R25 -L26 -R40 -R441 -R45 -R76 -R60 -R8 -R76 -L162 -R42 -L23 -R89 -R1 -L31 -L36 -R53 -L53 -L72 -L17 -L51 -R40 -R27 -R46 -R627 -L279 -L12 -R55 -R17 -L89 -R9 -L1 -R662 -L18 -L88 -L56 -L940 -R224 -L9 -L74 -R99 -L114 -R67 -R47 -R18 -R74 -R31 -L23 -R21 -L43 -R45 -R82 -R95 -L444 -R44 -R275 -L618 -L10 -L79 -R79 -L847 -R88 -L88 -L13 -R82 -R31 -L24 -R41 -R80 -R44 -L94 -L62 -L10 -L7 -R38 -L91 -L44 -R29 -L64 -L336 -L436 -L30 -L73 -R561 -L322 -R45 -R11 -L65 -L91 -R691 -R809 -R30 -R470 -R64 -L20 -R461 -R95 -R13 -L2 -L95 -R841 -R33 -L724 -R98 -L14 -L335 -L15 -R6 -R94 -L649 -L352 -R8 -R56 -R27 -L55 -R77 -R1 -R58 -L24 -L41 -L757 -R51 -L49 -R773 -R14 -R78 -L16 -R46 -L72 -R17 -L91 -L61 -R76 -R85 -L45 -R94 -R51 -L75 -L25 -R69 -R31 -R34 -L3 -R69 -L85 -R85 -L977 -R37 -R840 -R123 -R745 -L68 -R28 -R72 -L859 -L15 -L26 -R61 -L17 -R16 -R78 -L79 -L11 -L86 -L562 -R799 -L94 -L40 -L65 -R21 -L21 -L47 -R47 -R36 -L27 -L9 -R51 -L51 -L43 -R57 -L14 -R62 -R38 -R90 -L90 -R89 -R4 -L93 -R23 -R20 -R1 -R56 -R15 -L365 -R50 -L88 -R13 -L98 -R54 -L81 -L552 -L48 -R60 -R69 -R22 -R36 -L87 -R71 -L71 -R98 -R93 -L72 -L97 -R47 -R331 -L46 -R13 -R33 -R40 -R427 -L28 -L91 -R52 -R16 -L816 -L67 -R4 -L37 -L31 -R31 -L10 -L90 -L60 -R154 -R68 -L96 -R96 -L62 -R91 -R9 -L49 -L95 -R78 -L653 -R22 -R72 -R25 -L53 -L13 -R14 -L82 -R634 -L86 -L514 -L42 -R645 -R39 -L84 -L58 -L10 -L90 -R85 -L908 -L77 -L47 -R47 -L99 -L270 -L31 -R79 -L5 -R46 -L81 -L59 -R4 -R529 -R87 -L48 -R85 -L20 -R83 -L56 -L77 -R61 -L28 -L85 -L88 -L27 -R36 -R1 -R63 -R54 -R46 -R49 -L34 -R85 -L79 -R58 -R28 -R27 -L28 -L10 -R19 -L59 -R47 -L124 -R80 -L20 -R90 -R17 -R8 -L50 -R755 -L222 -R22 -R768 -L27 -L375 -L4 -R30 -R75 -L26 -L61 -L17 -R72 -L94 -R93 -L15 -L878 -L45 -L43 -R32 -R76 -R39 -R41 -R60 -R58 -R656 -L71 -L3 -L145 -L655 -R55 -R68 -R14 -L21 -L48 -R232 -L56 -R56 -L45 -R2 -R50 -R17 -L1 -L9 -L14 -R4 -R19 -L57 -L66 -L15 -R29 -R698 -L12 -R77 -L87 -R10 -L252 -L9 -R79 -L14 -R496 -R2 -R98 -L6 -L32 -R85 -R53 -L1 -L230 -L69 -L998 -L2 -L1 -L99 -R13 -L122 -R9 -L19 -R84 -L65 -R35 -R65 -L37 -R37 -L9 -L23 -L68 -L51 -R4 -R10 -R928 -R868 -R6 -L50 -R14 -R87 -L916 -R53 -R97 -R10 -R40 -R310 -R13 -R18 -L41 -R33 -L233 -R53 -L798 -R99 -L454 -L96 -L84 -R80 -L98 -L2 -R65 -L37 -R72 -R68 -R32 -L99 -L1 -L21 -R21 -L93 -L7 -R27 -R58 -R96 -L81 -L578 -L222 -R57 -L92 -R35 -L63 -R24 -L61 -L55 -R85 -L4 -L6 -R11 -L75 -L56 -R13 -L715 -L92 -R905 -L82 -R89 -R32 -R50 -L51 -L577 -R269 -R857 -R12 -L12 -L33 -L26 -L843 -L81 -L660 -R45 -L86 -R33 -L87 -L69 -R40 -R616 -R6 -L9 -R16 -L60 -R90 -L36 -L54 -R22 -R111 -R67 -L56 -L44 -R48 -L65 -L92 -R459 -L50 -L45 -L55 -R70 -L57 -L38 -R43 -R82 -R39 -R61 -L58 -L703 -R40 -L84 -R876 -L80 -R922 -R28 -L912 -L29 -R3 -R5 -R992 -R54 -L59 -R56 -R49 -R57 -L87 -L64 -L888 -R43 -R28 -L41 -L648 -R14 -L14 -R10 -L11 -L48 -L51 -L26 -R95 -L78 -L18 -L652 -R29 -R13 -L63 -L53 -R53 -L77 -L39 -R16 -L63 -L22 -R26 -R59 -R305 -R95 -R41 -R15 -R444 -L72 -R60 -R212 -R90 -L890 -L20 -R46 -R74 -R875 -L35 -L73 -L552 -L15 -L12 -R9 -R71 -L10 -R49 -R561 -L43 -L25 -L37 -R15 -L36 -R58 -R81 -R69 -R5 -R145 -L27 -L88 -L3 -L82 -L47 -L795 -R18 -L7 -R31 -R61 -R64 -L26 -R28 -L27 -L179 -L85 -L95 -L381 -L983 -R86 -R39 -R496 -R2 -R33 -R63 -L96 -L64 -L4 -R92 -R57 -L81 -L93 -R4 -L91 -R64 -R39 -R98 -L46 -L91 -L52 -R91 -L423 -L68 -L932 -L65 -R629 -L502 -L36 -R82 -L8 -L89 -R37 -R533 -R19 -R31 -L431 -L60 -L440 -L56 -R64 -R2 -R10 -R38 -L52 -L906 -L70 -L93 -R463 -L22 -R83 -L69 -L92 -R75 -L26 -L149 -L4 -R4 -R67 -R78 -L870 -R8 -L73 -R52 -R38 -L47 -R47 -L9 -L791 -R211 -L99 -L90 -R58 -R648 -L44 -R66 -L928 -R90 -R88 -L21 -L79 -R65 -R36 -L38 -R637 -L31 -L15 -L69 -L85 -R93 -R68 -R39 -R19 -L6 -L13 -R36 -L36 -R1 -R199 -R66 -L66 -L841 -R41 -R33 -R22 -R45 -R6 -L6 -L20 -L39 -L41 -R15 -R85 -R22 -L9 -R83 -L79 -L59 -R43 -L33 -R32 -R80 -R644 -L335 -L22 -R510 -R614 -R9 -L92 -L108 -R1 -L1 -L438 -R81 -L43 -L44 -L756 -R22 -L753 -R15 -R845 -R71 -L6 -R66 -L42 -R82 -L85 -R83 -R33 -L31 -R81 -R39 -R35 -L47 -R92 -L970 -L523 -R22 -R580 -L9 -R5 -L39 -L66 -L52 -R94 -L90 -R48 -R981 -L81 -R942 -R244 -L56 -R52 -L182 -L25 -R25 -R375 -L75 -L85 -R65 -L65 -R65 -L34 -L53 -R37 -R70 -L479 -R468 -R529 -L134 -R116 -R661 -R634 -R134 -R307 -L15 -L21 -L31 -R531 -L89 -R84 -L695 -L70 -R63 -R36 -L49 -L80 -R57 -R96 -R18 -R29 -R14 -R86 -R2 -L54 -L71 -R522 -R20 -L365 -R28 -R1 -R17 -R42 -R58 -R52 -L828 -R70 -R390 -R16 -R41 -R759 -L73 -L68 -R81 -R51 -L16 -L975 -R41 -L82 -L69 -L90 -L757 -L543 -R502 -R80 -L82 -R3 -L53 -R50 -L978 -R78 -R54 -L254 -R25 -R75 -L21 -R68 -L49 -R2 -R82 -R17 -L9 -L283 -R393 -L78 -L22 -L15 -L985 -R5 -R197 -L3 -R1 -L3 -R91 -R76 -R95 -L63 -R72 -R27 -L46 -R51 -R65 -L67 -R902 -R99 -L40 -L516 -L43 -L78 -L41 -R19 -L3 -L321 -L8 -L30 -R510 -L26 -L75 -R59 -R43 -R51 -R84 -R26 -R23 -L32 -R88 -R11 -L36 -L64 -L89 -R83 -R96 -L90 -L3 -R69 -L66 -R42 -R58 -R65 -R7 -L10 -R38 -R94 -R5 -R1 -R99 -R232 -L33 -L98 -L5 -R5 -L88 -R20 -R5 -R63 -L615 -L806 -L32 -R53 -L36 -R36 -L36 -L64 -R44 -L90 -L45 -R91 -L29 -R98 -R4 -L73 -R3 -L54 -L63 -R14 -L70 -L430 -R71 -R63 -L34 -R47 -L647 -R25 -L8 -R86 -L190 -L13 -L54 -R54 -L6 -L78 -R33 -L49 -L85 -R62 -L77 -R495 -R5 -R30 -L71 -L959 -L85 -L12 -L3 -R19 -L350 -L97 -R89 -L441 -R954 -L72 -R66 -R35 -L3 -L4 -L46 -R50 -R78 -R46 -L87 -L34 -L77 -R46 -L21 -L964 -R109 -L7 -L35 -L92 -R98 -R56 -R89 -R29 -L28 -R35 -R659 -L32 -L510 -R42 -L47 -R47 -R872 -L95 -R80 -L8 -L39 -R90 -L5 -L95 -L303 -L97 -R25 -R75 -R810 -L43 -R33 -R80 -L15 -R79 -L49 -L63 -L64 -R679 -L18 -L86 -R735 -R22 -L4 -L922 -L74 -L80 -R80 -R19 -L59 -R40 -R41 -R59 -L39 -R539 -L59 -R959 -R31 -R73 -L76 -R272 -L78 -L99 -L649 -R55 -L29 -L45 -R45 -L58 -L42 -L427 -L46 -L98 -R876 -L405 -L69 -L31 -L51 -L49 -R88 -R43 -R81 -R75 -R849 -R75 -R89 -L514 -R14 -L1 -L489 -L21 -L89 -R53 -L44 -L9 -L95 -R803 -R92 -L8 -R158 -L15 -R34 -L69 -L38 -R38 -R60 -R712 -L126 -L14 -L13 -L11 -R49 -L66 -L14 -R23 -L94 -R7 -L8 -R95 -L661 -R561 -L20 -L180 -L9 -R52 -R57 -R43 -L43 -R91 -L91 -R31 -L631 -L18 -R18 -R79 -R21 -R35 -L9 -L26 -L1 -R1 -L924 -L976 -L72 -L22 -L905 -R813 -R129 -L45 -L20 -L82 -R64 -R97 -L47 -L10 -L92 -L8 -L243 -L757 -L19 -L81 -R98 -L98 -R98 -L275 -L23 -L25 -L921 -L66 -R12 -L5 -R205 -R91 -L10 -R36 -R34 -R81 -R68 -L35 -R44 -R60 -R18 -L93 -L94 -R71 -R1 -L72 -L18 -L82 -L38 -R34 -R4 -R69 -L16 -R650 -R88 -L291 -L41 -L10 -R66 -L44 -R75 -R93 -R82 -L21 -R51 -R49 -L849 -R92 -R57 -R69 -R62 -R86 -L19 -L598 -L33 -R91 -L92 -R534 -R12 -L96 -L35 -R19 -R57 -R643 -R32 -R69 -L85 -L17 -R45 -L72 -R827 -R98 -R935 -R68 -R97 -L21 -R79 -R37 -L92 -L18 -R43 -L21 -L76 -R72 -L357 -R62 -L5 -L33 -L74 -L93 -L11 -R54 -L43 -L5 -R41 -R32 -L68 -L584 -L16 -R8 -L17 -R40 -L31 -R82 -R18 -L12 -R60 -R91 -R22 -R77 -R33 -L71 -R9 -R91 -L87 -L98 -R85 -R399 -L57 -L24 -R82 -L405 -L68 -L943 -L76 -L65 -L643 -R15 -L215 -L597 -R7 -L10 -R94 -R26 -L64 -R44 -L52 -R23 -R29 -R5 -R577 -R680 -R36 -L98 -R662 -R92 -L98 -L76 -L55 -R41 -L59 -L7 -L74 -R74 -L53 -L84 -L12 -L851 -L618 -L71 -L90 -R79 -R410 -L10 -L90 -L10 -L325 -L50 -L39 -R77 -L565 -R402 -L15 -R96 -R29 -L23 -R794 -R872 -L32 -L71 -R89 -R54 -L84 -R4 -R87 -R804 -R96 -L429 -L81 -L53 -L339 -R2 -R62 -R92 -R24 -R97 -L75 -L443 -L57 -L10 -L104 -L16 -R30 -L21 -R921 -L35 -R62 -R43 -R748 -R82 -R13 -R87 -L828 -L14 -L89 -R567 -L36 -R15 -L15 -R99 -L61 -R74 -R56 -R68 -R51 -R82 -L757 -R88 -L97 -L71 -L432 -L62 -L88 -L76 -L74 -R47 -R38 -L85 -L690 -R90 -L98 -L7 -R5 -L792 -R75 -L83 -L60 -L40 -R89 -R45 -R66 -R88 -R90 -L57 -R1 -R67 -L89 -L66 -L939 -R605 -L13 -L87 -L36 -L87 -R905 -R81 -R62 -R75 -L316 -L54 -R80 -L113 -L195 -L202 -R74 -L47 -L27 -R31 -R48 -R79 -R487 -R84 -L29 -L8 -R8 -R76 -L76 -L96 -R96 -L44 -L8 -L48 -R869 -L469 -R44 -R56 -L30 -R78 -L948 -R346 -R29 -L75 -L53 -L38 -R568 -R23 -L39 -L76 -L72 -R225 -R23 -R129 -L25 -L4 -L61 -L3 -R70 -R76 -L78 -R35 -L11 -R8 -L91 -R52 -R565 -R77 -L11 -R23 -R723 -R17 -R7 -R41 -R35 -R265 -R95 -R80 -L75 -R52 -R24 -R73 -L49 -R19 -R950 -L169 -L9 -R85 -L76 -R792 -L82 -L518 -L62 -R63 -L11 -L95 -L540 -R20 -R39 -R94 -L48 -L18 -L34 -L1 -L54 -R17 -R938 -R15 -R75 -L84 -R94 -L72 -L228 -L77 -L523 -L28 -R25 -R3 -R3 -R48 -L51 -L739 -L27 -L75 -L10 -L36 -L38 -L74 -L73 -R35 -L520 -L18 -L25 -L9 -R13 -L998 -R603 -R91 -R986 -L22 -L54 -L510 -L2 -R2 -R47 -R206 -R951 -R93 -R3 -R921 -R18 -L5 -R71 -R889 -L9 -L57 -L11 -L874 -R81 -R15 -L639 -R825 -R407 -R16 -L48 -L31 -R32 -L5 -R933 -R64 -L693 -R52 -R11 -L9 -L54 -L21 -L14 -R30 -R31 -R474 -R78 -L13 -L686 -L39 -R36 -L76 -L37 -R26 -L7 -R918 -R79 -R37 -L16 -L25 -L22 -L624 -R10 -R781 -R58 -R14 -R94 -L4 -L320 -L627 -L363 -L88 -L50 -R27 -L6 -R45 -L76 -L6 -R71 -R11 -R84 -L91 -L93 -R8 -R87 -L95 -R684 -L91 -R11 -R96 -L7 -L521 -R28 -R327 -R340 -L63 -R25 -R793 -R15 -L987 -L28 -R97 -R31 -L2 -L564 -R112 -L934 -L62 -L78 -R61 -L83 -L33 -L45 -L822 -R94 -R6 -L93 -R89 -R77 -R27 -L16 -L22 -R38 -R526 -R748 -R8 -R718 -R703 -L48 -R35 -L90 -L99 -R8 -R34 -R557 -R2 -L7 -R75 -L90 -L80 -L74 -L521 -L5 -L590 -L34 -R80 -L99 -L73 -R16 -L95 -L70 -L79 -L93 -L16 -L9 -L38 -L89 -R40 -L21 -R85 -L87 -R72 -R5 -L5 -L7 -R25 -L3 -L15 -R86 -L791 -L53 -R89 -L7 -R43 -R33 -L32 -R47 -R85 -L19 -L81 -L259 -R86 -L18 -L9 -L5 -R5 -R53 -R58 -R346 -L57 -L26 -L203 -L71 -R51 -R359 -L86 -L97 -L29 -L32 -L82 -R816 -L59 -L4 -L37 -R97 -L18 -L779 -R27 -L27 -L26 -L1 -R27 -L643 -L27 -R45 -R25 -R105 -R37 -R67 -R39 -L335 -R32 -L47 -R244 -R638 -L32 -L13 -L9 -L52 -R98 -R74 -L116 -L30 -R55 -L55 -R25 -L44 -L65 -L16 -L867 -L58 -R62 -L324 -L48 -L27 -L20 -L18 -L35 -R10 -R61 -L11 -R75 -L82 -L18 -L674 -R24 -L7 -L84 -R10 -R431 -R42 -R51 -L99 -L72 -R30 -R142 -R6 -L76 -R76 -R40 -L97 -R49 -L526 -L69 -L97 -R70 -L827 -R8 -L11 -L40 -L841 -L86 -R47 -L71 -R88 -L37 -L58 -L280 -R58 -L3 -L17 -L54 -R54 -L24 -R24 -R44 -L74 -L70 -L69 -R69 -L87 -L13 -L20 -L18 -L47 -R56 -L28 -L817 -L90 -R64 -R157 -R86 -R68 -L85 -R2 -R15 -L84 -L29 -L30 -L160 -L742 -R497 -L995 -L41 -R97 -L73 -L59 -R73 -L597 -L17 -L36 -R97 -R56 -R42 -R58 -L818 -L82 -R902 -L202 -R96 -L84 -R57 -R19 -R12 -L939 -R585 -R54 -L14 -L735 -L446 -L5 -R58 -L56 -R868 -R522 -L72 -R80 -L64 -L101 -L4 -L51 -R375 -L71 -L68 -L56 -L51 -R885 -R35 -L29 -R79 -R721 -R70 -R430 -L16 -L84 -R28 -L65 -R21 -L84 -R31 -L15 -L28 -L346 -R258 -R95 -L44 -L9 -R58 -L674 -R80 -R2 -L51 -R25 -L82 -L43 -R7 -R58 -L65 -R71 -R72 -R3 -L8 -L95 -R582 -R18 -L20 -R53 -L528 -L705 -L76 -L24 -L87 -R87 -L69 -L58 -L27 -R54 -L77 -R77 -R60 -L60 -L46 -L19 -R72 -L68 -L39 -L17 -R29 -L12 -R46 -L17 -L29 -R90 -R99 -L95 -L94 -L26 -L44 -L30 -R97 -R3 -L27 -L60 -R87 -R62 -R38 -R32 -L70 -L62 -R96 -R14 -R41 -L36 -L15 -L71 -R71 -L53 -R53 -L30 -L53 -R83 -R11 -L48 -R50 -R28 -L16 -L7 -R37 -L28 -R14 -R14 -R50 -R42 -R41 -R2 -L10 -R26 -R26 -R49 -L47 -R30 -R24 -R14 -R8 -R30 -R15 -R47 -R9 -L27 -L32 -R17 -R46 -L34 -R40 -R43 -R25 -L3 -L17 -L4 -L3 -R15 -L50 -R9 -L5 -R40 -L7 -R40 -L15 -R20 -R45 -R39 diff --git a/input/day2.txt b/input/day2.txt deleted file mode 100644 index 7b308fc..0000000 --- a/input/day2.txt +++ /dev/null @@ -1 +0,0 @@ -655-1102,2949-4331,885300-1098691,1867-2844,20-43,4382100-4484893,781681037-781860439,647601-734894,2-16,180-238,195135887-195258082,47-64,4392-6414,6470-10044,345-600,5353503564-5353567532,124142-198665,1151882036-1151931750,6666551471-6666743820,207368-302426,5457772-5654349,72969293-73018196,71-109,46428150-46507525,15955-26536,65620-107801,1255-1813,427058-455196,333968-391876,482446-514820,45504-61820,36235767-36468253,23249929-23312800,5210718-5346163,648632326-648673051,116-173,752508-837824 diff --git a/input/day3.txt b/input/day3.txt deleted file mode 100644 index b6da1ed..0000000 --- a/input/day3.txt +++ /dev/null @@ -1,200 +0,0 @@ -3422445336235842747226623979451284644788593556234563483755458563477877585692774519487775553824591745 -3234117833333631332251333312512222483622152242222222313222232243821345653466665422223223324159332325 -2121223312222142223122171282212523212421242122322114323122252323122222221343332422332222232222121121 -6352516566252422324455242622521344385122222532225833555211322537334121323212843552221253122494255525 -5433543922462623152342535434224554523255452441522624356456455522334475255431384723253443253397134484 -6222225322434224224224522733346425235312323224532425222254324532574453524227332235232333323584222355 -2215326123622464834245431284362122433562272483412556554121463833344414532134245435234541224326151244 -2134252233223323313243333233243213331333523545325333432523533422333232583323233413323333831435352122 -6632656225825528262136284254222972154232223424388533227222252285824386592723585548258637625266323232 -2512535522643554342316135343383532525432233334624442424423223223244342145133232423223333143213422242 -2653363531231665323454246756565726374776132449546455625636691533964246752243764482746856725244924526 -3332132373432434333232231325232321152212333233122341233232423133333313231333321223332232532322132232 -2574538524744674353325562423333333324462372826343323724443346633334447212724525433645574722149446323 -2644323222353233223332231223845552313833341533242322223323433222434228232332315383422822348133422323 -4222422221123221222211223222221243422231222212153351321414214132224544532122223222312242212223423225 -5535491646363447914486747775453165443865376335642354345374634666958346446862974643664335565255548345 -6477764646344647639684769536842745445354866542556689652634554354375427644256565649474444635437244466 -2268422574942321223487292762622527222621624724217162212234278221215228626656427178612354324222922235 -2225432555335221214225434242253252521342116544431124222412222235124126342551262432433342533223346232 -5784759778776787685686958667777667577977878676687686787746496975555797598978767439578768767777687564 -5756247483657585656575544577365949974846699547768867455647918439344455575583536445757456368545545846 -2335362643322565312214313722224356342555444362222222444413531322341322323242425254245224211535422514 -4722255111323222324331232142552453155522324541543421132232224451511363224342121158133154222542226165 -5356255552346245262523223652438323522452563353512452552233333434453531232334134432342261454253243323 -8787577983365533427776563223987489544757638673557697893562346736537568463374832236923465684336677777 -5254311315253414233342433236133424324233422222524673251232334415513243234352742221232142522441461236 -3565246341363123433434644654332523333226344424353573343235226732465323353138344332535345334344462363 -5243446534443464342422732258342424453532365414424244446244635421554543345124443424233244242529444643 -2233134213422283421312222125114323425243133224232243632123362221332343222313231122412244222262332234 -8538333874633351312542363376242343833123353452233575232143375123243333254452215548332235238313355133 -5875444434253255446742434458432326452232694534333372444221534664433462623432323424362333113365219254 -4323353344355453353335591344452544532534353411333333335227458454253354453535332333425225534423193438 -5554645643624573542545552754954349447565454649479734459453453375374647853874234557465475595526443554 -4531366635135445434412123636542663221266514526436612366154141253154513115446365646324526345215231789 -2622739212323173442342455234342373342335613561522433538253242113453253334222653523374141322223355344 -2333212532234232232339443733239233433333133333331342243925373122236371311393313533333333344339232245 -6545655353156365245863556456376574577444432444655564453345344562226665267434445455235495624262522646 -2323625534228554432622433245336336243655187665525224625153342624613213463254254354345455422225543252 -4434544446455644443543445473445443446424464424444434343464444432443344444544456344443444344543444445 -1322122227222133122522122232213352221123222242332222322222122229221432222222322222212132443413212122 -3373471711653772464211312555617361261431213346146262311556714626157722122215177771535464337744262389 -5273447414643743321423883633242254242424224225374632442213744242345343234422423536343744444435553236 -2433542342431122452542222235642136457153135215225222352311134632452223226223333462261213232151133256 -8845433356344854255376424732725338333565636723637544862294866645868378231133883323282635758636334257 -2343344243523333333432513653324343323212224433733333463333365368534533536322523237432723635235372221 -7876445656865475748763677736667927575666464664357546668754667679796466864756785878354877674456685344 -4322721152122522232322223324253221222215332222222312222512241232112223225328322232222222222422324214 -1223242225424457325944461411552253225375242223323737125232124354251415244225334534342365134555248544 -4353553265532424342434353343646244635343454543353263426458332442455564235255334446383825331622553244 -3342355232241413323495363342313342334312532222235361123335434432113314332143253354223324325443133323 -5317454554616541435267544745564345535444454554426455856424554644426564533456247612545627463343354344 -7351212425822572222224122221322219332622842232622412224234691634427394141452295252268344223251233222 -3534222422223248335212442215413265323223222322244225313222426222123422126122224213321265533344163236 -3862524232255622244426463545231553425465224522643352533233242656323335543424521263353462532456525626 -3123333333323333334323333333333333333434133342333333233331323334233323333233423323333333322233332313 -6963465545525438665445562376544622656146626447265466356464654554564464556364734266665466575524466733 -4246243234583753224761247624347163673324673532734412353464732823336243757643523733722332462834438333 -3232522252233221342222323442222523211111223322231644255243133352432336132233344225112122112222426422 -9227329136662584777229327365545243194261242415652686542284964322432388334779324336192546823434316632 -8978475677865965877789996988788977788854868468658397789864588787988878689888678587498848986687886666 -2433334244233336223732433453525232222333334154225244243334443236423232423132214526426221244234223321 -4548452341643345442462443554446544333345235551435525735165552331335451323221755452435453363324553225 -3431347224133324313323453331344114254345723332233313333333251234333343442434313334434323323733334352 -2242362222531432222122927474823222142324464231282332244122332232212231124244322262221212433342215231 -8233634333432447363432346446233433423163734123242513244362333632322224223733413333524344114653223223 -4477456435953543454526577775574332514654843462625764726676434237737687344353457473674357652263652724 -2212432463242322442432212312535214222246443422124222423244322323414363632232416244264162244231224324 -2423242342313121232343121222242242323334332263245423254225422222233427421242222212222222242321132225 -4342534111253353452553114425315732326334462456323454457443335433425343225223561337245743324325622363 -4525251325232561854255122252223615632452222225225521242245355235525351422225423234243242222252325252 -2543243343243435424245643232423334342243542423373424333344333544244124735323333243331324684234226373 -2444433243433545424444544445436845427554344353544344647444444433442344345544347414344434433634448435 -5476943443524324446225422472222722411423254232145242662563324242436654253335726373343223552732336512 -3322333331223333333323323333332424333433332333333333333334343223343151232433334423133333233432223333 -3443233223264734342223223353236433145423232344432732224323341362122213712371625273443233233334232333 -3255224434415325225225333331248541234552463222254338445233515443536322454339223357545464234333324512 -3442312322324323241231322243423222314242131321431421242414223141413224421121433234224312434343156789 -3243433333554545223334433324334243434323833433343334323233333244334333332534444445432133241433333234 -3334143222213524134223432231333354533943832331214243232239422321322322222229323378312433312123232221 -3934959642317634855483863524654442433544482764895853434386698883345833854725243533635359666522568721 -6252224223234223213241222325212311216222141222823233213222421521222222213222632512312213622343212221 -3335331543333533726313332333348433435325312434233323334334335322233243334623233453533333353333233333 -2157224222222222221334912126222222122242232232422622275232122761221224222213242222231292638421262232 -2221232142122422225223226322232421232153221922223111223311222126222212223225252232211223272423226222 -2323223396632424214412222314322334312622336424132642315244212423423522232234464241222636612393222232 -1344133339543334335343333343634322295453234333343533336633333233333343232313522345653535133255353732 -1122634333363333245333323433463232333334233233333336333613633133333353543243253223234237242333232122 -5445655544596736536441383447754444524952544448335551454425444774565334386643455635435446554555546384 -4533442564356443432454253343443856425354353423442424433133333346343444456434534473144333333333422544 -3212123222132223212152323331322222223222223453722332212222222226222324152421222232322223332322133222 -6121244422342322323333314323334243346265542121231355745423453272243244534333653528323823574132523234 -6277352424732346574662432433332654623436364147425425231264363262225257312513357232236533321322325235 -6855236522543618422321625512321555363617264545321532324852844414226234325155233433224143444113625252 -4145521232353513124253542552213223231115432112451253111223344214232455521235252511332253322153316789 -6833423342653322523539775571322824435245233523224663242842543866122333442312434423662641322516244335 -1133343433323232312432334334234332122333323323124532333222423224332122132243333424333332232123341323 -8844494449444484546348444546453635433424475534412444464844466435475343435444748442443344434447734334 -4741733773643853643764731782646747734765337644598347642774277655144744429477573467442454255546364747 -2323323315123333644232323653333222222232353323212225336523353323322512334143614223231335222212315512 -7323328237259433262237836242271415444643473176256523622433446243246533264364247362247745257564423365 -2113634241533553445435625555531526535455437242453235545545255553522232445543243365342514423523252352 -4252234473674947743345725244725612527734455344412713245332342634253534444324822423482254494389243474 -2222522222222422225223212232521222313232224522422222122222222434222222221222211232526312141222542242 -6456766847365953864376877536333487364443376734944385494376365837637537356444674686546856374634968939 -4765845555666457645566433564584646556578866646656244959566646676674555965676567455735584666562334534 -2211262122222122222231222212232122224221212222222252212122212222222222622132212125222332222121222312 -1221223242222131232222222213312212212323221222223222222142222222222222112222122232222232321223192312 -3653334443454344444645434338644453424443645534564456345227544446445443343476753634356446353244445642 -1222222212233323221122222222213412122222222222232122221142222251251212222222421221222262232231222222 -3123415525444364245433315232445425462343424554351643456332552332444433432224322242742424334124637144 -3333743733324313833723418733624353333126333232732633333423333338343233236394648332333332234636333344 -3393624193593252431143333323335228343332294137613225332326368329224463753223662832176334633243223331 -7312332221343314322231232232252323322622572343232336211223324939221221223323532322326232235223923333 -7358762788521723733237235626624278333662647778872445285688328782457297893478535831662255872697323346 -3555345444524632333355345623325465335454254425455555434553342335545647522333553345533255552333523365 -2414334122423122331236222313326322623124223124323222321142212323321323333244123232234133432324122221 -6474582772326271413226644226295317882433343716177222441515222324572237948565252328222159322127623328 -1242224241214443232442223424423242132221223322232434233444325252222332323225423233222132222341222451 -2332223424442352431646411254623463731223262268434233233425352823223233412341232244327343333732432622 -4133332233231233333332333333423333223343232332336333333333323334353333431333333311314233353333332554 -4321431121261322122412233222331321222512233222244212222253212322823421144132242224222231222121712212 -5563332376441336563627194513352233233323634332973646424632333423353614533413733342134631453643434332 -4222241342343132323212773424432213462326313332773264331342334132243133326933242322534246324222332544 -3443332212431321534362223283222422412223221323322221243212222223232225323134422124234125232425224622 -2342238225534222432333253422322436234224332472222444433135442244344445243441225442422425243522533613 -2513213334493423322333334612334233337223223215331242433323333433373114632333634313333253233423332222 -5453544695543365574585455453355532467234448625426355545845455465525588455655545557455451555594344736 -1432732331123433211231323122223333323333422332232333212333222126233222533324343122432422126322233322 -3232223447323433323341622542332343433343632333432415343323333332143332122225334315343542333473334353 -5341782673817423538842316255388787281882545724122821376458584651148162857412752783166852132282164119 -2722122221222222132223222522412222254232221523222422222224363322212221142222242221242424421122121122 -7643224448343453412444743424343435253443464324441663234324352334443144322424342443443864447444512435 -1896583533764563827377567924897485697285834684449821526445376649465829444455653736645456871625857679 -5355294421345316236225363368623536723222343642362153348625553146544854467666322243276614533561435666 -4434464545444444324445753345354544433524234452443434545452434444544444441423444444154413422344124444 -2542625333535253544524343225535524413234315423222553454353543453355425234455456234253545552322432552 -4543434353433344454354344343444357363543225343484223455421334343442434443533512334435444433323344432 -2335332231322325113323334632122125232232223332222333223222242222222237333553312322124262263342222336 -2112427364113224216151312344224443225218261334421232424332324142222412115225362225224257222345411322 -4697433525359759637832753655349288982452531588782744641446453727464543735314657852673167646622545553 -6454844345464356434455343434444541545371365563444455645455545545143254532463433547565531343555547434 -2452232312311223222211211321323212253235212223192552241221232111223222552258245223252321213332223223 -4465376442346433443566654433643344356645345453447514336543526653663534465443444346444455524465435533 -4673766555236893327678563634969557621473673483674567366633768267556936715353426755745349645655564738 -3331323623322235274433423122323236353322422312243322132225248326334332354323233332224466223833226234 -6527855669668468647972685689668668486546486366578852567872567847778586888865786646866935637553626757 -2243142153244353211241524643565415344455425244324453135271332422236344563354247252263135441352645235 -3213253231231311321335422123322212222121222154222121231112222342545142322732223422232312121232222121 -5726826735628432438522254436263422682482523492664532452692247442354456623453243245654274354244322569 -1233833423213233341335233334134323213433223333213333333323133233423313323233232241332243323321332333 -6755556533622352362753561343636633842437655454743738268478463536567446452226644553553426666643646554 -4433454232422332343333312357523453231333323253333437333245332436373233433293533323353423343324322722 -3323343334322133323332243231333343332633124321331433323333333313143232623252123132412333335123343422 -2242351222324228326422222622222221222513362162321218331332222123222142222222142231551222222328542522 -2135548132223212221375545416852132242223522422324622255392122241314135225122244225222224212551221132 -2322582253222222332232442312223244222233224232322222533323221553133381232213276223332232343224522215 -3443334441534224444342543463487534453436452623432133428647323473125343625465444432232423752258445345 -4222322322223526221434222232222532623216252552236226332412452343213413321122215132213225651343525322 -3543344943242657414434248424154294434444541444244454444452435454441533442144244435432545355512513744 -3734356533337352224284452335373353233431232547217636629455623344723896275243333474353854122734326326 -1212333312333122233222222223331143222222224333123432213133222324231222432342212422222212234432332234 -3445455474754645544467447448573368623754658843363658345454412877864836485478347882653445433447643347 -4434897565575544473356355578451466585993554455955432246647265277673545859615958655239656583533356355 -1322322423213442125433333323332223321222322833223216232342134326233232333342323232233216432332322421 -3563745383454345545545365384345352433635546454992338553532545765465553334436555557667753364365639856 -4225242231222132332446224249244126253233423322323361111421342533224222222221433422125422811228832642 -3121241251232222222122122321222222422624163222122193223222252334232222122223222321224422125222122222 -3222231124356423225342643252315425142642122432333112263452511222322222322346222422223114242437212532 -2441111222251322424241132611222252452312434222222222222221252122712224222226122224122562152111222221 -3545342544314425345342321225375545353245433763565472435423533446522443433251445346663535635465433365 -4522323233313261333333441223346334222612123433252133223133324323326133222541246251422222353532332222 -1222221321225242712221222525222223522222552272213272343272323223122224441115122732521232222222322222 -4232522222323233413342333432333223213412332114322331731312383343122233322123333223234314132322421423 -2351346323224222213242242242361321242126337432324223226146325425424922241521113235112233141333244341 -1653321221515263323263154235222142222133323242332143137341312323222233514721532338632523231433133335 -2533333373443374336434233442436332344334344333346464413544645434433415933333233333333373343362432435 -1721864332622342344427253453223452555338355345335542421443354233245533533752432332532252152133383242 -4444732272157263362723426222912738332612544422722233342633447445265273823252872521334448221112422824 -5245352626633463622437434334464335446533393564253884683655842434665286833766525349864333536926435453 -3636325123432232222122313133393432343234345935722323223424326124634237232225474359336438474431726213 -5226415523525432627335534525425224534734935458564332436527699453573323331429423432536472324653753224 -2513422342531322352413243132234672222324346623331232424342223257131454541233672222383242145122438252 -3146544467949658344474366347526924233647574355355462865318835797953875553548525542955335475377447453 -3262222312322223212323324214232512562243341134343244321214243224522232362224436233221222212241432243 -3343332433633542333332163346314226934475214223336523314243224243352235243553433442336633333413432333 -3335166544833455445576355545425535465363364435641265654263555444447552459546555525454445237317454743 -8264754457452247365533353372516569232483465375527726572335332223924835123936413343323373763537353833 -3223212542332221222232221367222442232353136422331432223325332332231621142325223323323333232422233533 -3226111211222122244411222212122222222211322412211223211422212222142223122321224212221221225512322252 -1822323342252235324328433242974452232922315225335331823244637232241532433252322623323332332253433221 -7121232125422432322322321243322222522242224343421432343333232113114122122434524353232232124431433323 -6113142322443331212213122334732623253235251322233343232332352332335421414223332322321123122631222233 -2322221332542541422212534252535332224544224425222153342244673717844573612444323423425251837744529245 -1521222352252333133312551134422416223423241222523228325232421323162434253222434253252322322232425412 -6466566666466566566485665633555564465626652241654664656653566665555565566774566656636655866566655666 -9243463446264547553622544637456455665475755577564747465552436565645463623546666654667543566565734656 -2223115154523324243322335224232433232213423231123241121276132225534444325125127222243123543235222521 -2423212334233333231234343313313462237323223323333334316334334341334343332322333422439334344321353233 -3323412224233312232225227312333333322222322223533233322237221334336232172252222231222342323135434213 -2324332326333332663333233333233333253323314333532335333332433333333323123332122333334323333323233333 diff --git a/input/test-day1.txt b/input/test-day1.txt deleted file mode 100644 index 9db3fc6..0000000 --- a/input/test-day1.txt +++ /dev/null @@ -1,10 +0,0 @@ -L68 -L30 -R48 -L5 -R60 -L55 -L1 -L99 -R14 -L82 diff --git a/input/test-day2.txt b/input/test-day2.txt deleted file mode 100644 index a3f22ef..0000000 --- a/input/test-day2.txt +++ /dev/null @@ -1 +0,0 @@ -11-22,95-115,998-1012,1188511880-1188511890,222220-222224,1698522-1698528,446443-446449,38593856-38593862,565653-565659,824824821-824824827,2121212118-2121212124 diff --git a/input/test-day3.txt b/input/test-day3.txt deleted file mode 100644 index 7255fca..0000000 --- a/input/test-day3.txt +++ /dev/null @@ -1,4 +0,0 @@ -987654321111111 -811111111111119 -234234234234278 -818181911112111 diff --git a/scripts/docker-entrypoint.sh b/scripts/docker-entrypoint.sh new file mode 100644 index 0000000..fd65923 --- /dev/null +++ b/scripts/docker-entrypoint.sh @@ -0,0 +1,26 @@ +#!/bin/sh +set -eu + +if [ "$#" -eq 0 ]; then + set -- list +fi + +target="$1" +shift + +case "$target" in + day[0-9]*) + day="${target#day}" + exec make run DAY="$day" "$@" + ;; + run-day[0-9]*) + day="${target#run-day}" + exec make run DAY="$day" "$@" + ;; + list) + exec make list "$@" + ;; + *) + exec make "$target" "$@" + ;; +esac \ No newline at end of file diff --git a/src/Day1.asm b/src/Day1.asm deleted file mode 100644 index 8ba8f0e..0000000 --- a/src/Day1.asm +++ /dev/null @@ -1,314 +0,0 @@ -; Advent of Code 2025 - Day 1 - -bits 64 -default rel - -global _start - -%define SYS_EXIT 60 -%define SYS_READ 0 -%define SYS_WRITE 1 -%define SYS_OPEN 2 -%define SYS_CLOSE 3 - -%define O_RDONLY 0 -%define STDOUT 1 - -section .data - inputPath db "input/day1.txt", 0 - newline db 10 - - label1 db "Password 1: ", 0 - label2 db "Password 2: ", 0 - - angle1 dd 50 - angle2 dd 50 - - password1 dd 0 - password2 dd 0 - -section .bss - buffer resb 4096 - lineBuffer resb 256 - numberBuffer resb 16 - lineLen resd 1 - -section .text - -_start: - ; open file - mov rax, SYS_OPEN - mov rdi, inputPath - mov rsi, O_RDONLY - xor rdx, rdx - syscall - - mov r12, rax ; fd in R12 - mov dword [lineLen], 0 ; no chars in current line yet - -ReadLoop: - ; read up to 4096 bytes - mov rax, SYS_READ - mov rdi, r12 - mov rsi, buffer - mov rdx, 4096 - syscall - - cmp rax, 0 - jle EOF ; <=0 -> EOF or error - - mov rdi, buffer ; scan pointer - mov rbp, rax ; bytes remaining in this chunk - -ScanChunk: - cmp rbp, 0 - je ReadLoop ; chunk done, read next - - mov al, [rdi] - - ; windows can be a fucking bitch - ; handle (CR) -> just skip - cmp al, 13 - je SkipCR - - ; handle LF (10) -> end of line - cmp al, 10 - je EndOfLine - - ; normal character -> append to lineBuffer if space left - mov edx, [lineLen] - cmp edx, 255 ; leave 1 byte for NULL - jae SkipStore ; ignore extra characters if too long - mov [lineBuffer+rdx], al - inc edx - mov [lineLen], edx - -SkipStore: - inc rdi - dec rbp - jmp ScanChunk - -SkipCR: - inc rdi - dec rbp - jmp ScanChunk - -EndOfLine: - ; terminate current line - mov edx, [lineLen] - mov byte [lineBuffer+rdx], 0 - - ; if line isn't empty, process it - cmp edx, 0 - je LineDone - - push rdi - mov rsi, lineBuffer - call HandleLine - pop rdi - -LineDone: - mov dword [lineLen], 0 ; reset line length - inc rdi - dec rbp - jmp ScanChunk - -; process last line if not newline-terminated, then print result -EOF: - ; if there is a partial line at EOF, process it - mov edx, [lineLen] - cmp edx, 0 - jle PrintResults - mov byte [lineBuffer+rdx], 0 - - mov rsi, lineBuffer - call HandleLine - -PrintResults: - mov rcx, label1 - call PrintString - mov eax, [password1] - call PrintInt - - ; newline - mov rax, SYS_WRITE - mov rdi, STDOUT - mov rsi, newline - mov rdx, 1 - syscall - - mov rcx, label2 - call PrintString - mov eax, [password2] - call PrintInt - - ; new linhe - mov rax, SYS_WRITE - mov rdi, STDOUT - mov rsi, newline - mov rdx, 1 - syscall - - mov rax, SYS_CLOSE - mov rdi, r12 - syscall - mov rax, SYS_EXIT - xor rdi, rdi - syscall - -; Handle one line: RSI -> "L123" or "R45" -HandleLine: - mov al, [rsi] - cmp al, 'L' - je .left - mov ebx, 1 ; direction = +1 for 'R' or anything else - jmp .after -.left: - mov ebx, -1 ; direction = -1 for 'L' -.after: - inc rsi ; skip 'L' or 'R' - call ParseInt ; EAX = steps - mov ecx, eax - -; Part 1 -P1_Start: - mov eax, ecx - imul eax, ebx - add eax, [angle1] - call NormalizeAngle - mov [angle1], eax - cmp eax, 0 - jne P2_Start - mov rdi, password1 - mov edx, [rdi] - inc edx - mov [rdi], edx - -; Part 2 -P2_Start: - mov rdi, password2 -.loop: - test ecx, ecx - jle P2_Exit - dec ecx - - mov eax, [angle2] - call UpdateAngleCount - mov [angle2], eax - - jmp .loop -P2_Exit: - ret - -; normalize eax to 0..99 -NormalizeAngle: - cmp eax, 0 - jl .add - cmp eax, 100 - jl .done - sub eax, 100 - jmp NormalizeAngle -.add: - add eax, 100 - jmp NormalizeAngle -.done: - ret - -; eax = angle, ebx = direction, rdi = password counter addr -UpdateAngleCount: - add eax, ebx - call NormalizeAngle - - cmp eax, 0 - jne .done - mov edx, [rdi] - inc edx - mov [rdi], edx -.done: - ret - -; parse ASCII integer into EAX -ParseInt: - xor eax, eax ; result = 0 -.parseLoop: - mov dl, [rsi] - cmp dl, '0' - jl .done - cmp dl, '9' - jg .done - - sub dl, '0' ; digit value 0..9 - movzx edx, dl - - imul eax, eax, 10 ; result *= 10 - add eax, edx ; result += digit - - inc rsi - jmp .parseLoop -.done: - ret - -PrintInt: - mov edi, numberBuffer+15 ; write digits from the end - mov byte [rdi], 0 ; terminator - dec rdi - - cmp eax, 0 - jne .convert - mov byte [rdi], '0' - jmp .finish -.convert: - ; we will repeatedly compute: - ; q = eax / 10 - ; r = eax % 10 - ; using only subtraction -.nextDigit: - mov edx, eax ; tmp = current value - mov ecx, 0 ; q = 0 - - cmp edx, 10 ; if < 0, q=0, r=edx - jb .lastDigit -.subLoop: - sub edx, 10 - inc ecx ; q++ - cmp edx, 10 - jae .subLoop ; while tmp >= 10 -.lastDigit: - ; now: - ; ecx = quotient - ; edx = remainder (0..9) - add dl, '0' - mov [rdi], dl ; store digit - dec rdi - mov eax, ecx ; eax = quotient - test eax, eax - jnz .nextDigit ; more digits to extract? - - inc rdi ; move to first digit -.finish: - mov rax, SYS_WRITE - mov rsi, rdi ; buffer pointer - mov rdi, STDOUT - mov rdx, numberBuffer+15 - sub rdx, rsi ; length - syscall - ret - -PrintString: - push rcx - push rdx - mov rdx, 0 -.count: - cmp byte [rcx+rdx], 0 - je .doneCount - inc rdx - jmp .count -.doneCount: - mov rax, SYS_WRITE - mov rdi, STDOUT - mov rsi, rcx - syscall - - pop rdx - pop rcx - ret diff --git a/src/Day2.asm b/src/Day2.asm deleted file mode 100644 index dfbfb38..0000000 --- a/src/Day2.asm +++ /dev/null @@ -1,410 +0,0 @@ -; Advent of Code 2025 – Day 2 - -bits 64 -default rel - -global _start - -%define SYS_EXIT 60 -%define SYS_READ 0 -%define SYS_WRITE 1 -%define SYS_OPEN 2 -%define SYS_CLOSE 3 - -%define O_RDONLY 0 -%define STDOUT 1 - -section .data - inputPath db "input/day2.txt", 0 - newline db 10 - - label1 db "Part 1: ", 0 - label2 db "Part 2: ", 0 - -section .bss - buffer resb 4096 - lineBuffer resb 65536 - lineLen resd 1 - - sum1 resq 1 - sum2 resq 1 - - numberBuffer resb 32 ; for printing and NumberToString - -section .text - -_start: - mov rax, SYS_OPEN - mov rdi, inputPath - mov rsi, O_RDONLY - xor rdx, rdx - syscall - - mov r12, rax ; file descriptor - mov dword [lineLen], 0 - -ReadLoop: - mov rax, SYS_READ - mov rdi, r12 - mov rsi, buffer - mov rdx, 4096 - syscall - - cmp rax, 0 - jle EOF - - mov rdi, buffer - mov rbp, rax - -ScanChunk: - cmp rbp, 0 - je ReadLoop - - mov al, [rdi] - - cmp al, 13 - je SkipCR - - cmp al, 10 - je EndLine - - mov edx, [lineLen] - cmp edx, 65535 - jae SkipStore - mov [lineBuffer+rdx], al - inc edx - mov [lineLen], edx - -SkipStore: - inc rdi - dec rbp - jmp ScanChunk - -SkipCR: - inc rdi - dec rbp - jmp ScanChunk - -EndLine: - mov edx, [lineLen] - mov byte [lineBuffer+rdx], 0 - - cmp edx, 0 - je ClearLine - - push rdi - mov rsi, lineBuffer - call HandleLine - pop rdi - -ClearLine: - mov dword [lineLen], 0 - inc rdi - dec rbp - jmp ScanChunk - -EOF: - ; process final partial line if needed - mov edx, [lineLen] - cmp edx, 0 - jle PrintResults - - mov byte [lineBuffer+rdx], 0 - mov rsi, lineBuffer - call HandleLine - -PrintResults: - mov rcx, label1 - call PrintString - mov rax, [sum1] - call PrintInt64 - call Newline - - mov rcx, label2 - call PrintString - mov rax, [sum2] - call PrintInt64 - call Newline - - mov rax, SYS_CLOSE - mov rdi, r12 - syscall - - mov rax, SYS_EXIT - xor rdi, rdi - syscall - -; parse "A-B,C-D,..."l, RSI = pointer to line -; uses r13 = current ID, r14 = end of range -HandleLine: -NextRange: - ; parse start - call ParseInt64 - mov r13, rax - - cmp byte [rsi], '-' - jne DoneLine - inc rsi - - ; parse end - call ParseInt64 - mov r14, rax - -RangeLoop: - cmp r13, r14 - jg AfterRange - - ; Save RSI (line pointer) across the checks, - ; because NumberToString / CheckInvalid* use RSI - push rsi - - ; Part 1: exact AA - mov rax, r13 - call CheckInvalid1 - test rax, rax - jz .skipP1 - add qword [sum1], r13 -.skipP1: - ; Part 2: any repeating block >= 2 - mov rax, r13 - call CheckInvalid2 - test rax, rax - jz .skipP2 - add qword [sum2], r13 -.skipP2: - pop rsi ; restore line pointer - - inc r13 - jmp RangeLoop - -AfterRange: - cmp byte [rsi], ',' - jne DoneLine - inc rsi - jmp NextRange - -DoneLine: - ret - -; RSI points at decimal digits; stops on first non-digit -ParseInt64: - xor rax, rax -.parse: - mov dl, [rsi] - cmp dl, '0' - jl .done - cmp dl, '9' - jg .done - - sub dl, '0' - movzx rdx, dl - imul rax, rax, 10 - add rax, rdx - - inc rsi - jmp .parse -.done: - ret - -; NumberToString: convert RAX to decimal ASCII, MSB-first -; Output: -; RSI = pointer to first digit -; ECX = length -NumberToString: - mov rdi, numberBuffer+31 - mov byte [rdi], 0 ; terminator (for convenience) - dec rdi - - cmp rax, 0 - jne .conv - - ; handle zero - mov byte [rdi], '0' - mov rsi, rdi - mov ecx, 1 - ret - -.conv: - mov rbx, 10 -.nextDigit: - xor rdx, rdx - div rbx ; RAX = quotient, RDX = remainder - add dl, '0' - mov [rdi], dl - dec rdi - test rax, rax - jnz .nextDigit - - inc rdi ; now RDI points to first digit - mov rsi, rdi - mov rdx, numberBuffer+31 - sub rdx, rsi ; RDX = length - mov ecx, edx - ret - -; CheckInvalid1: "AA" pattern -; RAX = number -; Returns RAX = 1 if digits == A A, else 0 -CheckInvalid1: - push rbx - push rdx - - call NumberToString ; RSI=string, ECX=len - mov eax, ecx ; EAX = len - - cmp eax, 2 - jl .no1 - - test eax, 1 - jnz .no1 ; odd length => cannot be AA - - shr eax, 1 ; half = len/2 - mov r8d, eax ; half - xor r9d, r9d ; i = 0 - -.loop1: - cmp r9d, r8d - jge .yes1 - - ; s[i] - mov rdx, r9 - movzx eax, byte [rsi + rdx] - - ; s[i+half] - mov rdx, r9 - add rdx, r8 - movzx ebx, byte [rsi + rdx] - - cmp eax, ebx - jne .no1 - - inc r9d - jmp .loop1 - -.yes1: - mov rax, 1 - jmp .ret1 - -.no1: - xor rax, rax - -.ret1: - pop rdx - pop rbx - ret - -; CheckInvalid2: any repeating block >= 2 -; RAX = number -; Returns RAX = 1 if string is some A repeated k>=2 times -CheckInvalid2: - push rbx - push rdx - - call NumberToString ; RSI=string, ECX=len - mov r11d, ecx ; n = length - - cmp r11d, 2 - jb .no2 - - mov r8d, 1 ; m = 1 (candidate period) -.outer: - cmp r8d, r11d - jge .no2 - - ; if n % m != 0 => cannot tile - mov eax, r11d - xor edx, edx - div r8d ; EAX=q, EDX=r - test edx, edx - jnz .next_m - - mov r9d, r11d - sub r9d, r8d ; limit = n - m - xor r10d, r10d ; i = 0 -.inner: - cmp r10d, r9d - jge .yes2 ; all positions checked - - ; s[i] - mov rdx, r10 - movzx eax, byte [rsi + rdx] - - ; s[i+m] - mov rdx, r10 - add rdx, r8 - movzx ebx, byte [rsi + rdx] - - cmp eax, ebx - jne .next_m - - inc r10d - jmp .inner -.yes2: - mov rax, 1 - jmp .ret2 -.next_m: - inc r8d - jmp .outer -.no2: - xor rax, rax -.ret2: - pop rdx - pop rbx - ret - -Newline: - mov rax, SYS_WRITE - mov rdi, STDOUT - mov rsi, newline - mov rdx, 1 - syscall - ret - -PrintInt64: - mov rdi, numberBuffer+31 - mov byte [rdi], 0 - dec rdi - - cmp rax, 0 - jne .conv - - mov byte [rdi], '0' - jmp .done -.conv: - mov rbx, 10 -.next: - xor rdx, rdx - div rbx - add dl, '0' - mov [rdi], dl - dec rdi - test rax, rax - jnz .next - - inc rdi -.done: - mov rax, SYS_WRITE - mov rsi, rdi - mov rdi, STDOUT - mov rdx, numberBuffer+31 - sub rdx, rsi - syscall - ret - -PrintString: - push rcx - push rdx - mov rdx, 0 -.length: - cmp byte [rcx+rdx], 0 - je .submit - inc rdx - jmp .length -.submit: - mov rax, SYS_WRITE - mov rdi, STDOUT - mov rsi, rcx - syscall - pop rdx - pop rcx - ret diff --git a/src/Day3.asm b/src/Day3.asm deleted file mode 100644 index e547475..0000000 --- a/src/Day3.asm +++ /dev/null @@ -1,301 +0,0 @@ -; Advent of Code 2025 - Day 3 - -bits 64 -default rel - -global _start - -%define SYS_EXIT 60 -%define SYS_READ 0 -%define SYS_WRITE 1 -%define SYS_OPEN 2 -%define SYS_CLOSE 3 - -%define O_RDONLY 0 -%define STDOUT 1 - -section .data - inputPath db "input/day3.txt", 0 - - newline db 10 - - label1 db "Part 1: ", 0 - label2 db "Part 2: ", 0 - -section .bss - buffer resb 4096 - lineBuffer resb 65536 - lineLen resd 1 - - sum1 resq 1 - sum2 resq 1 - - workDigits resb 64 ; stack for greedy subsequence - numberBuffer resb 32 ; for printing - -section .text - -_start: - mov rax, SYS_OPEN - mov rdi, inputPath - mov rsi, O_RDONLY - xor rdx, rdx - syscall - - mov r12, rax ; fd - mov dword [lineLen], 0 - -ReadLoop: - mov rax, SYS_READ - mov rdi, r12 - mov rsi, buffer - mov rdx, 4096 - syscall - - cmp rax, 0 - jle EOF - - mov rdi, buffer - mov rbp, rax - -ScanChunk: - cmp rbp, 0 - je ReadLoop - - mov al, [rdi] - - cmp al, 13 - je SkipCR - - cmp al, 10 - je EndLine - - mov edx, [lineLen] - cmp edx, 65535 - jae SkipStore - mov [lineBuffer+rdx], al - inc edx - mov [lineLen], edx - -SkipStore: - inc rdi - dec rbp - jmp ScanChunk - -SkipCR: - inc rdi - dec rbp - jmp ScanChunk - -EndLine: - mov edx, [lineLen] - mov byte [lineBuffer+edx], 0 - - cmp edx, 0 - je ClearLine - - push rdi - mov rsi, lineBuffer - call HandleLine - pop rdi - -ClearLine: - mov dword [lineLen], 0 - inc rdi - dec rbp - jmp ScanChunk - -EOF: - ; possible last partial line - mov edx, [lineLen] - cmp edx, 0 - jle PrintResults - - mov byte [lineBuffer+edx], 0 - mov rsi, lineBuffer - call HandleLine - -PrintResults: - mov rcx, label1 - call PrintString - mov rax, [sum1] - call PrintInt64 - call Newline - - mov rcx, label2 - call PrintString - mov rax, [sum2] - call PrintInt64 - call Newline - - mov rax, SYS_CLOSE - mov rdi, r12 - syscall - - mov rax, SYS_EXIT - xor rdi, rdi - syscall - -HandleLine: - mov rdi, rsi - xor ecx, ecx ; ECX = 0 -.lengthLoop: - mov al, [rdi+rcx] - cmp al, 0 - je .lengthDone - inc ecx - jmp .lengthLoop -.lengthDone: - mov r15d, ecx ; r15d = n - - ; part 1: k = 2 - mov ecx, r15d ; ECX = n - mov edi, 2 ; K = 2 - call GetMaxForK ; RAX = best 2-digit value - add qword [sum1], rax - - ; part 2: k = 12, only if n >= 12 - cmp r15d, 12 - jl .skipPart2 - - mov ecx, r15d - mov edi, 12 - call GetMaxForK ; RAX = best 12-digit value - add qword [sum2], rax - -.skipPart2: - ret - -; Greedy lexicographically largest subsequence of length K -; -; Input: -; RSI -> digits string -; ECX = n (length) -; EDI = k -; Output: -; RAX = numeric value of chosen k digits -; Clobbers: R8..R11, EAX, EDX -GetMaxForK: - ; dropsRemaining = n - k - mov eax, ecx - sub eax, edi - mov r8d, eax ; r8d = drops - - xor r9d, r9d ; r9d = stackSize - xor r10d, r10d ; r10d = i - -.loop: - cmp r10d, ecx - jge .after_input - - ; current digit in AL - mov r11, r10 - mov al, [rsi + r11] - -.pop: - cmp r9d, 0 - jle .push - cmp r8d, 0 - jle .push - - mov edx, r9d - dec edx - mov r11d, edx - mov bl, [workDigits + r11] - - cmp bl, al - jge .push - - dec r9d - dec r8d - jmp .pop -.push: - mov r11d, r9d - mov [workDigits + r11], al - inc r9d - inc r10d - jmp .loop - -.after_input: - ; trim if stackSize > k -.trim: - cmp r9d, edi - jle .convert - dec r9d - jmp .trim -.convert: - xor rax, rax - xor r11d, r11d -.convertLoop: - cmp r11d, edi - jge .done - - mov rdx, r11 - mov dl, [workDigits + rdx] - sub dl, '0' - movzx rdx, dl - - imul rax, rax, 10 - add rax, rdx - - inc r11d - jmp .convertLoop -.done: - ret - -Newline: - mov rax, SYS_WRITE - mov rdi, STDOUT - mov rsi, newline - mov rdx, 1 - syscall - ret - -PrintInt64: - mov rdi, numberBuffer+31 - mov byte [rdi], 0 - dec rdi - - cmp rax, 0 - jne .conv - - mov byte [rdi], '0' - jmp .done -.conv: - mov rbx, 10 -.next: - xor rdx, rdx - div rbx - add dl, '0' - mov [rdi], dl - dec rdi - test rax, rax - jnz .next - - inc rdi -.done: - mov rax, SYS_WRITE - mov rsi, rdi - mov rdi, STDOUT - mov rdx, numberBuffer+31 - sub rdx, rsi - syscall - ret - -PrintString: - push rcx - push rdx - mov rdx, 0 -.length: - cmp byte [rcx+rdx], 0 - je .submit - inc rdx - jmp .length -.submit: - mov rax, SYS_WRITE - mov rdi, STDOUT - mov rsi, rcx - syscall - pop rdx - pop rcx - ret diff --git a/src/Day4.asm b/src/Day4.asm deleted file mode 100644 index 475f2ef..0000000 --- a/src/Day4.asm +++ /dev/null @@ -1,25 +0,0 @@ -bits 64 -default rel - -global _start - -%define SYS_EXIT 60 -%define SYS_WRITE 1 - -%define STDOUT 1 - -section .data - message db "Hello Day 4!", 0xA - length equ $-message - -section .text -_start: - mov rax, SYS_WRITE - mov rdi, STDOUT - mov rsi, message - mov rdx, length - syscall - - mov rax, SYS_EXIT - xor rdi, rdi - syscall -- cgit v1.3