12
votes
Day 4: Secure Container
Today's problem description: https://adventofcode.com/2019/day/4
Join the Tildes private leaderboard! You can do that on this page, by entering join code 730956-de85ce0c
.
Please post your solutions in your own top-level comment. Here's a template you can copy-paste into your comment to format it nicely, with the code collapsed by default inside an expandable section with syntax highlighting (you can replace python
with any of the "short names" listed in this page of supported languages):
<details>
<summary>Part 1</summary>
```python
Your code here.
```
</details>
Join the leaderboard using code
730956-de85ce0c
!This was, to me, the easiest challenge so far. Here's a simple, dirty solution in Javascript.
Part 1
Part 2
Day 4 in Befunge
Day 4 took a long time, partially because I had to fix some kinks in my interpreter so it functioned more accurately according to the spec, so I could feed my code into an ultra fast Befunge compiler and get the answer in a reasonable amount of time. The other reason it took a while was because I initially had my code only check in 3 sections, so
[56][34][11]
would have been valid, and I had a hard to see error with end of number detection. But I fixed it all eventually. I haven't completed part 2 yet.Part 1
For this to complete in any reasonable amount of time, I recommend BefunExec to run it.
Part 2
This one was almost trivial to implement, and I ended up doing it on my phone during a break at work. I'll have to rewrite it in Julia once I'll be back home, though.
Part 1
Part 2
I'm trying out the advent challenges as an opportunity to learn go. This is the first day that my code is clean enough that I'm not actively embarrassed by it.
Part 1
Whew, I thought it was almost getting too hard for me with yesterday's challenge, but this one seems much easier. Here's a quick and dirty
awk
implementation; might clean it up a bit later.Part 1
Part 2
The same as part 1, except with line 6 extended to this:
Yes, I meant it when I said quick and dirty.
PHP
functions.php
part-1.php
part-2.php
Rewrited function findBi()
Language: Rust
As everyone else is saying, this one was much easier. I felt that there was probably a pure math way to solve this, but I couldn't quite work it out and I don't think it would work for arbitrary ranges. Anyway, the solution:
Solution
This one felt significantly easier. Maybe because I was actually trying to concentrate and doing it fast (seeing the top-100 swoosh by, of course). The main difficulty seems to have been getting the digits but it's almost a programming exercise cliche.
I hard-coded almost all of it, expecting it to bite me in the ass for the second star (varying number of digits, etc) but it seems for the second star just copy-pasting it manually was also the fastest way. Anyway, couldn't help but clean it up a tiny little bit.
Part 1
Part 2
Part of me likes how simple these exercises are (especially that the outcome is a single number so you don't have to fiddle with formatting), part of me would love there to be a higher emphasis on optimization challenges (though that would limit the amount of possible languages you can use). I heard this will get harder so I assume the later ones might simply run too long if you don't optimize?
After days 2 and 3 it's nice to see a simpler one again to take a breather (even as excited as I am to revisit the VM puzzle).
Part 1, Crystal/Ruby
Part 2
Same as before, except I refactored the
check_adjacency
bit with an improved versionI think that my code always tends towards "dumpster fire that also happens to be correct" so in the future I will probably try to focus on good code beyond strict correctness.
Part 2 is included as a module in the code, since the problem makes it very easy to add Part 2 to Part 1.
Parts 1/2, C++
This one was pretty easy on the first part, but the second part took some thinking (and guessing) to get right. Things started to fall into place once I realized it would be more readable and easier to understand if I split some of my increasingly ugly conditional expressions into multiple if statements. I've added comments this time, but I may have overcompensated for my past uncommented spaghetti.
I am also a little miffed that these release right at my bed time. It's tough to make it on the leaderboard when I often don't have a chance to really work on them until the following afternoon!
Parts 1&2, Python 3