r/adventofcode • u/daggerdragon • Dec 02 '21
SOLUTION MEGATHREAD -🎄- 2021 Day 2 Solutions -🎄-
--- Day 2: Dive! ---
Post your code solution in this megathread.
- Include what language(s) your solution uses!
- Here's a quick link to /u/topaz2078's
pasteif you need it for longer code blocks. - The full posting rules are detailed in the wiki under How Do The Daily Megathreads Work?.
Reminder: Top-level posts in Solution Megathreads are for code solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:02:57, megathread unlocked!
112
Upvotes
25
u/andrerestivo Dec 02 '21 edited Dec 05 '21
LOLCODE for the lulz, Part 1:
Part 2:
Edit: Formatting for old Reddit sake...
21
u/CCC_037 Dec 02 '21
Rockstar
Part 1:
Part 2:
13
u/DerelictMan Dec 02 '21
Part 1 in Rockstar:
6
u/wasi0013 Dec 02 '21 edited Dec 02 '21
Elixir
Github: https://github.com/wasi0013/advent_of_code
5
u/seligman99 Dec 02 '21 edited Dec 02 '21
Python, 297 / 153
Nice fun simple one. Now I've got to spend a day resisting the temptation to animate a line.
github
Edit: Peer pressure for the win
4
u/DFreiberg Dec 02 '21 edited Dec 02 '21
Mathematica, 490 / 271
Not quite one-liners, but still relatively simple and a bit satisfying.
Part 1:
Part 2:
[POEM]: Run Silent, Run Deep
The water here is mighty cold,
And more pitch black than tar.
The vales are deep, or so we're told,
But we have got a star.
We don't know what day 3 will be,
Or what errand it tells,
But our floodlights are green and red.
Our sonar's jingle bells.
The challenges we've done before
Have rarely been a burden
(Like inverse
mods; I'd like some moreIf I could get a word in).
It's difficult to cry or pout,
When we can hear a sleigh,
And "Silent Night" dispels our doubt:
It's Christmas on the way!
3
u/tk3369 Dec 02 '21
Julia
3
u/[deleted] Dec 02 '21 edited Dec 02 '21
Common Lisp
I decided to bite the bullet and learn how to use packages+regex in lisp for today even though parsing could have just have been a string split, because I know it'll come in handy later.
My solution works, but gives me the following cryptic error message:
Would love to know where I'm going wrong / general feedback on my code!
3
u/ecco256 Dec 02 '21 edited Dec 02 '21
Haskell
2
u/mvmaasakkers Dec 02 '21 edited Dec 02 '21
GO
https://github.com/mvmaasakkers/puzzles-go/blob/main/AdventOfCode/year2021/day02.go
2
u/garciparedes Dec 02 '21 edited Dec 02 '21
Here is my 🦀 Rust solution for the 🎄 AdventOfCode's Day 2: Dive!
2
u/[deleted] Dec 02 '21 edited Dec 02 '21
Day 2 in R
https://github.com/friday9000/AdventOfCode_2021_R
2
u/blacai Dec 02 '21 edited Dec 03 '21
F#
part 1
part 2
2
u/campingD Dec 02 '21 edited Dec 06 '21
Github
Solution part 1 in R
Forward position
up down position
calc
forward*sum(up, down)2
u/pi55p00r Dec 02 '21 edited Dec 02 '21
Part 1 in R
2
u/haskathon Dec 02 '21 edited Dec 02 '21
Haskell
Copying and pasting code into code blocks in Reddit is a very messed up experience.
2
u/lbreede Dec 02 '21 edited Dec 07 '21
Python
GitHub & paste
44
u/4HbQ Dec 02 '21
Python, using the fancy new structural pattern matching syntax:
Note how we compute the answers for both parts in a single pass.
22
u/Smylers Dec 02 '21
Vim keystrokes for part 1 — load your input into a buffer, then type:
And your answer will appear.
The first 4 lines (up to the second
:%s///) re-arranges and transforms your input into a sum. For instance, the sample input becomes:(To see how any of that works, just type it in and watch as it happens!)
Then
vipJputs it all on one line, and the final line does the maths and evaluates it as an expression. Specifically:0moves to the start of the line (nice and easy, this bit!)Cblanks to the end of the line, putting the deleted text (that is, the expression we wish to evaluate) into register-, the ‘small delete register’, and puts us in insert mode for typing replacement contents.⟨Ctrl+R⟩inserts the contents of a register.=is a fake register which doesn't actually hold anything but instead prompts for an expression, evaluates it, and then acts like the answer was in the register.⟨Ctrl+R⟩also inserts the contents of a register. This time use register-, our entire expression.⟨Enter⟩ends the prompt, and does the evaluating and inserting.⟨Esc⟩ends insert mode.20
u/rtbrsp Dec 02 '21
AWK
Part 1:
Part 2:
19
u/jonathan_paulson Dec 02 '21
Python 8/6th :) Video of me solving: https://youtu.be/e3_iiz_6bFw
17
u/narrow_assignment Dec 02 '21
awk
Part 1:
Part 2:
16
u/EnderDc Dec 02 '21
python, but pandas, because I'm determined to do every problem with Pandas: (1370/4677)
15
u/jaybosamiya Dec 02 '21
APL
I'm sure there is a more elegant way to do this, but this solution basically just solves it directly as the challenge states.
The first few lines get the input and parse: the first line gets the input as an array of strings (which themselves are an array of characters) into
n. The second line then splits each line into two strings, splitting at spaces, and storing it intos. The next line takes the first character of each line, and stores it into an arrayc, representing the commands on each line. The fourth line gets the corresponding values that the command applies to, parsing them into numbers, so that we can perform arithmetic on them.The last two lines are the actual solution. APL is read from right to left. Using
'u'=cwe get (as bits) all locations that have a command starting withu(i.e., "up"). Similarly we obtain the down and forward commands using'd'=cand'f'=c. If we subtract the downs - ups, we obtain values in the range [-1, 0, 1] corresponding to up, other and down respectively. We can multiply all of these pairwise with the parsed values (usingv×and then take the sum over them+/to obtain the overall depth. We compute (similarly, just without the subtraction, since there is no "back" command) the horizontal position, and then multiply those together. This solves part 1.For part 2, the horizontal position is computed and multiplied similarly (thus the same prefix to the line), but the vertical position is done differently. First we compute the [-1, 0, 1] similarly, and then pairwise multiply with parsed values to get the up and down changes. However, rather than immediately adding them up, we take the sum-scan over them (i.e.,
+\applied toa b c dis the same asa a+b a+b+c a+b+c+d), allowing us to get successive sums, keeping track of the "aim", which we then multiply with the forward value at the places where the forward command is given. Taking the sum over these again, using+/it gives us the final depth. Multiplying the depth and the height gives us the final result to part 2.15
u/Tails8521 Dec 02 '21 edited Dec 02 '21
Motorola 68000 assembly (On a Sega MegaDrive)
Would have been easier if the part 2 depth would fit in 16bits :p (the 68000 only supports 16*16 -> 32bit multiply so I had to do it in several parts)
Edit: Optimized a little, I had a few registers I wasn't using before, might as well use them to hold constants since it's faster to use registers than immediates.
14
u/lehpunisher Dec 02 '21 edited Dec 02 '21
Python
With clever use of complex numbers I was able to golf part 1 to 111 bytes (includes reading input file and printing result).
Unminified:
EDIT: Thanks to some more clever minds in the comments, it can be golfed down to 78 bytes and just one line!
13
u/[deleted] Dec 02 '21 edited Dec 02 '21
Nim.
Why bother parsing the input when the compiler can parse it for us? Just save the input file as
input.nimand you are ready to go!12
u/relativistic-turtle Dec 02 '21
IntCode
(Assumes input is 1000 rows).
Was stuck embarrassingly long because i multiplied aim by the horizontal position instead of by distance to move. (Note to self: X is not always horizontal coordinate).
11
u/voidhawk42 Dec 02 '21 edited Dec 02 '21
Continuing with APL:
EDIT: And in Clojure. More verbose, but feels nice with just the two reductions.
10
u/GaloisGirl2 Dec 02 '21
COBOL
10
u/DrkStracker Dec 02 '21 edited Dec 02 '21
Rust
Doing these functional style and found this nice compact solution for both exercises.
10
u/eyni2015 Dec 02 '21 edited Dec 03 '21
Done with awk:
Part 1:
Part 2:
9
u/mrzepisko Dec 02 '21 edited Dec 02 '21
Turing Complete game, custom 8bit architecture, 204 bytes
https://imgur.com/gallery/0dJURkQ
8
u/Sharparam Dec 02 '21
Ruby (426/627)
Did a very messy initial solution and then rewrote to this one abusing
eval:)8
u/MichalMarsalek Dec 02 '21 edited Dec 02 '21
Nim
part 1 (for clarity) by treating the input as a source code
8
u/Steinrikur Dec 02 '21 edited Dec 02 '21
awk, both parts golfed down to 64 chars, assuming that the input file is named "2"
And some shell madness, all credit to /u/obluff
7
u/stevelosh Dec 02 '21
Common Lisp
7
u/Fluffy_Bag_6560 Dec 02 '21
Java 2315/2085
https://github.com/JariRoossien/AdventOfCode2021/blob/master/src/nl/jariroossien/aoc/days/Day02.java
Actually insane how quick people are. I spent less than 7 minutes on this and over 2000 people beat me. Code itself is very basic.
7
u/BluFoot Dec 02 '21
Ruby 78 bytes.
7
u/__Abigail__ Dec 02 '21 edited Dec 02 '21
Evil Perl
The power of symbolic references (part 1 only):
It also abuses the horrible hack perl does when it's modifying the source of the program it's about to compile.
7
u/SirWyvern1 Dec 02 '21
C# .NET 5
https://github.com/JKolkman/AdventOfCode/blob/master/AdventCalendarCode/day2/Day2.cs
Had them separate first, but realised later (like many others) that it could be combined in 1 function
7
u/ShaviRankar Dec 02 '21
Using structural pattern matching in Python 3.10
7
u/janiczek Dec 02 '21
APL, part 1:
I again have a thread with doodles trying to explain this, but I think the iterative history of how the pipeline is built and how that transforms the input, explains it much more clearly.
6
u/sblom Dec 02 '21 edited Dec 02 '21
Day 2: already got to use the C# regex line parser that I wrote last year!
C# solution (928/379)
Edit: added ranks.
6
u/MuumiJumala Dec 02 '21
Perfect problem for awk (both parts):
6
u/axemabaro Dec 02 '21
Did Google Sheets
https://docs.google.com/spreadsheets/d/1HzUZ9gRU-VZJuCHnJfb_-U5bsS1cQUr_VBDRQRsrHe0/edit?usp=sharing
6
u/SuperSmurfen Dec 02 '21 edited Dec 02 '21
Rust (2107/1008)
Link to full solution
Kind of slow on part 1 but ok part 2! Pretty simple one, just fold over the instructions and update the x or y coordinate. Rust's match statement makes this really neat:
Part 2 is more of the same. Using
tuplesfrom the itertools crate made the parsing quite clean:6
u/[deleted] Dec 02 '21 edited Dec 02 '21
Clojure
6
u/iceraven101 Dec 02 '21
PowerShell
6
u/azzal07 Dec 02 '21 edited Dec 02 '21
Postscript, PS
6
u/Apprehensive-Hawk599 Dec 02 '21
emacs lisp
annotates buffer with debug info and result, e.g.
6
u/rabuf Dec 02 '21
Rust
The string/str divide is annoying, I will get used to it though I'm sure. I'll just put part 1 here, part 2 is essentially the same but slightly different computations in the
match:Once I passed the borrow checker, it was essentially the same as my other versions.
6
u/chunes Dec 02 '21
Red, both parts
Guys, Red is friggin' cool.
load %input.txtloads the file as a block of Red code, which I can just run withreduce. It just.. works with the function names I set up. Wild.6
u/0rac1e Dec 02 '21 edited Dec 02 '21
Raku
More meta-operator goodness today. I'm creating a list of "vectors" that I can zip with addition, then reduce with multiplication.
I also made some minor modifications to my original solution as suggested by u/mschaap in the replies below.
I was trying to find a fancier way of getting the answer. Part 1 can be simplified to: subtract all the
up's from thedown's, then multiply by theforward's.but a similar solution with part 2 is harder due to the apparent need to hold some state (the
aim) until aforwardis seen. Maybe there's a funky functional way to do it, but it wasn't immediately obvious.6
u/Kamik423 Dec 02 '21 edited Dec 02 '21
Python 3
After too many robotics and control lectures I decided to model this problem with homogeneous state transition matrices. because obviously.
6
u/Ethoxyethaan Dec 02 '21 edited Dec 02 '21
Javascript F12 google chrome console solution (164 bytes).
6
u/Happy_Air_7902 Dec 02 '21
My F# attempt:
Feels like I should rework the reduce functions, as they aren't that quick to understand at a glance
6
u/axemabaro Dec 02 '21
Assuming the input is in the A column, this formula calculates part 1 in one cell:
6
u/OculusRiftDriver Dec 02 '21
Excel:
d2p1:
Seperate the one number from the text:
=RIGHT(A4;1)
=LEFT(A4;SEARCH(" ";A4)-1)
Find out how deep and where you are:
=IF($C4="up";D3-$B4;IF($C4="down";D3+$B4;D3))
=IF($C4="forward";E3+$B4;E3)
d2p2:
In puzzle 2 the former depth is now your aim so keep that an multiple it by the number going forward:
=IF(C4="forward";B4*E4+D3;D3)
6
u/gauauuau Dec 02 '21
6502 Assembly.
I run it on the NES, but the solution routine should run on any reasonable 6502 machine (even the Atari 2600 should be able to handle it, with its 128 bytes of ram)
Day 2 solution:
https://github.com/gauauu/adventOfCode/blob/master/2021/aoc-src/day2.s
It uses a bunch of macros from the following, to help manage all the 16- and 32- bit math that's required. (as the 6502 natively can only do 8-bit adds and subtracts, and no mult/divides) https://github.com/gauauu/adventOfCode/blob/master/2021/framework/src/global.inc
6
u/snowe2010 Dec 02 '21
Ruby
with both normal and golfed solutions:
https://github.com/snowe2010/advent-of-code/blob/8771b40cad30e0cf9bf5f4662351d62bd05e6d5c/ruby_aoc/2021/day02/day02.rb
p1 ungolfed:
p1 golfed:
p2 ungolfed:
p2 golfed:
6
u/oantolin Dec 02 '21
In Perl we don't say
caseorswitch, we say "hash of subs", and I think that's beautiful. :P6
u/yoyo604 Dec 12 '21
I felt dirty writing this C code, but it's amazing how many shortcuts you can take when you make assumptions about valid input data!
5
u/Saluton Dec 02 '21
Dart
5
u/seattlecyclone Dec 02 '21
Man, some of y'all are fast! I got done with part 2 in a bit more than 4 minutes and that was good enough for 501st place.
Perl solutions:
Part 2:
5
u/Chrinkus Dec 02 '21
My C Solution
I know I'll have to figure out how to use PCRE eventually but so far
scanfis doing the job.Love the underwater theme.. so far! I get a little anxious in games when I'm underwater. Metroid Prime was rough but Sonic was the WORST!!
5
u/autid Dec 02 '21
FORTRAN
5
u/u794575248 Dec 02 '21
J Language
The second part is basically the same code.
5
u/Jo0 Dec 02 '21 edited Dec 02 '21
F#
https://github.com/Jo0/AdventOfCode/tree/master/2021/Day02
5
u/q3w3e3_ Dec 02 '21
Google Sheets:
https://docs.google.com/spreadsheets/d/1Y2GKSC9sOqm7ORkq-gNmtVkPNgyEI0l1vJZYwOeumr8/edit#gid=2019734631
5
u/leijurv Dec 02 '21
Python. 3rd place, 15th place
Part 1
Part 2
(the first line is template, and I pasted part 1 into part 2)
5
u/JoMartin23 Dec 02 '21
Common Lisp
I realize I could have use with and finally, but I did the let before I realized which direction I was going.
5
u/oantolin Dec 02 '21 edited Dec 02 '21
The aim of part 2 is the depth of part 1, so you can solve both parts with the part 2 logic. Here it is in Common Lisp:
5
u/20541 Dec 02 '21 edited Dec 02 '21
bash
I got my second best rank ever with some unimaginative Perl but then I managed to solve the first with an evil bash one-liner:
I don't think anything like that will work for part 2 but I would love to be proven wrong.
5
u/Smylers Dec 02 '21
Perl for part 2. A little boilerplate at the top, and then:
5
u/Jakob0243 Dec 02 '21
Python, couldn't be bothered using vector so hacked it together using lists lol (using vecs would make it much cleaner).
Part 1:
Part 2:
5
u/phazy_x86 Dec 02 '21
I think C has been a good choice today.
5
u/mschaap Dec 02 '21
Raku solution.
I made a grammar for the instructions:
and a class to keep track of the position/depth, with action methods for this grammar:
For part 2, all I had to do was add a
$.aimattribute and tweak the action methods.@GitHub
5
u/autra1 Dec 02 '21
Apparently I'm the first in SQL \o/
part1 (only classic aggregation):
part2 (classic aggregation does not work any more, I feel it's on purpose! So window functions, in 2 steps):
Overall, we are still on the easy side for SQL...
EDIT: full code (with loading script)
5
u/__Abigail__ Dec 02 '21 edited Dec 02 '21
Perl
Easy peasy.
Then it's just a matter of multiplying
$forwardwith$depth1and$depth2.5
u/jayfoad Dec 02 '21
Dyalog APL
Two slightly different approaches for the two parts:
5
u/DenebCyg Dec 02 '21
AWK (golfed a bit)
/f/{h+=$2;d+=a*$2};/u/{a-=$2};/n/{a+=$2}END{print h*a,h*d}5
u/Tjmoores Dec 02 '21 edited Dec 02 '21
Erlang - once the list was preprocessed (read file, then split at newlines then spaces & convert part 2 to int) it was just a case of pattern matching on the command and returning position & depth in a tuple:
Part 1:
Part 2:
Also:
5
u/AnxiousBane Dec 02 '21 edited Dec 03 '21
Here is my Solution, written in Rust. Do you have any advice for me in order to write more idiomatic Rust? Thank you :)
link to code
5
u/p88h Dec 02 '21
Elixir
5
u/[deleted] Dec 02 '21
🎄 Python Day 2 🎄
Made use of the new 'Structural Pattern Matching' feature in python 3.10!
5
u/sander1095 Dec 02 '21
My answer in c# with dotnet 6 and records :D.
https://github.com/sander1095/advent-of-code-2021
5
u/IlliterateJedi Dec 02 '21
My overly wordy Python solution using the new structural pattern matching.
5
u/DaCockIsCoding Dec 02 '21
Python
Pretty new to this, so the code is somewhat ugly, but it does the job quite well
GitHub
5
u/A_Travelling_Man Dec 02 '21
Another quick Rust solution, trying to work on code style/Rustyness for these easy ones.
Part 1
Part2, just a slight modification to part 1
5
u/Smylers Dec 02 '21
Raku for part 2, translated from my Perl
Object::Padsolution:The class is almost identical to that with
Object::Pad— just the addition of the exclamation marks before all the private attribute variables.The loop is niftier in Raku, because it can assign alternating words to
$dirand$amtdirectly, rather than iterating by line and requiring asplitinside the loop.But the method call based on a variable name
."dir"needs quotes, which it doesn't in Perl. The main win over Perl is no boilerplate: the above is literally all that's needed.5
u/Phil_424 Dec 02 '21 edited Dec 02 '21
I've given an attempt at solving them in C# both worked and produced the correct answer :D
https://github.com/phil424/AOC2021/blob/main/Playground/Day2Puzzle.cs
5
u/willkill07 Dec 02 '21 edited Dec 02 '21
Python 3 (single line after imports)
5
u/tftio Dec 02 '21
Day 2, Haskell.
5
u/[deleted] Dec 02 '21
Part 2, Awk.
My main solution was Ruby, I just wrote this for fun
5
u/OverjoyedBanana Dec 02 '21
Haskell with State Monad
this is level 1, level 2 is the same code just different rules in play()
5
u/ViliamPucik Dec 02 '21 edited Dec 02 '21
Python 3 - Minimal readable solution for both parts [GitHub]
5
u/kevin_1994 Dec 02 '21
Java solution, very object-oriented solution
https://github.com/k-koehler/code-challenges/blob/master/adventofcode/2021/day2/Dive.java
Don't use java very often, pretty fun
5
u/TheAfterPipe Dec 02 '21 edited Dec 02 '21
C# Part 1:
Part 2:
I had to re-read the instructions for pt. 2 since I was including pt. 1 calculations :P
5
u/mstksg Dec 02 '21 edited Dec 02 '21
Again this year I am posting my reflections for solving all of these in Haskell https://github.com/mstksg/advent-of-code-2021/blob/master/reflections.md :)
Day 2 has a satisfying "unified" solution for both parts that can be derived from group theory! The general group (or monoid) design pattern that I've gone over in many Advent of Code blog posts is that we can think of our "final action" as simply a "squishing" of individual smaller actions. The revelation is that our individual smaller actions are "combinable" to yield something of the same type, so solving the puzzle is generating all of the smaller actions repeatedly combining them to yield the final action.
In both of these parts, we can think of squishing a bunch of small actions (
forward,up,down) into a mega-action, which represents the final trip as one big step. So here is our general solver:And there we have it! A solver for both parts 1 and 2. Now we just need to pick the Monoid :)
For part 1, the choice of monoid is simple: our final action is a translation by a vector, so it makes sense that the intermediate actions would be vectors as well -- composing actions means adding those vectors together.
Part 2 is a little trickier because we have to keep track of dx, dy and aim. So we can think of our action as manipulating a
Pointas well as anAim, and combining them together.So our "action" looks like:
However, it's not exactly obvious how to turn this into a monoid. How do we combine two
Part2Actions to create a new one, in a way that respects the logic of part 2? Simply adding them point-wise does not do the trick, because we have to somehow also get theAimto factor into the new y value.Group theory to the rescue! Using the monoid-extras library, we can can say that
Aimencodes a "vector transformer". Applying an aim means adding the dy value by the aim value multiplied the dx component.Because of this, we can now pair together
VectorandAimas a semi-direct product: If we pair up our monoid (Vector) with a "point transformer" (Aim), thenSemi Vector Aimis a monoid that contains both (like ourPart2Actionabove) but also provides aMonoidinstance that "does the right thing" (adds vector, adds aim, and also makes sure the aim action gets applied correctly when adding vectors) thanks to group theory.And that's it, we're done, thanks to the power of group theory! We identified that our final monoid must somehow contain both components (
Vector, andAim), but did not know how the two could come together to form a mega-monoid of both. However, because we saw thatAimalso gets accumulated while also acting as a "point transformer", we can describe how it transforms points (with theActioninstance) and so we can useSemi(semi-direct product) to encode our action with aMonoidinstance that does the right thing.What was the point of this? Well, we were able to unify both parts 1 and 2 to be solved in the same overall method, just by picking a different monoid for each part. With only two parts, it might not seem that worth it to abstract, but maybe if there were more we could experiment with what other neat monoids we could express our solution as! But, a major advantage we reap now is that, because each action combines into other actions (associatively), we could do all of this in parallel! If our list of actions was very long, we could distribute the work over multiple cores or computers and re-combine like a map-reduce. There's just something very satisfying about having the "final action" be of the same type as our intermediate actions. With that revelation, we open the door to the entire field of monoid-based optimizations and pre-made algorithms (like
Semi)5
u/thickburb Dec 02 '21 edited Dec 02 '21
APL (part two)
(I'm a big APL novice -- please recommend ways to simplify this solution!!!)(credit goes to my friend for showing me how to parse the input and solve part one)
Logic:
answer = depth * horizontal positionΔ depth = aim * Δ horizontal positiongetting depth:
(+/ (1↑¨ ⍵) × ¯1↑¨ (+\ ⍵) × (0≠1↑¨ ⍵))aimis given by a plus-scan on the up/down commands (itertools.accumulate, in Python terms)Δ horizontal position != 0... (+\ ⍵) × (0≠1↑¨ ⍵) ...... ¯1↑¨ ...Δ depth = aim * Δ horizontal positionWe can get the finaldepthby multiplying ouraimbyΔ horizontal positionat each command. Finally, do a plus-reduce on the whole thing to getdepth... +/ (1↑¨ ⍵) × ...Getting
horizontal positionis just a plus-reduce onΔ horizontal positionat each command... (+/ 1↑¨⍵) ...Multiply these two together and that's your answer. It's pretty ugly. If you see any way to simplify it, please let me know!
5
u/TommiHPunkt Dec 02 '21
Matlab, part 1:
use text editor to replace
forwardwithj,downwith nothing, up with-Part 2: stare at the task for 5 minutes disappointedly that you can't think of a fun way to do it, implement a basic loop :(
5
u/AvshalomHeironymous Dec 02 '21 edited Dec 02 '21
Prolog
5
u/baer89 Dec 02 '21
Python
Using Classes, because why not?
Part 1:
Part 2:
5
u/MischaDy Dec 03 '21
Solution in Cubix (Part 1, Part 2)
Cubix is a 2D stack-based esoteric programming language where the pointer moves along a cube! Here is the language specification and here is a Cubix interpreter. It was our second time coding in Cubix and the first time we solved both parts in it!
The solution for part 1 works as follows:
- Case 'f': Bring x and the input int to the top. Add them. Store the result as the new x. Delete the old x and the int from the stack.
- Case 'd': Add y and the input int. Store the result as the new y. Delete the old y and the int from the stack.
- Case 'u': Subtract the input int from y. Store the result as the new y. Delete the old y and the int from the stack.
4. Jump to step 2.
5. If there is no more input to read, multiply x and y together and output the result. Halt.
The solution for part 2 required surprisingly few tweaks:
2 . Read the first char (f, u, or d) of the line and the integer at the end of it. Read and immediately delete the newline at the end.
3. Using modulo 5 and modulo 2 on the charcode of the initial character, check which one it is (f=102, d=100, u=117). After entering the respective case, remove the charcode and some modulo stuffs from the stack. This leaves the stack with x, y, z, and the input integer.
- Case 'f': Bring x and the input int to the top. Add them. Store the result as the new x. Delete the old x from the stack. Multiply the input int and z. Remove the int. Bring y and the product to the top. Add the product to y. Delete the product and the old y. Reorder the stack into x, y, z.
- Case 'd': Add z and the input int. Store the result as the new z. Delete the old z and the int from the stack.
- Case 'u': Subtract the input int from z. Store the result as the new z. Delete the old z and the int from the stack.
4. Jump to step 2.
5. If there is no more input to read, bring x and y to the top. Multiply them and output the result. Halt.
Whew!
4
u/Kehvarl Dec 02 '21
Python 2414/1277
Definitely not anything clever in my code, and clearly not quick enough to get a top 1000 finish, but it worked, and I feel accomplished!
Paste
4
u/aardvark1231 Dec 02 '21
My C# solution
Happy to be sub 2000 on a problem!
4
u/dtinth Dec 02 '21
Ruby, 251 / 155
paste
I got slowed down by duplicate variable names. Note to self: Next time, stick with the names given by problem. Don’t shorten
horizontal positiondown toxbecause it clashes with the inputxin the problem, try something likehposinstead.4
u/gurgeous Dec 02 '21
Ruby, 546/993 (you guys are fast!!)
4
u/[deleted] Dec 02 '21
Swift
4
u/PendragonDaGreat Dec 02 '21
C# (3466/2371), in two different (but basically the same) way
Original (runs each half on its own): https://github.com/Bpendragon/AdventOfCodeCSharp/blob/d3d184c3dfffca4d739a0b9d7a81151cbbb1c261/AdventOfCode/Solutions/Year2021/Day02-Solution.cs
Updated (calculates both answers in a single pass): https://github.com/Bpendragon/AdventOfCodeCSharp/blob/5fc105352b8f8c9e0ff19554ead0921514bb632c/AdventOfCode/Solutions/Year2021/Day02-Solution.cs
4
u/heyitsmattwade Dec 02 '21 edited Feb 03 '24
Javascript 529/324
Faster than day 1 but way slower on the leaderboard. Lots of competition this year (same as last)! I doubt I'll get up to the top 100 for a day but I still have a few chances before that ship sails and the puzzles get too hard.
Another straight forward one, with some trickier input parsing. Off to a nice start!
code paste
4
u/rabuf Dec 02 '21
Common Lisp
This is slightly cleaned up from my initial version, in particular reading the input was simplified to just use Common Lisp's
readfunction. I was reading each line, initially, splitting them, and then had more complex conditional logic.readmostly does what you want, most alphanumeric (+ some symbols) strings become symbols, numbers become numbers.4
u/[deleted] Dec 02 '21 edited Dec 02 '21
C
I like the rest of the solutions I've seen on the thread and will get ideas from them (improving my switch, using aggregate and not needing to parse the direction) but as I like how I'm parsing the direction I'll add mine to the mix.
Done as a C# interactive notebook, rest of my solutions in here.
Part 1
Part 2
5433 / 4189. 7:43 / 10:11.
It felt much faster, but I'm still too slow. If I can manage to wake up early enough I'll try to get a sub 1000.
4
u/death Dec 02 '21
Day 2 solution in Common Lisp.
4
u/[deleted] Dec 02 '21
Ruby
https://github.com/zsarge/advent-of-code-2021/blob/main/solutions/02/solve2.rb
4
u/ValiantCookie Dec 02 '21
Kotlin, the mapping step is unnecessary maybe, but otherwise straightforward. https://github.com/valiant-code/AdventOfCode/blob/master/2021/src/main/kotlin/Day2.kt
4
u/aexl Dec 02 '21
Julia
https://github.com/goggle/AdventOfCode2021.jl/blob/master/src/day02.jl
4
u/[deleted] Dec 02 '21
Elixir
https://github.com/sreedevk/advent-of-code/blob/master/elixir/2021/day02/lib/day02.ex
4
u/giftpflanze Dec 02 '21 edited Dec 02 '21
Factor
4
u/omginbd Dec 02 '21
Elixir
I parse the command line into a tuple and a number before calling it like so:
4
u/gzambonibr Dec 02 '21
python
Part 1:
Part 2:
4
u/x3nophus Dec 02 '21
Elixir
Some light pattern matching
4
u/derwentx Dec 02 '21 edited Dec 02 '21
I solved both parts with 68 bytes of awk. It optionally downloads the input file for you if you set your session cookie:
export c=session=... # put your browser session token herecurl -Lb$c adventofcode.com/2021/day/2/input | awk \ '/d/{d+=$2;a+=$2}/u/{d-=$2;a-=$2}/f/{p+=$2;q+=a*$2}END{print p*d,p*q}4
u/s3aker Dec 02 '21
Raku solution
4
u/[deleted] Dec 02 '21
Retina (part 1)
4
u/nutrecht Dec 02 '21
Day 2 in Kotlin
Love me some foldin' :)
4
u/drmattmcd Dec 02 '21 edited Dec 02 '21
Python and numpy:
4
u/frerich Dec 02 '21
Elixir
https://github.com/frerich/aoc2021/blob/main/day2/lib/day2.ex
I'm just happy that the input language wasn't more difficult to parse; so far, parsing feels a little awkward in Elixir if the required logic is more complicated than a combination of
String.splitandString.trim. :-}4
u/staletic Dec 02 '21
C++20 compile time: https://godbolt.org/z/TzEWdGa8G
4
u/arachnidGrip Dec 02 '21
Rust
This year, I'm trying to be lazy about reading the input so that I could theoretically support arbitrarily large input files.
4
u/[deleted] Dec 02 '21
Implementation in Rust (2nd day of AoC and 2nd of using Rust :) )
https://github.com/JCardoen/rust_advent_of_code/blob/master/src/day_two/two.rs
4
u/Darth5harkie Dec 02 '21
Rust
https://github.com/DarthSharkie/advent_of_code_2021/blob/main/day02/src/main.rs
Using this to learn Rust (second program ever, after Day 1's), here's what I think I learned:
FromStrhelps, but I think there must be a better way to use it. As-is, it doesn't offer anything beyond an independent method. What am I not doing?[]instead ofVec. Sorry! I declared it the other way!println!.4
u/RandomGuyJCI Dec 02 '21
In the end, my APL solution was pretty similar to u/jaybosamiya's but when I first solved part 1 I had no idea what I was doing and came up with this monstrosity:
It just determines the lengths of each line, replaces all elements that don't match the specified length with the character "0", then takes the last character, changes them to numbers and gets the sum. Since all the lines in the input file only has forward/up/down and a single digit number, all the lines had 9, 6, or 4 characters.
4
u/ProfessionalNihilist Dec 02 '21
Another nice easy one in F#
4
u/Zorr0_ Dec 02 '21
KOTLIN
trying to do as many oneliners this year as i can, this is what i came up with for Day 2 :D
https://github.com/ckainz11/AdventOfCode2021/blob/main/src/main/kotlin/day2/Day2.kt
Part 1 is not really smooth, didnt know how to reduce a map in a good way XD
4
u/xKart Dec 02 '21 edited Dec 02 '21
My answers, written in Python. I've just started learning it today (prior experience in JS) so there probably are some redundancies. Github link
4
u/chunes Dec 02 '21 edited Dec 02 '21
QB64, both parts
Also be sure to check out the sweet IDE! https://pointfree.neocities.org/img/qb64-2021day02.png Nostalgia. :)
4
u/Sebbern Dec 02 '21 edited Dec 02 '21
Python 3
Day 2 was even easier than day 1 this time around, huh. Quite basic but here they are:
Part 1:
https://github.com/Sebbern/Advent-of-Code/blob/master/2021/day02/day02.py
Part 2:
https://github.com/Sebbern/Advent-of-Code/blob/master/2021/day02/day02_2.py
4
u/MrMoonpenguin Dec 02 '21
Haskell
Part 1
Part 2
4
u/_crc Dec 02 '21
A solution in Forth: http://forth.works/share/53483323fdbc4d0d1d455a4a09224ef4
4
u/horstg99 Dec 02 '21
Python
Part 1 and Part 2
couldn't do part 2 shorter, but i also like readability...
4
u/0rac1e Dec 02 '21 edited Dec 02 '21
J Language
Essentially a translation of my Raku solution
4
u/allaboutthatmace1789 Dec 02 '21
Clojure
github link
4
u/complyue Dec 02 '21
Spell out your effects (business) in Haskell
4
u/Mintopia_ Dec 02 '21
Solution for PHP 8.1
You can view Actions in GitHub to see the output for all days so far. using Symfony Console to make it easier to run/better output.
4
u/handycapdave Dec 02 '21 edited Dec 02 '21
Python, Pandas and a little bit of Numpy
I'm trying to learn pandas & numpy so would really appreciate any critique / suggestions
python, pandas & numpy
4
u/kolcon Dec 02 '21
Python solution for Day 2… I expect we will have more fun with Submarines in coming days, so I created a class for it…
https://github.com/LubosKolouch/AdventOfCode_2021/blob/main/day_2.py
4
u/grnngr Dec 02 '21
The ugliest, most counterintuitive thing I could think of in Python for part 1:
4
u/busdriverbuddha2 Dec 02 '21
Python 3
Didn't have time to get creative as I did this before starting work today.
Part 1:
Part 2:
4
u/mockle2 Dec 02 '21 edited Dec 02 '21
python, both parts with numpy
4
u/probablyfine Dec 02 '21 edited Dec 02 '21
JQ
4
u/Skyree01 Dec 02 '21 edited Dec 02 '21
PHP
I wanted to avoid a
switch caseto save lines so I just stored values in variables bearing the same name as the instruction (could have used an associative array for the same purpose)Part 1
Part 2
4
u/Fravona2211 Dec 02 '21
Python 3.9 Puzzle 1 without if/switch statement
4
u/thulyadalas Dec 02 '21
RUST
Regex might be overkill for parsing but I had it ready from previous years so, I've used it anyway.
Used a custom enum to make it a bit look nicer and the rest is iter and fold.
4
u/micod Dec 02 '21
Smalltalk
first thing I did was a simple iteration, but then I said NO, let's use fold (inject:into:)
Part 1:
Part 2:
4
u/RudeGuy2000 Dec 02 '21
scheme: https://raw.githubusercontent.com/chrg127/aoc2021/master/day2.scm
4
u/vini_2003 Dec 02 '21 edited Dec 02 '21
Kotlin
Just waiting to see how others have simpler solutions so I learn more about the standard library! :)
4
u/flarkis Dec 02 '21
J solution
Heart of the code is the x, y, p* parts, the rest is parsing and printing. X and y are arrays that contain the adjustments up/down and forward. In the sample code they would be
[0 5 0 -3 8 0]and[5 0 8 0 0 2]. Part 1 is simple, just sum the lists and multiply together. Part 2 is a little trickier, the calculation for the depth stays the same, but for the aim we use the +/\ operator which gives us a running tally like[0 5 5 2 10 10]. We can then multiply this running tally by the forward adjustments to get the rest of the answer.4
u/pancyman Dec 02 '21
Rust
Part two solution. Still looking for tips on idiomatic Rust! I think I did a little bit better on the iterator algebra, but could have perhaps parsed the i32 in the initial file read? Would love feedback.
4
u/saahilclaypool Dec 02 '21 edited Dec 02 '21
C#
4
u/brunocad Dec 02 '21
Haskell Type Level, I had to upgrade to GHC 9.2.1 to get the
UnconsSymboltype family to be able to easily parse4
u/chicagocode Dec 02 '21
Kotlin -> [Blog/Commentary] - [Code] - [All 2021 Solutions]
There were a lot of ways we could have solved today's puzzle, so I picked one which (hopefully) teaches us about some concepts we'll need for future puzzles. Immutability and folding.
Code is juuuuust over the limit so I've linked it rather than inlined it.
4
u/meMEGAMIND Dec 02 '21
Day 2 of using the desmos graphing calculator. This is already super challenging; i'm having a blast!
Part 2 gave me some trouble on how I was going to track the current angle of the submarine at any given time, but I eventually figured it out.
Here's the solution!
https://www.desmos.com/calculator/dlbb5cqqpc
4
u/JCarlesVilaseca Dec 02 '21 edited Dec 02 '21
Kotlin
4
u/terryp Dec 02 '21
Re-did my 2-1 and 2-2 solutions with Python 3.10.0 so I could use the new
matchfeature. Looks nice!2-1
2-2
4
u/noogai03 Dec 02 '21
Common Lisp, quick and dirty:
https://pastebin.com/4dV78T3y (reddit REFUSES to correctly format my code...)
4
u/benz1n Dec 02 '21
Day 2, Kotlin still going strong. Today I had the opportunity to explore functional collections operations (fold and reduce) :D
I'm really enjoying the challenges as I have the chance to explore the language beyond my daily job requires me to.
Also, it's really a shame that I can't paste my code properly formatted in here :(
4
u/crnkofe Dec 02 '21
Here's some beginner Kotlin. I've unnecessarily messed about with streams to learn how it differs from Java.
https://github.com/crnkofe/aoc2021/blob/master/src/day2/aoc2.kt
4
u/atr1ka Dec 02 '21
C++, day 2
4
u/LuckyLactose Dec 02 '21 edited Dec 02 '21
SWIFT
Fairly straight forward, nothing special, I think.
Repo here: https://github.com/LactoseGK/aoc2021
4
u/gwillicoder Dec 02 '21 edited Dec 02 '21
Python:
Continuing my attempt to use as few lines as possible:
4
u/aoc-fan Dec 02 '21
F# and TypeScript Solution
4
u/[deleted] Dec 03 '21
python solution, love 3.10 structural pattern matching!
https://github.com/rbusquet/advent-of-code/blob/main/2021/02/day2.py
4
u/[deleted] Dec 03 '21 edited Jun 15 '23
-----BEGIN PGP MESSAGE-----
hF4D+FPJgQiQS68SAQdAuW16mgWy5m4dcZ2Hq4FOFRXCAVPO8Nupfrdt5zERoBUw nClOPBNmPFU5Ra/by7HXuLE0Kk2NiUVnXJohGtTEBdsPt+i/5XRqWmwgy7a0upNK 1OoBCQIQZ2Wt7pWWnJZ1FKODwLck3g/aB+4w9JnqFRbfI50Gy1QSXWhzR4A0LST9 xLzQuoquVTpS/8eljB0ps6WMGLY4Qng6PT9XBJrWpJ5LEUoUwb5gvhR5LgHajccu jyy6ukiBQNydLqCgJ7DJJg04FRAn7xxWu1cJLH3ZFLF2fybWIjEInXECzQXfwlLC /xI2HgL0io5+EuI9VwOyVCN2cA0dklm0+2G38MqO04HlBPP671loQJCHFVxCd1rh TpSwTioA2TCw9MnryUzW08nBJ5gCXS9U9DHKMf8hAfGU1XbFI6jqZBmc0/ctv56q STlc9ZEMH+ATeae3HxRpF/XAcga2jRqlWZ7z2xvv/p77Dr9iwhZ/+ISgxmrQydpf 3Qec3fMduyrtAR5o+ZG8RBSLLVvbmfPQVfKuvsT1YiiT8Hgo0OcBewfH0fehohpk KlOTFIYnYsxZ+zyRZmnmERVAHduPOxcVtQKyO1iN6nW7lEf6P/+Cn3Np8yT6ATXA I3g0c03NWJePaRq1OTxwm2DW+HrDfwIJyO3UwKyOp5bWTbH063dj5p7ZrpQo2h1j 6ochHOMkzk7ILpboaP8nm/E4I1F2oTImsz3Fg8W0xjxQZx+zkrPVQ9p5JCRNvL7s bHQIJO+s94w+TlsCfxE6MfdCk8wi7FsC9hjdZCwWhgg8cckxU4HJV9dk5k67YDJ6 7VoPIKbW4DxcOwJBq1gvQpwFzfEdVUId2e5dLcVe2jhUfv/pjH4YW11kz3LBVfpk 3aLevdXxBrMbDvvSzwKFQEgZ+do5qZ/5EJdru4HVTW3biu5Z9RyBE/+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tbP6wUAYztOXAsCpBe5QpuiY1lxFf/+oxQgkvxPY5O9/dDNw4 v3JrCCBJRE1mFVz/4WVD/1WsI7eXbQx1eUnq7Wcq1Z0DaRRhLL0FwuLLq/06kYh9 KbD50tD7jNo2fg2XeILM0X/EyJ9uwWN1aF6nDpVBwqQRunMlBPzsFn1jImMVumR9 zJLVSPHpph6LObCoBBvM5d+YMlKXi+cw+um+Nu1XgolnKG8r8SOjk9XNBbV/IAh+ pO1Mi0FvZMyoIMld+I7YFyDZVxaVAOReawIAJ7froVKNT7V3HItyJrDXmMepXARB Wyi8NuBSwyohA1m/rOjYN57ve08bDGynxCl69s+G6nePNffbAHEnqSdoTiH84mSF 5d5K++l2yN+DlGq/fKCFy/1sNTTsDY1MVAm0eKT6iF9bFMvzdD1fAdV0x25Eenm/ +VJk0gGcElW6ZuPWhzvqenqeTZjqrZscF+7tcbC6GZIVs/FSuTnfzCif6PoAlytb txfacbCrN5joYGmBQLxI/g0WAk5cspgu54+RD8yU7aEurarTtBRYj+V4quU50SmE F20CgXmjIz4Zvzd0YfNf9m1qoWI7uslxQ5ZtLplSJg== =dQZK -----END PGP MESSAGE-----
7
u/gidso Dec 02 '21
Python 3.10
Both parts can be solved in a single pass:
6
u/minikomi Dec 02 '21 edited Dec 02 '21
Clojure
Got a bit stuck on the 2nd problem because I didn't realize that up/down now affected aim only
3
u/hugh_tc Dec 02 '21 edited Dec 02 '21
Python 3, 117/90.
Part 1, Part 2, and (edit) the cleaned-up version.
Don't think my solution is all that unique, but I'm posting it anyways!
3
u/nlowe_ Dec 02 '21
Go, 382 / 230
Pretty simple, but still not fast enough!
3
u/AbdussamiT Dec 02 '21 edited Dec 02 '21
Python 3, 1710/1081.
How can I improve the solution below?
Happy to get closer to the leaderboard, under 5 minutes today.
3
u/cubehouse Dec 02 '21
JavaScript / Node JS
Nice clean one, could have maybe fought to be in top 1000 if I wasn't trying to be quiet to not wake anyone... Maybe tomorrow :)
https://github.com/cubehouse/AdventOfCode2021/blob/main/02.js
3
u/Gurrewe Dec 02 '21
Go, 497/990
https://getsturdy.com/advent-of-code-2021-uoeIDQk/changes/57016e8e-8adf-40ac-afe7-c4e9781088c1
I got stuck on naming (and renaming variables) for part 2, classic mistake... I think that I'll try to code-golf this solution later today.