aoc

Thing1's 2025 aoc
Log | Files | Refs

commit 84b993d6dd8bc353209fb7580bea5b3015daadd4
parent 3c2883bb0c8fbfd6be0c15c3a61de0e68d1c8f7b
Author: thing1 <thing1@seacrossedlovers.xyz>
Date:   Sat,  6 Dec 2025 11:58:54 +0000

advanced 5b, this doesnt work right now

Diffstat:
M5/5b.c | 7++++---
A5/5b.go | 62++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
M5/Makefile | 9++++++---
3 files changed, 72 insertions(+), 6 deletions(-)

diff --git a/5/5b.c b/5/5b.c @@ -33,11 +33,12 @@ seen: int main() { - long long int total = 0; + long long int total = 0, start; + int i; loadranges(stdin); - for (int i = 0; i < rangecount; i++) { - for (long long int start = ranges[i].lower; start <= ranges[i].upper; start++) { + for (i = 0; i < rangecount; i++) { + for (start = ranges[i].lower; start <= ranges[i].upper; start++) { if (!hasappeared(start, &ranges[i])) { total++; //printf("new valid id\n"); diff --git a/5/5b.go b/5/5b.go @@ -0,0 +1,62 @@ +package main + +import ( + "fmt" + "strconv" + "C" + "bufio" + "os" +) + +type limit struct { + lower C.longlong + upper C.longlong +} + +var limits [1024]limit +var limitscount int = 0 + +func loadlimits() { + reader := bufio.NewReader(os.Stdin) + for { + line, _ := reader.ReadString('\n') + if len(line) == 0 { + break; + } + + lower, _ := strconv.Atoi(line) + upper, _ := strconv.Atoi(strchr(line, '-') + 1) + + limits[limitscount].lower = C.longlong(lower) + limits[limitscount].upper = C.longlong(upper) + limitscount++ + } +} + +func hasappeared(id C.longlong, end limit) int { + for _, r := range limits { + if (r == end) { + break + } + if id <= r.upper && id >= r.lower { + goto seen + } + } + return 0 +seen: + return 1 +} + +func main() { + total := 0 + loadlimits(stdin) + + for i := 0; i < limitscount; i++ { + for start := limits[i].lower; start <= limits[i].upper; start++ { + if hasappeared(start, limits[i]) == 0 { + total++ + } + } + } + fmt.Printf("%lld\n", total) +} diff --git a/5/Makefile b/5/Makefile @@ -1,10 +1,13 @@ CFLAGS=-Ofast -ffast-math LDFLAGS= -all: 5a 5b +all: 5a 5b 5bgo 5a: 5a.c 5b: 5b.c +5bgo: 5b.go + go build 5b.go + clean: - rm 5a 5b -\ No newline at end of file + rm 5a 5b 5bgo +\ No newline at end of file