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
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
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,...
New
Here is my solution for day 2 of Advent of Code:
https://github.com/bjorng/advent-of-code/blob/main/2024/day02/lib/day02.ex
New
I have 2 arrays: a1 can be any combination of value or nil like that
a1 = [1,nil,3]
and array 2 the same
a2 = [4,2, nil]
How do I com...
New
This is my second year doing AoC in Elixir and my first year doing it with Livebook.
When I was doing just plain Elixir I usually set up...
New
Note by the Moderators: This topic is to talk about Day 6 of the Advent of Code.
For general discussion about the Advent of Code 2018 an...
New
Note: This topic is to talk about Day 4 of the Advent of Code 2019.
There is a private leaderboard for elixirforum members. You can join...
New
This topic is about Day 1 of the Advent of Code 2021.
We have a private leaderboard (shared with users of Erlang Forums):
https://adven...
New
part 1:
https://github.com/rugyoga/aoc2021/blob/main/day8.exs
part 2:
https://github.com/rugyoga/aoc2021/blob/main/day8b.exs
New
Note by the Moderators: This topic is for general discussion about the Advent of Code 2018.
To prevent people from being spoiled about s...
New
Ok, that was a rough one today.
I haven’t found a way to improve the algorithm further. Part 1 runs in .5 seconds, Part 2 in ~ 5 minutes...
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
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
Hello everyone,
I try to use an Javascript Event Handler in my root.html.leex file.
Therefore I created a function in the app.js file: ...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Hi all,
I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage.
I’m trying to use Postgres...
New
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
Hello!
Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something…
Haskell reminds me of Java, and e...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
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









