hvnsweeting

hvnsweeting

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

Showing Posts 1 to 7

hvnsweeting

hvnsweeting OP

Merry Christmas everyone :tada:

bjorng

bjorng

Erlang Core Team

Merry Christmas everyone!

Here is my solution.

Papey

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
Hallski

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
lud

lud

My code is a bit long. Is started to implement each step separately because the part 1 text gave all what there is to be done to solve the problem, so I expected a part 2 this year.

Last year was my first AoC and I found it really hard. Day 25 was about finding your way in a spaceship, on a map that could not fit on a grid (if you do east -> south -> west -> north you could be somewhere else than your starting point), while carrying objects to change your weight to open a gate. And doing so not directly in code, but by inputting plaintext commands to an intcode program.

And this year you have to increment a number until rem(the_number * 7, 20_201_227) is equal to your input. Oh and the number is not like 20020024857472872873874… mine was 8.

I have to admit that I am kind of disappointed. I expected to struggle way more.

But still, it was fun anyway, and I learned new techniques along the way, by myself and by looking at the code posted here.

Merry Christmas to you all.

skovmand

skovmand

I was so tired on D25 that I stubbornly held on to some ideas that performed pretty badly. I got the answer, but was pretty dissatisfied. However today I refactored it to be quite nice. I love Stream.iterate :heart:

Merry christmas everyone.

https://github.com/skovmand/advent_of_code_2020/blob/main/lib/advent20/25_combo_breaker.ex

code-shoily

code-shoily

Here’s mine: https://twitter.com/mafinar/status/1343609407201042436 couldn’t resist fitting it in a tweet.

defmodule Day25 do
  def run(a, b), do: t(1, a, lp(1, b, 1))

  def lp(x, k, s), do: ((r = t1(x, 7)) == k && s) || lp(r, k, s + 1)

  def t(x, p, s), do: (s == 0 && x) || t(t1(x, p), p, s - 1)
  def t1(x, p), do: rem(x * p, 20_201_227)
end
— All posts loaded —

Where Next? Top

Trending in Challenges Top

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
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
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews