LOADING: An error occurred. Update Chrome, try Firefox, or visit this post for more details.

⚠️Reddit changed how removals work, which breaks Reveddit's website. Install the extension to track removed content:Add to chromeAdd to firefoxWhat changed?
✖︎
about reveddit
⚙F.A.Q.add-ons
r/
status
copy sharelink
[+] show filters
74
SOLUTION MEGATHREAD-🎄- 2022 Day 11 Solutions -🎄-(self.adventofcode)
submitted 3 years, 1 month ago* (edited 17 minutes after) by daggerdragon to /r/adventofcode (134.8k)
1036 commentsredditother-discussionssubreddit-indexmessage modsop-focus

WIKI NEWS

  • The FAQ section of the wiki on [Code Formatting](https://www.reddit.com/r/adventofco...

... view full text

since 3 years, 1 month ago
10 of 10

Tip Reveddit Real-Time can notify you when your content is removed.

your account history
(check your username's removed content. why?)
Tip Check if your account has any removed comments.
view my removed comments
you are viewing a single comment's thread.
view all comments
[–][deleted]4 points3 years, 1 month ago
[deleted] by user
(check your username's removed content. why?)
hide replies (4)as-of
[–]pem42242 points3 years, 1 month ago* (edited 1 hour, 2 minutes after)

Hi Svetlin

I manage to get part2 in less than 4ms in Go without any particular trick (but without parsing). I am sure you can do better with Rust 😁

https://github.com/pemoreau/advent-of-code/blob/main/go/2022/11/day11.go

permalinkparentcontexthide replies (1)author-focusas-ofpreserve
[–][deleted]1 point3 years, 1 month ago
[deleted] by user
(check your username's removed content. why?)
parenthide replies (1)as-of
[–]pem42241 point3 years, 1 month ago* (edited 12 minutes after)

Hi

Did you notice that the input is hard coded since I did not implemented a general parser.

To get more precise timing I use the following command to measure the execution time:

go test -bench .

In fact the purpose of my message was not to compare go and rust, but to indicate you that your implementation may be not optimized enough. If my version is as fast as a Rust implementation this may come from the use of high order functions to describe monkeys, or the fact that the arrays are never deallocated or resized. This may give you some ideas

For instance when you use the drain method line 142, does this keep the underlying array or does the upcoming push will reallocate memory? I am not expert enough in rust to answer this question

Cheers

permalinkparentcontextauthor-focusas-ofpreserve
[–]__maccas__1 point3 years, 1 month ago

I did something really similar but kept everything on the stack (using fixed arrays). My runtime is circa 8ms. Code here if you're interested

permalinkparentcontexthide replies (1)author-focusas-ofpreserve
[–][deleted]1 point3 years, 1 month ago
[deleted] by user
(check your username's removed content. why?)
parenthide replies (1)as-of
[–]__maccas__1 point3 years, 1 month ago

Yikes! Will do. Appreciate the thorough work checking my code. I really didn't expect that level of service

permalinkparentcontexthide replies (1)author-focusas-ofpreserve
[–]__maccas__1 point3 years, 1 month ago

Now that I'm back at a computer, I've given it a go and you're spot on: your part 2 runs in 5 ms on my machine (Intel i7-9750H 2.60 GHz).

And there was me thinking I was writing efficient code :( Really I've just paid for more processing power.

permalinkparentcontextauthor-focusas-ofpreserve
[–]Shrugadelic1 point3 years, 1 month ago

You did something similar to me to make the borrow-checker happy, but I found this can be achieved by 1. Using indices to access the monkeys and 2. Accessing the current monkey within its inner item loop. https://github.com/shrugalic/advent_of_code_2022/commit/f3560c8a4072e36b8d880aeaf55cc3fda144126c#diff-822fc9256accc2cb36ea596f0bc6bc017dc3cab0e32f89ca7ee7da3e2c5e8cdaR105

permalinkparentcontextauthor-focusas-ofpreserve
[–]MrJohz1 point3 years, 1 month ago

I also ran into the multiple borrow issue, so I ended up just using indices instead of iterating over the monkeys themselves, which kept the borrows short. (I assume the compiler can still optimise that, and doesn't keep on loading the data each time?)

permalinkparentcontextauthor-focusas-ofpreserve
r/revedditremoved.substack.com
🚨 NEWS 🚨
✖︎

Important: Reddit Changed How Removals Work

A recent Reddit update makes mod-removed content disappear from profile pages, which breaks Reveddit's website.

Install the browser extension to receive removal alerts.

Add to chromeAdd to firefox

What changed?

r/revedditremoved.substack.com