# Anyone planning on solving Advent of Code 2020?

**URL:** <https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560>\
**Category:** General Dev Chat\
**Tags:** programming-challenge, algorithms\
**Created:** [30 November 2020 15:42 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560 "2020-11-30T15:42:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mafinar](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mafinar/32/723_2.png) [@mafinar](https://forum.devtalk.com/u/mafinar)\
**Post date:** [30 November 2020 15:42 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/1 "2020-11-30T15:42:36Z")

</div>

I always start with excitement and then get busy on 9/10th day. This year, like the year before this, and the year before that, I intend to be regular. My language of choice this year would be Elixir (and/or Dart depending on my mood on the day). Anyone else going to solve Advent of Code puzzles starting tomorrow?

Waiting for the first one to unlock 😉 [https://adventofcode.com/](https://adventofcode.com/)

---

<div class="post-metadata">

**Author:** ![bot](https://forum.devtalk.com/user_avatar/forum.devtalk.com/bot/32/1112_2.png) [@bot](https://forum.devtalk.com/u/bot)\
**Post date:** [30 November 2020 15:56 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/2 "2020-11-30T15:56:03Z")

</div>

> <https://twitter.com/dev_talk/status/1333439657858699264>

[Share link](https://twitter.com/intent/tweet?url=https://twitter.com/dev_talk/status/1333439657858699264&text=Anyone%20planning%20on%20solving%20Advent%20of%20Code%202020?%20%23algorithms%20%23programming-challenge) for this tweet.

---

<div class="post-metadata">

**Author:** ![gianthamster](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/g/e68b1a/32.png) [@gianthamster](https://forum.devtalk.com/u/gianthamster)\
**Post date:** [30 November 2020 18:00 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/3 "2020-11-30T18:00:42Z")

</div>

I remember when that first came out – I was still living on the east coast and ended up staying up past midnight every night for three weeks straight. Now I won’t touch it, even though I’m on the west coast and the puzzles come out at 9:00 – I’m too competitive to ignore the leaderboard and I just can’t risk my sleep!

Be sure to brush up on your regex!

---

<div class="post-metadata">

**Author:** ![rgd43](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/r/df705f/32.png) [@rgd43](https://forum.devtalk.com/u/rgd43)\
**Post date:** [30 November 2020 19:04 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/4 "2020-11-30T19:04:05Z")

</div>

Is it much more difficult if attempting in a “manual memory” kind of language like Rust?

---

<div class="post-metadata">

**Author:** ![mafinar](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mafinar/32/723_2.png) [@mafinar](https://forum.devtalk.com/u/mafinar)\
**Post date:** [30 November 2020 19:12 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/5 "2020-11-30T19:12:49Z")

</div>

I have a friend who solves these things blazingly fast with C and C++, so I’m not sure if it’s that much more difficult, I guess it all depends on how much practice one has in a language?

There were some problems I found a little hard to solve in Elixir, sometimes I got into reduce-hell (my fault), and once I just used :digraph

@rgd43 if you do attempt to solve it with a “manual memory” language do let us know of your experience 🙂

@gianthamster that explains why I am suddenly so proficient with regex during the end of the year 😃

---

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.devtalk.com/user_avatar/forum.devtalk.com/astonj/32/7_2.png) [@AstonJ](https://forum.devtalk.com/u/AstonJ)\
**Post date:** [30 November 2020 19:55 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/6 "2020-11-30T19:55:44Z")

</div>

> [@gianthamster](#):
>
> Be sure to brush up on your regex!

I would be lost without sites like [rubular.com](http://rubular.com) 🙈 😂

> [@rgd43](#):
>
> Is it much more difficult if attempting in a “manual memory” kind of language like Rust?

Do it RDT’er! 🤓

> [@mafinar](#):
>
> My language of choice this year would be Elixir (and/or Dart depending on my mood on the day)

Let us know how you get on @mafinar 👍

---

<div class="post-metadata">

**Author:** ![herminiotorres](https://forum.devtalk.com/user_avatar/forum.devtalk.com/herminiotorres/32/570_2.png) [@herminiotorres](https://forum.devtalk.com/u/herminiotorres)\
**Post date:** [1 December 2020 00:21 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/7 "2020-12-01T00:21:54Z")

</div>

I thought to participate this year(btw it will be my first time), and I will use elixir as my main language on the advent of code! o/

---

<div class="post-metadata">

**Author:** ![mafinar](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mafinar/32/723_2.png) [@mafinar](https://forum.devtalk.com/u/mafinar)\
**Post date:** [1 December 2020 14:15 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/8 "2020-12-01T14:15:03Z")

</div>

Here’s the first one:

> <https://github.com/code-shoily/advent_of_code/blob/master/lib/2020/day_1.ex>

---

<div class="post-metadata">

**Author:** ![finner](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/f/a4c791/32.png) [@finner](https://forum.devtalk.com/u/finner)\
**Post date:** [1 December 2020 14:58 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/9 "2020-12-01T14:58:31Z")

</div>

thanks @AstonJ - I never heard of [rubular.com](http://rubular.com/)

I use [regex101](https://regex101.com/)

---

<div class="post-metadata">

**Author:** ![gianthamster](https://forum.devtalk.com/letter_avatar_proxy/v4/letter/g/e68b1a/32.png) [@gianthamster](https://forum.devtalk.com/u/gianthamster)\
**Post date:** [1 December 2020 16:56 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/10 "2020-12-01T16:56:47Z")

</div>

That’s a very pretty use of Enum.reduce\_while, and I love how you’ve set up the entire project. I’m always hacking this sort of thing out in one-off scripts.

Going to keep following this, I think – it looks like I’m going to learn some things.

---

<div class="post-metadata">

**Author:** ![mafinar](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mafinar/32/723_2.png) [@mafinar](https://forum.devtalk.com/u/mafinar)\
**Post date:** [1 December 2020 19:36 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/11 "2020-12-01T19:36:29Z")

</div>

Thanks. I tend to be very lazy and at the same time am very picky about code consistency. So figured, a little generator won’t hurt. Yeah maybe I’ll keep posting my hiccups and solutions here, most of the time I did Advent of Code solo and ended up bored after a week or so, this time probably discussions and help from y’all would help me learn things and stay motivated 🙂

---

<div class="post-metadata">

**Author:** ![mafinar](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mafinar/32/723_2.png) [@mafinar](https://forum.devtalk.com/u/mafinar)\
**Post date:** [2 December 2020 06:17 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/12 "2020-12-02T06:17:16Z")

</div>

This is today’s (Day 2) one. `Regex` started to appear.

> <https://github.com/code-shoily/advent_of_code/blob/master/lib/2020/day_2.ex>

---

<div class="post-metadata">

**Author:** ![Rainer](https://forum.devtalk.com/user_avatar/forum.devtalk.com/rainer/32/553_2.png) [@Rainer](https://forum.devtalk.com/u/Rainer)\
**Post date:** [2 December 2020 18:08 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/13 "2020-12-02T18:08:55Z")

</div>

As I’m trying to learn Erlang, I did the first one, but I don’t think I’ll continue as it takes too much time 😉

```auto
-module(day1).
-export([run/0]).

run()->
    process_list(load_file("day1input.txt")).

load_file(Filename)->
    {ok, Binary} = file:read_file(Filename),
    StringContent = unicode:characters_to_list(Binary),
    [element(1, string:to_integer(Substr)) || Substr <- string:tokens(StringContent, "\n")]. 

process_list([H | T])->
    case process_sublist(H, T) of
        notfound -> process_list(T);
        {found, X, Y, Result} -> {X, Y, Result}
    end;
process_list([])->
    notfound.

process_sublist(Elem, [H | T]) ->
    case is_solution(Elem, H) of
        true -> {found, Elem, H, H*Elem};
        false -> process_sublist(Elem, T)
    end;
process_sublist(_, []) ->
    notfound.

is_solution(X, Y) ->
    X + Y =:= 2020.

```

---

<div class="post-metadata">

**Author:** ![mafinar](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mafinar/32/723_2.png) [@mafinar](https://forum.devtalk.com/u/mafinar)\
**Post date:** [2 December 2020 18:45 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/14 "2020-12-02T18:45:43Z")

</div>

> [@Rainer](#):
>
> As I’m trying to learn Erlang

Me too. The book has just arrived, but you already know that 😉 … I think I will pass on AoC with Erlang this year. This is the first time I intend to learn a language slowly and know the theories before getting my hands dirty 🙂

---

<div class="post-metadata">

**Author:** ![mafinar](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mafinar/32/723_2.png) [@mafinar](https://forum.devtalk.com/u/mafinar)\
**Post date:** [3 December 2020 06:33 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/15 "2020-12-03T06:33:26Z")

</div>

Solution of day 3 in Elixir.

Suggestion Needed: I have a gut feeling I could make the code beautiful with pattern matching and avoiding the map to matrix transformation. If any of you did it that way or like to give me ideas on it that’d be appreciated \<3

> <https://github.com/code-shoily/advent_of_code/blob/master/lib/2020/day_3.ex>

---

<div class="post-metadata">

**Author:** ![Rainer](https://forum.devtalk.com/user_avatar/forum.devtalk.com/rainer/32/553_2.png) [@Rainer](https://forum.devtalk.com/u/Rainer)\
**Post date:** [3 December 2020 19:32 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/16 "2020-12-03T19:32:31Z")

</div>

After my first version of Day1 I wantet to try another approach with much less code, it became a one-liner 😉

```auto
-module(day1).
-export([run/0]).

run()->
    process_list(load_file("day1input.txt")).

load_file(Filename)->
    {ok, Binary} = file:read_file(Filename),
    StringContent = unicode:characters_to_list(Binary),
    [element(1, string:to_integer(Substr)) || Substr <- string:tokens(StringContent, "\n")]. 

process_list(L)->
    [{X, Y, X*Y} || X <- L, Y <- L, X + Y =:= 2020].

```

---

<div class="post-metadata">

**Author:** ![mafinar](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mafinar/32/723_2.png) [@mafinar](https://forum.devtalk.com/u/mafinar)\
**Post date:** [3 December 2020 19:34 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/17 "2020-12-03T19:34:00Z")

</div>

I miss Erlang/Python style list comprehension in Elixir.

---

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.devtalk.com/user_avatar/forum.devtalk.com/astonj/32/7_2.png) [@AstonJ](https://forum.devtalk.com/u/AstonJ)\
**Post date:** [3 December 2020 19:41 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/18 "2020-12-03T19:41:05Z")

</div>

That’s making me want to get back in to reading the book!

Soon I hope 🤓📙

---

<div class="post-metadata">

**Author:** ![Rainer](https://forum.devtalk.com/user_avatar/forum.devtalk.com/rainer/32/553_2.png) [@Rainer](https://forum.devtalk.com/u/Rainer)\
**Post date:** [4 December 2020 05:19 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/19 "2020-12-04T05:19:40Z")

</div>

Despite having no time, I did day 2, as it’s quite addictive 😃  
Biggest problem was that i had no idea how to parse a string in erlang 🤷‍♂️  
But now I’m quite satisfied with my solution 🙂

```auto
-module(day2).
-export([part1/0, part2/0]).

part1()->
    ParsedLines = load_file("day2input.txt"),
    ValidLines = [Line || Line <- ParsedLines, is_valid1(Line)],
    length(ValidLines).

part2()->
    ParsedLines = load_file("day2input.txt"),
    ValidLines = [Line || Line <- ParsedLines, is_valid2(Line)],
    length(ValidLines).

is_valid1({From, To, Char, Pw}) ->
    N = length([[X] || X <- Pw, [X] =:= Char]),
    (N >= From) and (N =< To).

is_valid2({Idx1, Idx2, Char, Pw}) ->
    (string:slice(Pw, Idx1-1, 1) =:= Char) xor (string:slice(Pw, Idx2-1, 1) =:= Char).

load_file(Filename)->
    {ok, Binary} = file:read_file(Filename),
    StringContent = unicode:characters_to_list(Binary),
    [parse(Line) || Line <- string:tokens(StringContent, "\n")]. 

parse(Line)->
    {ok, MP} = re:compile("([0-9]+)-([0-9]+) ([a-z]): ([a-z]+)"),
    {_,[_,From, To, Char, Pw]} = re:run(Line, MP),
    {extract_num(Line, From), extract_num(Line, To), extract_str(Line, Char), extract_str(Line, Pw)}.

extract_str(String, {Start, End})->
    string:slice(String, Start, End).

extract_num(String, {Start, End})->
    Str = string:slice(String, Start, End),
    {Int, _} = string:to_integer(Str),
    Int.

```

---

<div class="post-metadata">

**Author:** ![mafinar](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mafinar/32/723_2.png) [@mafinar](https://forum.devtalk.com/u/mafinar)\
**Post date:** [4 December 2020 06:53 UTC](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560/20 "2020-12-04T06:53:31Z")

</div>

Today’s one was boring 😕

> <https://github.com/code-shoily/advent_of_code/blob/master/lib/2020/day_4.ex>

[Next page](https://forum.devtalk.com/t/anyone-planning-on-solving-advent-of-code-2020/4560.md?page=2)
