Aetherus
Hello, guys. I’m back again, but only for the weekends, maybe.
This topic is about Day 13 of the Advent of Code 2020 .
Thanks to @egze, we have a private leaderboard:
https://adventofcode.com/2020/leaderboard/private/view/39276
The join code is:
39276-eeb74f9a
Trending in Challenges
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
code-shoily
I am stuck at part 2 of this one, trying to use Chinese Remainder Theorem but for some reason getting the mods messed up, whether to go backwards or something like
(v - idx)… ekh, I guess I’m just tired, will try tomorrowMeanwhile, my not so sophisticated part 1:
Aetherus
I’m stuck at Part 2, too. Chinese Remainder Theorem looks interesting.
So far, my Part 1 code:
code-shoily
Ekh, I could not sleep without trying out Chinese Remainder Theorem. It works!!! Though I cheated. I did not have the energy to remember the details of algorithm and try to implement in Elixir, so I Rosetta Coded it and the Elixir version there was brute forced, so Nope. So I translated the Erlang version there into Elixir (which in turn was translated from OCaml) and Bam! it worked and performed well. Here’s my CRT:
https://github.com/code-shoily/advent_of_code/blob/master/lib/helpers/chinese_remainder.ex
And the relevant bits of the main code:
Also I realized, my “read Erlang, write Elixir” speed is more than I thought it would be, it’s almost typing speed level
Aetherus
I Wiki’ed the Chinese Remainder Theorem and hand-coded the sieving approach. It worked on the example input, but was deadly slow on the true input. I guess I’ll go the Rosetta way, too.
UPDATE
I implemented the same sieving approach in Ruby, and it finished in 0.15s. I wonder why Elixir is so much slower than Ruby.
Here’s the Ruby code:
voltone
My part 2 runs in 64µs:
cblavier
Really clever. I was playing with lcm but could not figure out how
Damirados
Took me hours and few papers to figure out LCM should raise period of steps, not sleeping for more than 30 hours didn’t help either.
https://github.com/Damirados/AoC/blob/master/lib/Y2020/event13.ex
kwando
Beautiful!
Papey
Here is my naive part 2, it’s a brute force that gets the job done really fast
I use the fact that, since they are all prime numbers,
CGD(p, q) = 1, then if a = 0 [p] and a = 0 [q], then a = 0 [pq]
And i’m searching for a = 0 [l0..ln]
LostKobrakai
This is genius. I’m not sure how I would ever have come to something like that. I knew lcm would be somehow needed but the offsets blew anything I could think of out of the window. I’ve inlined the actual calculation I adapted from yours, so it’s no longer manually recursive and hopefully a bit simpler in what happens: