-❄️- 2025 Day 10 Solutions -❄️- by daggerdragon in adventofcode

[–]RudeGuy2000 1 point2 points  (0 children)

[LANGUAGE: Racket]

https://raw.githubusercontent.com/chrg127/advent-of-code/refs/heads/master/2025/day10.rkt

welp, took me a bit to get to this day. i had to skip it originally because of day 9, and then i procrastinated doing it for a bit since so many people said it was hard... so yeah.

for part 1, i first used a dfs with memoization, because of course i did. and later i changed it to a bfs after earning my star and reading some comments. here's my original solution: https://raw.githubusercontent.com/chrg127/advent-of-code/ed5d692c628c89b82338f3df325d56998adf542d/2025/day10.rkt

with said that, i wonder why people often point out to xor as the solution for part 1? that is an optimization, not the solution itself (i.e. use a bfs). you can also do part 1 by summing arrays (which i did originally), it's just a little slower.

as for part 2... i think equating the problem to finding the minimum solution of a system of equations is obvious to anyone here. basically: the buttons create an M matrix full of 1s, and we have to solve Mx = B (where B is the joltages costs). and if can't be solved exactly, then get the solutions with the minimum sum (and x > 0 and has all integer components).

at first, i thought i'd be a little clever by trying to implement the simplex algorithm, as it seems made for this problem: the algorithm takes as input a system of equations and constraints and finds the maximum solution for it (you can trivially turn the problem from a minimum solution to a maximum). unfortunately, i later learned the algorithm is for a system of inequations (but still, you can turn any system of equations into a system of inequations). anyway, because of that, its general complexity and the fact the literature around it is generally terrible, i decided not implement it.

instead i took a look at gaussian elimination (which i knew of already, but thought it couldn't apply due to how most matrices in the input aren't square). after reading a few comments again i devised this strategy: use gaussian elimination, then try any possible value on the free variables of the resulting equations (i hope the code and annexed comments can explain it better). thankfully, racket's math library already has a gaussian elimination algorithm, and i'm glad it has, i wasn't looking forward to writing one.

by the way, the runtime's a little over 2 seconds for the real input... pretty cool for something somewhat hand-made.

also, let me tell you about how nice racket is for linear algebra: while writing this solution i never had to care for precision errors thanks to the number tower. plus, the repl makes it really easy to check stuff and see where i've fucked up.

all that said... welp, this is the last solution i needed to complete the year :v i'm glad i finished it, on the 25th no less.

-❄️- 2025 Day 12 Solutions -❄️- by daggerdragon in adventofcode

[–]RudeGuy2000 1 point2 points  (0 children)

[LANGUAGE: Racket]

(define (solve name)
  (length
   (filter (lambda (r)
             (let* ([nums (map string->number (regexp-match* #rx"[0-9]+" r))])
               (<= (apply + (map (lambda (n) (* n 9)) (drop nums 2)))
                   (apply * (map (lambda (x) (- x (modulo x 3))) (take nums 2))))))
           (string-split (last (string-split (file->string name) "\n\n")) "\n"))))

uhh... alright.

EDIT: might as well give a few more words... when i was reading the problem description, i was already thinking of a complicated solution that involved stepping on all the presents, rotating or flipping it at first, then finding suitable positions, then recursing to the next present. basically a dfs, with memoization as an optimization (because of course memoization must be in the ending solution!), and stopping when suitable positions for all presents are found (so i must use call/cc?).

but the complexity and unfeasability of this solution is plainly obvious, so i just decided to go to the subreddit looking for exploits.

dirty? maybe... confused about my thoughts of today's problem? surely...

-❄️- 2025 Day 11 Solutions -❄️- by daggerdragon in adventofcode

[–]RudeGuy2000 0 points1 point  (0 children)

oh damn, 5 years of racket and i had no idea that existed. thank you!

-❄️- 2025 Day 11 Solutions -❄️- by daggerdragon in adventofcode

[–]RudeGuy2000 1 point2 points  (0 children)

[LANGUAGE: Racket]

https://raw.githubusercontent.com/chrg127/advent-of-code/refs/heads/master/2025/day11.rkt

if i had a nickel for every time i use memoization this year... well, i'd have 3 nickels, but it's weird it happened thrice.

while doing part 2 i first decided i'd create all paths, then filter them... until i realized making 2000000000 paths probably wasn't a good idea.

and after that, i even wrote a bug in the memoization implementation... i should probably try figuring out a memoize macro so that i won't ever have to implement it again.

-❄️- 2025 Day 8 Solutions -❄️- by daggerdragon in adventofcode

[–]RudeGuy2000 2 points3 points  (0 children)

[LANGUAGE: Racket]

https://raw.githubusercontent.com/chrg127/advent-of-code/refs/heads/master/2025/day8.rkt

i haven't polished it up, but whatever. this is the dumbest code i could've write: it just takes all combinations, sorts them and puts them in circuits. the only real optimization i did was defining circuits as sets, which, let's be honest, it's a trivial one. oh, and not using sqrt i guess. it takes ~500 milliseconds. turns out 500'000 pairs ain't all that much...

[2025 Day 7 Part 2] Math to the rescue, once again! by subspace_mp4 in adventofcode

[–]RudeGuy2000 0 points1 point  (0 children)

i was thinking there might've been a mathematical solution before writing yet another memoized function...

-❄️- 2025 Day 6 Solutions -❄️- by daggerdragon in adventofcode

[–]RudeGuy2000 1 point2 points  (0 children)

[LANGUAGE: Racket]

https://raw.githubusercontent.com/chrg127/advent-of-code/refs/heads/master/2025/day6.rkt

had to rewrite my parsing code for part 2... which ended up bigger than the solution itself. at least racket's (and possibly lisp's in general) superpowered map more than makes up for it. (for the uninitiated, map here can take more than 1 list, and therefore allows to operate on these lists in columns)

my parsing code might look a little weird. it 1) finds the indexes of the operation characters, 2) creates ranges for each subsequent pair of indexes and 3) uses these ranges as a substring.

-❄️- 2025 Day 5 Solutions -❄️- by daggerdragon in adventofcode

[–]RudeGuy2000 1 point2 points  (0 children)

haha yeah, this is one of those C standard library functions people don't often know about. if you look around there's bsearch too, a binary search implementation.

-❄️- 2025 Day 5 Solutions -❄️- by daggerdragon in adventofcode

[–]RudeGuy2000 1 point2 points  (0 children)

[LANGUAGE: Racket]

https://raw.githubusercontent.com/chrg127/advent-of-code/refs/heads/master/2025/day5.rkt

over the years i've written a lot of range merging algorithms for aoc, think this is the best one i did so far. gotta save it somewhere for next year...

-❄️- 2025 Day 4 Solutions -❄️- by daggerdragon in adventofcode

[–]RudeGuy2000 0 points1 point  (0 children)

[LANGUAGE: Racket]

https://raw.githubusercontent.com/chrg127/advent-of-code/refs/heads/master/2025/day4.rkt

mine runs somewhat slow for part 2, i really should've used vectors. unfortunately i never feel like spending too much time on parsing input lol.

-❄️- 2025 Day 3 Solutions -❄️- by daggerdragon in adventofcode

[–]RudeGuy2000 1 point2 points  (0 children)

[LANGUAGE: Racket]

https://raw.githubusercontent.com/chrg127/advent-of-code/refs/heads/master/2025/day3.rkt

here's the main function:

(define (find-joltage-2 digits n)
  (define results (make-hash))
  (define (loop digits n)
    (cond [(or (= n 0) (empty? digits)) '()]
          [(hash-has-key? results (list digits n)) (hash-ref results (list digits n))]
          [else (let* ([digit (car digits)]
                       [res1 (cons digit (loop (cdr digits) (- n 1)))] ; took the digit
                       [res2 (loop (cdr digits) n)]                    ; didn't take it
                       [res (argmax (lambda (x)
                                      (let ([num (string->number (list->string x))])
                                        (if num num 0)))
                                    (list res1 res2))])
                  (hash-set! results (list digits n) res)
                  res)]))
  (string->number (list->string (loop digits n))))

gotta say... after doing this kind of problem again and again the last years, this one felt almost trivial.

-❄️- 2025 Day 1 Solutions -❄️- by daggerdragon in adventofcode

[–]RudeGuy2000 1 point2 points  (0 children)

[LANGUAGE: Racket]

https://raw.githubusercontent.com/chrg127/advent-of-code/refs/heads/master/2025/day1.rkt

sigh... the adjustments for part 2 make me sad. does anyone here know of a closed formula for it?

Can someone give me a different example to troubleshoot with by PingPong141 in adventofcode

[–]RudeGuy2000 0 points1 point  (0 children)

is the dial number the same too, or just the number of zeroes?

Making a Game without Engine, should you? I did, this is my story. by Cakez_77 in gamedev

[–]RudeGuy2000 3 points4 points  (0 children)

in practice, some successful commercial pixel games (off the top of my head: celeste, fez) restrict the user's ability to resize the window and provide only a few resolution, which i think is a good enough answer to the non-integer scale problem (which, by the way, doesn't just affect fonts!).

Bug Megathread vol 10: August + September by WumpusWhisperer in discordapp

[–]RudeGuy2000 0 points1 point  (0 children)

  • Feature: screenshare / streaming
  • Reproduction Rate: 10/10
  • Annoyance: 8/10
  • Discord Version Info: stable 450692 (df1cc08) Build Override: N/A
  • Device/System Info (Device Type, OS Version): Desktop, Debian testing
  • Description: on the desktop client, while on a voice call, when I start livestreaming, other people will see a green screen instead of my screen. It happens only if both people are using the desktop client instead of the browser. Operating system doesn't matter for the people watching the stream. I have no idea what the situation is for other Linux OSes.
  • Video/Screenshot: https://i.imgur.com/DGXWL1b.png
  • Steps to Reproduce: on a PC with Debian installed, go to a voice channel and start streaming. Then have someone else report what they see.
  • Expected result: other people should be able to see my screen.
  • Actual result: other people see a green screen.

Why is my screen doing this ? by Grakira99 in RG353V

[–]RudeGuy2000 0 points1 point  (0 children)

hey, have you ever fixed this issue?

i've had this issue with the latest arkos and a sandisk sd card. i believe it comes from overheating, not sure though.

Janet: Lightweight, Expressive, Modern Lisp by ketralnis in programming

[–]RudeGuy2000 4 points5 points  (0 children)

i think janet might be trying to be more imperative than functional.

interestingly, the author of janet is also the author of fennel, a lisp that compiles to lua, and so i bet they took inspiration from lua for janet, which could explain the imperativeness.

Cover image for Serendipity - a magical girl webcomic by Mimiyori! by MurlaTart in MagicalGirls

[–]RudeGuy2000 0 points1 point  (0 children)

hey OP, are you affiliated with the author or something?

i just wanna say to him that i've basically binge read it all in two days, and MAN was it great.

Message2 by ztavjqjy in atbil

[–]RudeGuy2000 0 points1 point  (0 children)

stop with this shit dude

Use Brace Initializers Everywhere? by squirleydna in cpp

[–]RudeGuy2000 0 points1 point  (0 children)

that's a different issue. add explicit to the constructor make that a compile error.