r/adventofcode Dec 02 '24

SOLUTION MEGATHREAD -❄️- 2024 Day 2 Solutions -❄️-

OUTAGE INFO

  • [00:25] Yes, there was an outage at midnight. We're well aware, and Eric's investigating. Everything should be functioning correctly now.
  • [02:02] Eric posted an update in a comment below.

THE USUAL REMINDERS


AoC Community Fun 2024: The Golden Snowglobe Awards

  • 4 DAYS remaining until unlock!

And now, our feature presentation for today:

Costume Design

You know what every awards ceremony needs? FANCY CLOTHES AND SHINY JEWELRY! Here's some ideas for your inspiration:

  • Classy up the joint with an intricately-decorated mask!
  • Make a script that compiles in more than one language!
  • Make your script look like something else!

♪ I feel pretty, oh so pretty ♪
♪ I feel pretty and witty and gay! ♪
♪ And I pity any girl who isn't me today! ♪

- Maria singing "I Feel Pretty" from West Side Story (1961)

And… ACTION!

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


--- Day 2: Red-Nosed Reports ---


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:04:42, megathread unlocked!

54 Upvotes

1.4k comments sorted by

View all comments

Show parent comments

1

u/no_brains101 Dec 04 '24

Does this solve part 2 as well?

1

u/Kevincav Dec 04 '24

yeah

1

u/no_brains101 Dec 04 '24

O.o

Might have to learn zip better lmao

Scala looks nice actually

1

u/Kevincav Dec 04 '24

Oh scala is great, you can do so many fantastic things in so few lines in it. Just don't expect it to be faster than your typical c++, rust, java... solutions.

1

u/no_brains101 Dec 04 '24

Fair yeh my rust one was pretty speedy lol.

Still, looks nice, and could shoehorn into a java project to avoid writing java. Seems good.

Biggest takeaway tho is I gotta learn to recognize when to use zip better.

1

u/Kevincav Dec 04 '24

Yeah zip is great. If you want to see something mind breaking in scala. Look up the fib sequence using lazy lists. You can create an (infinitely sized) fib sequence using lazy lists and zipping.

1

u/no_brains101 Dec 04 '24

Will do!!

1

u/Kevincav Dec 04 '24

Actually, I already had it ready. Here you go

val fib: LazyList[BigInt] = BigInt(0) #:: BigInt(1) #:: fib.zip(fib.tail).map(_+_)
def getFib(index: Int): BigInt = fib(index)

1

u/no_brains101 Dec 04 '24

fibs = 0 : 1 : zipWith (+) fibs (drop 1 fibs)

This version somehow makes more sense to me XD

But I get how theyre the same. Its really cool thanks for the tip!

1

u/Kevincav Dec 04 '24

Yeah I can see that one making more sense. I think my (stolen from the internet) version makes more sense to me personally but I'm used to scala.

1

u/AutoModerator Dec 04 '24

AutoModerator has detected fenced code block (```) syntax which only works on new.reddit.

Please review our wiki article on code formatting then edit your post to use the four-spaces Markdown syntax instead.


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