r/adventofcode • • Dec 08 '23

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

THE USUAL REMINDERS


AoC Community Fun 2023: ALLEZ CUISINE!

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

International Ingredients

A little je ne sais quoi keeps the mystery alive. Try something new and delight us with it!

  • Code in a foreign language

    • Written or programming, up to you!
    • If you don’t know any, Swedish Chef or even pig latin will do
  • Test your language’s support for Unicode and/or emojis
  • Visualizations using Unicode and/or emojis are always lovely to see

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 8: Haunted Wasteland ---


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:10:16, megathread unlocked!

52 Upvotes

968 comments sorted by

View all comments

2

u/Professional-Top8329 Dec 08 '23 edited Dec 08 '23

Both parts golfed in Python (180 bytes). Any improvements are welcome.

import math
M,*I=open(0)
S={l[:3]:l[7:].split()for l in I}
for s in 3,1:print(math.lcm(*[len([p:=S[p][m>"L"][:3]for m in M[:-1]*99if"Z"*s>p[-s:]])for q in S if"A"*s==(p:=q)[-s:]]))

1

u/AutoModerator Dec 08 '23

AutoModerator did not detect the required [LANGUAGE: xyz] string literal at the beginning of your solution submission.

Please edit your comment to state your programming language.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/azzal07 Dec 08 '23

You could save a few by not splitting the values in S:

S={l[:3]:l[7:].split()for l in I}S[p][m>"L"][:3]
S={l[:3]:l for l in I}S[p][7+5*(m>"L")][:3]

And in the same space you can get rid of a syntax warning (on py >= 3.11 it warns about "invalid decimal literal")

M[:-1]*99if
99*M[:-1]if

1

u/daggerdragon Dec 08 '23

Please add the language tag as requested by AutoModerator.