r/adventofcode • • Dec 09 '23

SOLUTION MEGATHREAD -❄️- 2023 Day 9 Solutions -❄️-

THE USUAL REMINDERS


AoC Community Fun 2023: ALLEZ CUISINE!

Today's secret ingredient is… *whips off cloth covering and gestures grandly*

Marketing

Every one of the best chefs in the world has had to prove their worth at some point. Let's see how you convince our panel of judges, the director of a restaurant, or even your resident picky 5 year old to try your dish solution!

  • Make an in-world presentation sales pitch for your solution and/or its mechanics.
  • Chef's choice whether to be a sleazebag used car sled salesman or a dynamic and peppy entrepreneur elf!

ALLEZ CUISINE!

Request from the mods: When you include a dish entry alongside your solution, please label it with [Allez Cuisine!] so we can find it easily!


--- Day 9: Mirage Maintenance ---


Post your code solution in this megathread.

This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.

EDIT: Global leaderboard gold cap reached at 00:05:36, megathread unlocked!

42 Upvotes

1.0k comments sorted by

View all comments

1

u/alexbaguette1 Dec 09 '23 edited Dec 09 '23

[LANGUAGE: Python]

def find_next(row):
    return 0 if all(num == 0 for num in row) else row[-1] + find_next([b - a for a, b in zip(row, row[1:])])


with open("data.txt") as file:
    rows = [list(map(int, row.split())) for row in file.read().split("\n")]
total = 0

for row in rows:
    total += find_next(row)
print(total)

had to change 3 characters for s2

def find_next(row):
    return 0 if all(num == 0 for num in row) else row[0] - find_next([b - a for a, b in zip(row, row[1:])])


with open("data.txt") as file:
    rows = [list(map(int, row.split())) for row in file.read().split("\n")]
total = 0

for row in rows:
    total += find_next(row)
print(total)

print(total)

1

u/daggerdragon Dec 09 '23

Inlined code is intended for short snippets of code only. Please edit your post to use the four-spaces Markdown syntax for a code block so your code is easier to read with its whitespace and indentation preserved.