Unable to load image

rDrama Advent of Code Day 5 - Brute Force Edition

Summary for those just joining us:

Advent of Code is an annual Christmas themed coding challenge that runs from December 1st until christmas. Each day the coding problems get progressively harder. We have a leaderboard and pretty good turnout, so feel free to hop in at any time and show your stuff!

Whether you have a single line monstrosity or a beautiful phone book sized stack of OOP code, you can export it in a nice little image for sharing at https://carbon.vercel.app

What did you think about today's problem?

https://adventofcode.com/2023

Our Code is 2416137-393b284c (No need to share your profile, you have the option to join anonymously if you don't want us to see your github)

15
Jump in the discussion.

No email address required.

Who is the mysterious anonymous user #371225?

Finally, a task that rewards a meticulous programmer. Nothing particularly complicated, just be careful, think a little bit ahead, write maintainable (for the next 10 minutes) code. The important parts:

   def intersect_range(x, xlen, y, ylen):
       r = max(x, y)
       rend = min(x + xlen, y + ylen)
       if rend <= r:
           return None, None
       return r, rend - r

   def mapstep2(x, xlen, curmap):
       ranges = []
       srcranges = []
       for dest, src, rlen in curmap:
           r, rlen = intersect_range(x, xlen, src, rlen)
           if r is None: continue
           srcranges.append((r, rlen))
           ranges.append((dest + r - src, rlen))

       curx = x
       for r, rlen in sorted(srcranges):
           if r - curx > 0:
               ranges.append((curx, r - curx))
           curx = r + rlen
       if curx < x + xlen:
           ranges.append((curx, x + xlen - curx))

       return ranges
Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.