
Advent of Code 2019 - scottdw
https://adventofcode.com/2019
======
aquova
Many of the comments are about the event as a whole, but I'd like to commend
the author for the day 1 puzzle, which I think is very cleverly written. Many
people (including myself) use these as an opportunity to try out learning a
new language, and the first puzzle does a good job of making sure you know
enough basic operations for some of the puzzles coming up. The puzzle itself
wasn't very difficult, you could do it by hand if you really wanted to, but it
required you to know how to read and parse lines in a file, handle compound
data structures, iterate through, and perform basic operations (floor, casting
strings to ints, etc). I thought it was really well done, and creates the
basic knowledge for the puzzles ahead.

~~~
melling
Learning new environments can be painful so it’s good it starts off easy.

I’m trying to solve them with Swift Playgrounds on the iPad, for example. And
I can’t figure out how to create a simple text file for the data.

~~~
melling
I solved the first part using the examples. Swift is nice.

    
    
       func calcFuel(_ mass:Int) -> Int {mass / 3 - 2}
    
       let z0 = massList.map(calcFuel).reduce(0, +)
    

or simply ...

    
    
       let z1 = massList.map({$0 / 3 - 2}).reduce(0, +)
    

Any idea how to read the data on the iPad?

~~~
chii
i just copy/pasted the data into the source instead of dealing with IO.

~~~
melling
I had to create the plain text input file in iCloud with my Mac then insert it
(Big +, third option) in the iPad’s Swift Playground. Need a text app that
will save to Files for a complete iPad solution. Also, a Swift Playground bug
reverted my final solution to the code from my first few minutes, losing my
code. That was frustrating...

Anyway, a complete Swift Playground on iPad solution:

    
    
       import UIKit
    
       let path = Bundle.main.url(forResource: "input01", withExtension: "txt")
       var text = try String(contentsOf: path!, encoding: .utf8)
    
       let massList:[Int] = text.components(separatedBy: .whitespacesAndNewlines).compactMap({Int($0)})
    
       let z1 = massList.map({$0 / 3 - 2}).reduce(0, +)
       print("\(z1)")

~~~
brantonb
You can option+tap a link in Safari to download to Files. Hold down the
command key to see available shortcuts.

------
messe
Self promotion, but as this is my first year doing advent of code I'm solving
all of the problems using awk[1], the solutions will be published here[2]

[1]: [https://man.openbsd.org/awk](https://man.openbsd.org/awk)

[2]: [https://jo.ie/advent-of-awk-2019.html](https://jo.ie/advent-of-
awk-2019.html)

~~~
bewuethr
I've used awk for one year of Advent of Code:
[https://github.com/bewuethr/advent-of-
code/tree/master/2016](https://github.com/bewuethr/advent-of-
code/tree/master/2016)

Some problems feel like they were designed to be solved in awk, like the
assembly style ones. Others, not so much... But it was great fun overall and I
learned a lot about awk.

------
thethirdone
I was doing a little of catching up on older problems to improve my speed to
get on the leaderboard and I found that the fastest way to finish one problem
was to use oeis.

After seeing the problem [0], I didn't immediately think to use oeis because
the manhatten distance of a spiral is pretty easy to code or do by hand. The
second stage has a harder sequence though. It prompted me to check oeis and I
easily got the answer [2] within a minute of checking.

Looking back at the first stage, I found a sequence for it [1] and PARI/GP
code i could run to answer the question. If I had used oeis immediately I
would have a solution to both phases in 2 minutes which would be the fastest
on the old leaderboard for the problem [3].

[0]:[https://adventofcode.com/2017/day/3](https://adventofcode.com/2017/day/3)

[1]:[https://oeis.org/A214526](https://oeis.org/A214526)

[2]:[https://oeis.org/A141481](https://oeis.org/A141481)

[3]:[https://adventofcode.com/2017/leaderboard/day/3](https://adventofcode.com/2017/leaderboard/day/3)

~~~
loeg
I had plenty of 20-20 hindsight about faster ways to have solved puzzles in
the past. I don't know if I was ever #1 on any day on either star. I think I
might've been top 10, on one star, of one day, _once_.

------
nabraham
Eric, the author, says he won't accept any puzzle submissions because of
attribution and legal issues. This seems like the wrong outcome for people who
want to make the site better but don't want credit, compensation, or
attribution.

Has anyone seen a site using an IP assignment agreement which is the
equivalent of "take my work, I don't want credit, and it's just for your
site"?

The Creative Commons CC0 license comes closest, but one could scrape those
puzzles and create a competing site, which I'd guess Eric wants to avoid.

~~~
inerte
“your site” is really complicated. Who is “you”, person, website or the
company? If it’s the person can they transfer the rights? What happens if they
die? If they donate the estate? If they get hired or contracted? If the
website expands scope or changes in any way?

~~~
nabraham
"You" would be the company, and the submitter would assign all the rights to
it. Interestingly, I looked and couldn't find any terms of service or company
name.

------
forrestthewoods
Last year was my first year and I loved every second of it.

I strongly recommend using AoC as a tool to help learn a new language. Many
people, myself included, use it to learn Rust.

The best part about AoC is the community. Everyone is super helpful and kind.
The daily Reddit thread has solutions in every language under the sun.

My better half is a designer and is going to participate this year to help
learn JavaScript.

------
dross
This is my first year. As I missed the start time I created an event to remind
me and published it for anyone else who'd wish to subscribe.
[https://calendar.google.com/event?action=TEMPLATE&tmeid=M203...](https://calendar.google.com/event?action=TEMPLATE&tmeid=M203MTA1Yjdib2RndHBrNm51ZWU0Njd2bWVfMjAxOTEyMDFUMDUwMDAwWiBkYWxlLnYucm9zc0Bt&tmsrc=dale.v.ross%40gmail.com&scp=ALL)

Looking forward to the fun, the stress and the eventual euphoria.

~~~
WrtCdEvrydy
Could not find the requested event...

------
evenh
An alternative with daily articles across a range of topics:
[https://news.ycombinator.com/item?id=21675200](https://news.ycombinator.com/item?id=21675200)

------
dom96
This event is a really nice way to try out new programming languages. You can
easily find many people doing the challenges in various languages and
communities coming together to work through the problems together. It’s also
very interesting seeing how each person solves the problem in their favourite
language.

For example, here is the Nim communities effort: [https://forum.nim-
lang.org/t/5588](https://forum.nim-lang.org/t/5588)

------
Barrin92
Always enjoy doing these but there was one last year that nearly broke me. I
think it was day15. It was the worst combination of mind-numbing coding and
horribly hard to debug special cases. It was purely convoluted with very
little to think about which makes for the worst kind of puzzles

~~~
AdeptusAquinas
That one wiped me out for a week too, and caused borderline psychological
problems.

Ultimately though I realised that if I followed the description word by word,
and made no assumptions, then I got the right solution. Still, a nightmare:
you could pass all the examples, or even some alternate real sample data, and
still get it wrong if you got the ordering slightly incorrect.

~~~
loeg
Yeah, it's really frustrating when the text summary is vague and
underspecified. It makes it hard to understand exactly the result the author
is looking for, which isn't the fun kind of puzzle.

~~~
AdeptusAquinas
I think the problem was it _felt_ vague and under specified. But when I read
it closely enough, it actually was exactly specific.

------
sunaden
If someone is interested in the previous years of Advent of Code they are
available as notebooks in Peter Norvig's pytudes repository:
[https://github.com/norvig/pytudes](https://github.com/norvig/pytudes)

~~~
narimiran
Thank you very much for this!

I was aware of Norvig's 2016 AoC solutions, but I thought he never did any of
the newer editions. I know what I'll be reading today :)

------
qznc
I'm trying to use J and still struggle with the second part of day 1. Any
other J users?

~~~
JaumeGreen
I have found a solution someone posted [0]

It looks similar to what I though I had to write, but I will have to reread it
and the documentation to understand it well.

And day 2 seems a bit too complex with my meager J knowledge. OTOH with the J
interpreter for android and its terseness it seems the most suited language
for programming on a phone, so I will probably stick to it.

[0]
[https://www.reddit.com/r/adventofcode/comments/e4axxe/2019_d...](https://www.reddit.com/r/adventofcode/comments/e4axxe/2019_day_1_solutions/f9dmskw/)

~~~
qznc
I'm actually surprise how many J/APL/K/Q solutions get posted there already.
It seems to be popular among golfers.

------
sergiotapia
I’m finally going to attempt it this year. Using elixir here:
[https://github.com/sergiotapia/advent-of-
code-2019-elixir](https://github.com/sergiotapia/advent-of-code-2019-elixir)

~~~
ulucs
Last year I started out using elixir, but I got filtered due to the goblins...

~~~
sergiotapia
What does this mean?

~~~
Jtsummers
Probably Day 15 [0] from last year. It was challenging, especially because
there were so many rules to implement (in a short time). A slight misreading
of the rules would let you pass all the provided examples, but fail on the
real input.

[0]
[https://adventofcode.com/2018/day/15](https://adventofcode.com/2018/day/15)

~~~
tialaramex
Idiot-proofing is hard. Figuring out everything people will get wrong is the
only reliable way to ensure people don't, but that takes more insight than is
needed to set and solve problems correctly.

~~~
Jtsummers
No doubt. I wasn't really complaining, but that was the one that seemed to
cause the most headaches last year. And the text had the problem fully
specified, there really was no good way to make it better other than perhaps a
different presentation (also a hard problem) or a few extra test cases to
tease out those potential misreadings. But you can't catch every error for the
participants, coming up with tests is part of the challenge.

------
dang
Already discussed at
[https://news.ycombinator.com/item?id=21660423](https://news.ycombinator.com/item?id=21660423),
but since it starts today we'll give it another go.

------
jammygit
These are daily programming puzzles? How long do they take on average?

Also, I know somebody who is just starting out at coding. Would it be too hard
for them? They are brand new, learning about loops

~~~
sergiotapia
For someone just starting out they would get stuck on this very first problem,
it involves recursion. People 'get' recursion, but coding it is something
different.

~~~
gbear605
It doesn’t need recursion, you can do a while(round(x/3)-2 > 0) type thing,
but recursion is simpler.

~~~
tialaramex
Nothing 'needs' recursion, it's always equivalent to an iterative solution. In
some languages a recursive solution is more natural and may perform better.

~~~
moron4hire
I know of languages that can automatically convert some kinds of recursive
code into the iterative equivalent automatically, but I've never seen one that
can make the recursive version faster than an iterative equivalent.

------
donatj
I always have a ton of fun with these sorts of things. I always wonder how
they come up with these sorts of puzzles. That's not a skill I have.

~~~
dazwah
There's a great talk by Eric Wastl that describes how he does it:
[https://www.youtube.com/watch?v=bS9882S0ZHs](https://www.youtube.com/watch?v=bS9882S0ZHs)

------
Kinrany
The third puzzle mentions Halt and Catch Fire, a brilliant TV show about
innovation and the lives of the (fictional) people behind it.

~~~
daveFNbuck
It actually references the thing that the show is named after. If you click on
the link, it's not about the show.

------
janvdberg
Advent of Code is a lot of fun! Last year I wrote a little bit about all the
different languages/approaches people use to solve the challenges:
[https://j11g.com/2018/12/03/advent-of-
code/](https://j11g.com/2018/12/03/advent-of-code/)

------
sircastor
I went to bed before trying it last night, but couldn't sleep. So I did the
day one problem early this morning. It was fun, and went quicker than I
thought. I guess I must've improved from last year.

------
LandR
Day 2 part 2, what is it actually asking?

I can't tell from the description what the actual puzzle is...

Is it that I need to generate a program that generates the output 19690720
when run through the function that was written in part 1?

~~~
eachro
In the first problem they told you what numbers to put in position 1 and 2. In
the second problem you want to find the specific numbers for position 1 and 2
that yield the desired output.

~~~
LandR
Ah ok, thanks!

My reading comprehension obviously needs some work :P

------
andonisus
Here is my solution to Day 1 Part 2 in Go:
[https://play.golang.com/p/SQsCdTXk_YH](https://play.golang.com/p/SQsCdTXk_YH)

------
devit
One line bash solutions:
[https://pastebin.com/QnKJEXxt](https://pastebin.com/QnKJEXxt)

~~~
noname120
You can do shorter in languages with functional constructs. For example
Python:

    
    
      sum(map(lambda x: x // 3 - 2, numbers))

~~~
the-dude
Why is that a double slash?

~~~
michaelmarkell
It rounds down the quotient

~~~
the-dude
How intuitive. But thanks anyway.

~~~
jacobolus
In Python 2, floor division is the default for integer arguments and exact (to
within machine precision) division the default for floating point arguments,
but this caused a lot of unnecessary confusion: new users were surprised that
3.0/2.0 == 1.5, but 3/2 == 1.

Thus for Python 3 the new // operator was added for explicit floor division
(which is often quite useful in its own right), leaving the / operator to
always return an exact (to machine precision) floating point result, even with
integer arguments.

cf.
[https://en.wikipedia.org/wiki/Principle_of_least_astonishmen...](https://en.wikipedia.org/wiki/Principle_of_least_astonishment)

------
ph2082
Jeez, tension is real. Specially if you are thinking about cracking top 100.
Competition is a b __ __.

Lot of fun though.

~~~
mathw
That's only possible if you live in the correct time zone, too.

------
sidcool
Does anybody know how the scoring system works for AoC?

~~~
vpzom
See
[https://adventofcode.com/2019/leaderboard](https://adventofcode.com/2019/leaderboard)

------
GaryNumanVevo
oh lord, I just started writing a GCODE motion planner, I forgot about AoC.

------
dbetteridge
Would appreciate feedback on my Go code!

I'm sure theres a better way to approach some of these.

[https://danielbetteridge.com/advent-of-code-
day-1/](https://danielbetteridge.com/advent-of-code-day-1/)

------
coolreader18
Wow, what a great distraction for students to have during finals season! ;)

------
malloreon
I like everything about this except the name.

the word advent is religious.

~~~
p1necone
And?

~~~
malloreon
if this is a religious project, it should be clearly marked as such.

if it's not, why not use a nonreligious word?

~~~
mpcjanssen
Because advent is a common term for the 4 weeks before Christmas even in non
religious contexts. And that is how it's used in this non religious project.

