hvnsweeting
Advent of code 2020 - Day 25
This topic is about Day 25 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
Most Liked
bjorng
Erlang Core Team
Merry Christmas everyone!
Here is my solution.
3
Papey
Thanks a lot, I learned a lot by reading your solutions and all !
Merry Xmas !
defmodule AOC.D25 do
import AOC.Helper.Input
def run1(test \\ false) do
[cpubk, dpubk] =
get_input("D25", test)
|> split_input()
|> Enum.map(&String.to_integer/1)
transforms(cpubk, 7, 1, 1)
|> encryption_key(0, dpubk, 1)
end
def run2() do
"Merry Xmas !"
end
def encryption_key(lsize, count, _subject, value) when lsize == count, do: value
def encryption_key(lsize, count, subject, value) do
encryption_key(lsize, count + 1, subject, rem(value * subject, 20_201_227))
end
def transforms(pubkey, _subject, lsize, value) when pubkey == value, do: lsize - 1
def transforms(pubkey, subject, lsize, value) do
transforms(pubkey, subject, lsize + 1, rem(value * subject, 20_201_227))
end
end
3
Hallski
Merry Xmas everyone, thanks a lot for all the fun!
Also went back to redo Day20 part 2 from scratch to get the last star, here is todays.
defmodule AdventOfCode.Day25 do
@subject_number 7
@magic_number 20_201_227
def run({card_key, door_key}) do
card_key
|> loop_size(@subject_number)
|> encryption_key(door_key)
end
def loop_size(key, subject), do: loop_size(1, key, subject, 0)
def loop_size(value, key, _subject, loop) when key == value, do: loop
def loop_size(value, key, subject, loop) do
value
|> transform(subject)
|> loop_size(key, subject, loop + 1)
end
def encryption_key(loops, subject), do: encryption_key(1, subject, loops)
def encryption_key(value, _subject, 0), do: value
def encryption_key(value, subject, loops) do
value
|> transform(subject)
|> encryption_key(subject, loops - 1)
end
def transform(value, subject) do
rem(value * subject, @magic_number)
end
end
2
Popular in Challenges
Took me a minute to remember my binary math :smile: :grimacing:..
import Bitwise
__DIR__
|> Path.join("puzzle.txt")
|> File.strea...
New
This topic is about Day 6 of the Advent of Code 2021.
We have a private leaderboard (shared with users of Erlang Forums ):
https://adve...
New
Since I started using Elixir, I have benefited greatly from being able to study various open-source projects. The codebase of LiveBook, i...
New
This topic is about Day 7 of the Advent of Code 2020 .
Thanks to @egze, we have a private leaderboard:
https://adventofcode.com/2020/le...
New
This topic is about Day 18 of the Advent of Code 2021.
We have a private leaderboard (shared with users of Erlang Forums):
https://adve...
New
This topic is about Day 16 of the Advent of Code 2020 .
Thanks to @egze, we have a private leaderboard:
https://adventofcode.com/2020/l...
New
Just did part 1. Part 2 seems to be demanding too much of my reading time so will get to that after I am done with some chores.
Oh here ...
New
Hello everyone,
I’m a new in elexir and functional language. I’m trying to implement Websocket interraction with server.
On first layer...
New
Note: This topic is to talk about Day 13 of the Advent of Code 2019.
There is a private leaderboard for elixirforum members. You can joi...
New
Thought I’d kick today’s thread off!
Parsing
Enum rocks, so most of my code was actually in parsing input.
▶ Preprocessing input
Part 1...
New
Other popular topics
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
Hi everyone,
One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








