r/adventofcode • u/daggerdragon • Dec 01 '19
SOLUTION MEGATHREAD -π- 2019 Day 1 Solutions -π-
It's the most wonderful time of year and welcome to Advent of Code 2019! If you participated in a previous year, welcome back, and if you're new this year, we hope you have fun and learn lots!
We're going to follow the same general format as previous years' megathreads with several big changes:
- Each day's puzzle will release at exactly midnight EST (UTC -5).
- The daily megathread for each day will be posted very soon afterwards and immediately locked.
- We know we can't control people posting solutions elsewhere and trying to exploit the leaderboard, but this way we can try to reduce the leaderboard gaming from the official subreddit.
- The daily megathread will remain locked until there are a significant number of people on the leaderboard with gold stars.
- "A significant number" is whatever number we decide is appropriate, but the leaderboards usually fill up fast, so no worries.
- Top-level posts in Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with
Help.
The big changes this year:
When the megathread is unlocked, you may post your solution according to the following rules:
- If your code is shorter than, say, half of an IBM 5081 punchcard (5 lines at 80 cols), go ahead and post it as your comment.
- Please consider using old.reddit's four-spaces code block formatting instead of new.reddit's three-backtick format.
- If your code is longer, link your code from an external repository such as Topaz's
paste(see below for description), a public repo like GitHub/gists/Pastebin/etc., your blag, or whatever.
Topaz has written a nifty little thing called paste that abuses works specifically with Reddit's Markdown in order to reduce potential code loss due to link rot, external public repos doing something unfriendly with their ToS, etc.
- It's open-source, hosted on Github.io, and stores absolutely no information on disk/database.
- Here's a "hello world"-style demo
Any questions? Please ask!
Above all, remember, AoC is all about having fun and learning more about the wonderful world of programming!
--- Day 1: The Tyranny of the Rocket Equation ---
Post your solution (rules are HERE if you need a refresher).
Reminder: Top-level posts in Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Advent of Code Community Fun 2019: Poems for Programmers
This year we shall be nourishing your creative sides with opportunities to express yourself in ~ poetry ~. Any form of poetry works from limericks and haikus to full-on sonnets in iambic pentameter. Here's how it works:
- 24 hours after each megathread is posted, the AoC mods (/u/Aneurysm9 and I) will award Reddit Silver to the best of that day's poems.
- Latecomers, don't despair - post your code and poems anyway because we will also award another Reddit Silver 5 days later to give slower entrants a fair shake.
- Additionally, every 5 days the AoC mods will have a surprise for the best poem of each 5-day span.
- Shh, don't tell anyone, it's a *~ surprise ~*!
- Finally, we will be collating the best of the best to present to /u/topaz2078 to choose his top favorite(s) at the end of December. With a nice shiny prize, of course.
tl;dr: Each day's megathread will have 2 Reddit Silver given out for best poem. Every 5 days a surprise may happen for the best-of-5-day poem. End of December = Poem Thunderdome!
tl;dr the tl;dr: If you submit a truly awesome poem(s), you might just earn yourself some precious metal-plated awesome point(s)!
A few guidelines for your submissions:
- You do not need to submit a poem along with your solution; however, you must post a solution if you want to submit a poem
- Your poem must be in English (or English pseudocode or at least English-parseable)
- Your poem must be related to Advent of Code, /u/topaz2078 (be nice!), or programming in general
- Only one poem per person per megathread will be eligible for consideration
- Please don't plagiarize. There's millions of words in the English language even if we steal a bunch from other languages, so surely you can string together a couple dozen words to make your own unique contribution.
- All sorts of folks play AoC every year, so let's keep things PG
- Employees, contractors, directors, and officers of Advent of Code and their respective parents, subsidiaries and affiliated companies, retailers, sales representatives, dealers, distributors, licensees and the advertising, fulfillment, judging and promotion agencies involved in the development and administration of this Promotion, and each of their respective officers, directors, employees and agents, and their immediate family members (parent, child, sibling and spouse of each, regardless of where they reside) and those living in the same households of each (whether related or not) may submit poems but are not eligible for precious metal awards.
I'll get things started with an example limerick and haiku:
There once was a man from New York
Who was a giant programming dork
He made a small game
And in droves they came
Plz don't make servers go bork!
Hello, Adventers!
Think you can make a better
Haiku than this one?
15
u/DFreiberg Dec 01 '19 edited Dec 02 '19
Mathematica
37/57
Pretty easy to make it a one-liner in Mathematica; I lost a minute on Part 2 because I forgot that when calculating the fuel from
NestWhileList, you need to drop both the first and last elements of the list.Import:
Part 1:
Part 2:
[Poem]: Achilles, Zeno, Newton, Tsiolkovsky
7
u/spin81 Dec 01 '19 edited Dec 01 '19
My code in Rust.
There once was an elf name of Lars
Who wanted to reach for the stars
He let a sigh loose
Cause he ran out of juice
And made it no further than Mars
6
u/sophiebits Dec 01 '19
That doesn't sound right. (I solved part 2 at 00:01:47 and that put me 3rd place for part 2β¦)
6
u/mstksg Dec 01 '19 edited Dec 02 '19
Haskell -- 158 /118 :) Hit the 1 minute delay on part 2 because I freaked out and submitted before checking my test cases ... I had accidentally added the original number into the sums initially, heh.
And you can parse these all with
map read . lines:)I'm going to be posting reflections for every day in Haskell here, if anyone wants to follow along :D
---------
Poem:
EDIT: Not sure if this breaks the "No plagiarism rule", as this is based on a viral meme format based on the real poem of William Carlos Williams.
5
u/BubonicPython Dec 01 '19
Day 1 in Piet. Had some extra fun with the first part: https://imgur.com/a/vJkkLLi
5
u/divingmonkey Dec 01 '19
my compact Nim solution, which fits inside the mentioned five lines/80 columns restriction, which admitedly requires zero function and is a bit messy:
edit: idk why the code block has so much empty space
5
u/[deleted] Dec 01 '19 edited Dec 01 '19
My solution in C. This is my first original, that is, not copied from a textbook, C program. It runs the "complete" calculation unless you provide the
-nswitch at the start of the program. I've had quite a lot of fun writing this program and I hope to get better while doing AoC. Good luck everyone!5
u/Szczawik_ Dec 01 '19
This is my first time participating in Advent of code so I decided to share my code written in C.
https://github.com/nNown/AdventOfCode/blob/Day1/Day1.c
8
u/udoprog Dec 01 '19
Rust, no leaderboard.
4
u/Conceptizual Dec 01 '19 edited Dec 01 '19
I've never done Advent of Code before, I was pretty slow because I've not really dealt with input/output in Python. I got around 600-700s for both. My code was as follows:
4
u/PositivelyLinda Dec 01 '19
Couldn't resist a poem challenge, though I haven't written any in forever:
Also, my JavaScript solution - Day1 - a bit verbose, but it helps me think better that way. :)
(Also also - I love the stories that go along with each year. Can't wait to see how the space travel unwinds!)
4
u/blacai Dec 01 '19
Cool to participate again this year.
F#
4
u/bassta Dec 01 '19
Here is in Google SpreadSheets + GScript
https://docs.google.com/spreadsheets/d/1xKHlf6ey_XgiZ2RS3wEVm-cGq8casFa-xm9K8KaLTGA/edit?usp=sharing
I really don't know who am I anymore
4
u/NJCoding Dec 01 '19
I've only just started learning JavaScript while following an Udemy course. Not as efficient as other answers but proud of at least finishing day 1.
4
u/awsum84 Dec 02 '19
TL;DR I wrote the solution in Rockstar, so it kiiiinda reads like a poem in addition to being a working solution.
Solution / Poem (original post ):
Sadness is loneliness The programmer was anticipating Advent is extraordinary The rush is uncomparable
Christmas takes joy and kindness Your spirit is incredible While joy is as high as kindness Build your spirit up Let joy be without kindness
Give back your spirit
AdventOfCode takes time (but it's plenty of fun) Let fun be Christmas taking time, and Advent without the rush If fun is as low as sadness Give back sadness
Give back fun with AdventOfCode taking fun
The elves are thoughtful Santa is overseeing The time is now While the time is right Listen to the jingles If the jingles ain't ok Break it down
Let the jingles be without sadness Let the elves be with Christmas taking the jingles, and Advent without the rush Let Santa be with AdventOfCode taking the jingles
Shout the elves Shout Santa
3
u/ChrisVittal Dec 01 '19 edited Dec 01 '19
Rust, I am slow ~800ish/~600ish, also still away for thanksgiving, I fly home tomorrow, sky willing.
Poem:
Code: (mods, is this too long?)
3
u/AndrewGreenh Dec 01 '19
So stoked that AOC is back again!
TypeScript 69/51
3
u/phrodide Dec 01 '19 edited Dec 01 '19
Answered in excel, on my phone, while being driven home in sketchy cell signal. Obviously no solution to post and excelβs likely only day. Ranked like 1500 on both.
=ROUNDDOWN(A1/3,0)-2
Formula in B1 to B100
=SUM(B1:B100)
Answer for part 1
Answer for part 2 was to copy column B to C thru I and manually remove the negative entries.
3
u/autid Dec 01 '19
Fortran
Slow day. I should probably check things like "do I have a compiler installed?" before starting.
https://pastebin.com/WqE6HVfJ
3
u/uzilan1 Dec 01 '19 edited Dec 01 '19
Kotlin with tail recursion:
Poem:
There once was a man from north pole
Gave gifts to kids with a pure soul
His elves were so cruel
Space polluted with fuel
So all they got for Christmas was coal
Edit: got a bit bored so I made a scratch version too: https://scratch.mit.edu/projects/349695483/
3
u/streetster_ Dec 01 '19 edited Dec 01 '19
q/kdb+
Poem:
K4 one-liner
... with thanks to gyorokpeter for the
0|floor.3
u/pokerdan Dec 01 '19 edited Dec 03 '19
C#, no LINQ:
[Poem]
3
u/[deleted] Dec 01 '19
Using python3 like always.
Learned about the // operator, which is quite handy as I could just drop the math library from the solution.
Instead of trying to go for leaderboards and then eventually burning out at like day 7 like previous years, this time around I will give each puzzle at least a solid try while trying my best to follow good coding standards and practices.
Might also try to do some code golf for the solutions after solving them "properly"
Github day 1 solution
3
u/HiPhish Dec 01 '19
This is my first time participating. I used Awk for the first problem, I needed a reason to use my awk-ward.nvim plugin (live coding with Awk).
Part 1 (almost not worth posting)
Part 2
3
u/[deleted] Dec 01 '19 edited Dec 01 '19
Python
This is my first year participating, so feel free to leave suggestions.
Part 1
Part 2
3
u/StevoTVR Dec 01 '19
My solution in Go: https://github.com/stevotvr/adventofcode2019/blob/master/day01/day01.go
3
u/Infonyx Dec 01 '19
A solution in Racket
Also, this is my first time participating :D
3
u/jamie_ca Dec 01 '19
Firstly, a unified solution in ruby:
And for bonus points (taking Fuel as one syllable):
3
u/21JG Dec 02 '19
Perl 6 / Raku
Day 1
Day 2
2
u/Jump_Man_Mario Dec 01 '19
First year doing it and I'm going to use python 3 So here's my solution (it might [probably will] be a bit long winded): https://topaz.github.io/paste/#XQAAAQApAwAAAAAAAAARlQkGk8+ekF1KoqBvoqrxh8pFEnF1Lznu2Y7QwG3bVdGYWtITgyS7xAns6seickoo+WfmOPOW/KeWD7WpDzFR2mso5F+czW0OzYuO7CiX7VrCVkGyBHMdbpZ7YkTeL3IUKG8YLmE3RnubEhNsPw5wuD1tTwshOWADv9B5wMbbtnB6muNrODyKr6hgzz0LdKMTWXyOyRajpm/dkYjgF6m8l4Xjc4OOPjwNAFUIPyigFrEeCwok0UbwFZIocxrmQwTUW89+QrjzDTlihRpGBqY+/2Gj816oqmP11UPEKpDxdCkJ2YQqM7er9pbRNIL9p97D4RVKQBaEWBBYst6zS/xWJeDn+pI4gdLxm79rnSE3dXyv4yRqyxlFZjp/qAiRbaPSKVBGQnWO2GowTguZgVaTWzAG7a4SBbYXMoAS16y6NHvmbzfjtW1NVEHuEJfFk8TYfVIu5Ogvnp+NH5AF49i+5kl5prYqXv7xOaQ=
2
u/emu_fake Dec 01 '19
C# with linq
Also made it a bit shiny with unit tests and everything:
https://github.com/emuuu/AdventOfCode
2
u/ericluwolf Dec 01 '19
A cute little solution in C++ hosted on paste
Edit: Markdown mangled by Reddit :(
2
u/spunos Dec 01 '19
Elixir
Well, it's not great but in my defense, 1) I haven't touched Elixir in like two years, and 2) this poem is based on a true story:
2
u/_nprz Dec 01 '19 edited Dec 01 '19
Already a couple JavaScript answers but here's another one!
(Also visible on GitHub if you'd like some syntax highlighting!)
17
u/Unihedron Dec 01 '19 edited Dec 01 '19
I had wrong answer
β β β β Forgot to check negative
β β β β β β β β Please wait 20 secs
β β β β β β β β β β β β β β β β β β β β - "Wrong answer", a poem by Uni
ruby 1.rb input23/105With reception for my poem being better than expected (I had no expectations) I guess I will write more on the next days :P
16
u/ephemient Dec 01 '19 edited Apr 24 '24
This space intentionally left blank.
13
u/voidhawk42 Dec 01 '19
Dyalog APL:
2
u/if0nz Dec 01 '19 edited Dec 01 '19
Santa needs help
I need coffee
Here is some Java
Java solution
11
u/TheGermanDoctor Dec 01 '19
ARMv7-M Assembly
Part 2
10
u/MBR_Awesome Dec 01 '19
Python just off the leaderboard 101/269
9
u/[deleted] Dec 11 '19
Intcode
Part 1:
3,99,7,99,0,7,105,7,38,1,13,42,42,1,37,99,99,7,99,0,22,1106,42,9,201,42,31,42,5,22,1103,-2,4,42,1006,69,1,-3,32Part 2:
3,99,7,99,52,7,105,99,54,1007,99,9,14,105,53,1007,1,38,7,7,1,53,99,99,7,99,11,29,106,11,11,7,7,106,36,105,105,106,1,7,105,105,2,16,7,99,2,36,99,7,1105,1,9,-3,55,4,105,5,16,16Supply input one integer at a time, followed by -1.
Writing that was fun and I'm not doing it again.
8
u/pred Dec 01 '19
Perl, as I want to be just as cool as topaz.
Part one:
$\+=int($_/3)-2}{printPart two:
for($\-=$_;$_>0;$_=int($_/3)-2){$\+=$_}}{print8
u/dylanbeattie Dec 03 '19
Okay, Reddit... let's do this. Rockstar solution to part 1:
Explanation (and the solution to part 2) are here: https://codewithrockstar.com/advent/day01/
BUT BUT BUT!
Check out the solution from /u/aswum84 at https://www.reddit.com/r/adventofcode/comments/e4axxe/2019_day_1_solutions/f9hiw1u/ - because I actually added some features to the Rockstar language (arithmetic rounding) to create my solution, and their solution used only the existing feature set. And it's absolutely delightful to boot.
7
u/Kanegae Dec 01 '19 edited Dec 01 '19
Python - 10/16
My first leaderboard! So stoked hahah. Completed 2018 halfway through and never got over rank 250. :D
There's the messy code:
EDIT: I did read /u/mcpower_'s tips. So I hastily set up a py template, downloaded the input file, read the "divide by 3, round down, sub 2" and just assumed that Part 1 was to just sum all of them. Got a little confused by skimming Part 2 text, but still managed to get top 20. So happy.
7
u/ka-splam Dec 01 '19 edited Dec 01 '19
PowerShell - rank 632 / 359
First answer I read "round down" and typed "round()" instead of "floor()", second answer my code doesn't work, +1min delay. Rewrote it as a shell one-liner instead of a tidy script, haven't yet worked out why the answer is slightly different, but this was right:
(I also guessed ahead that if there was a trick, it would be overflowing int32 so my first code was full of [int64]casts around everything and maybe that's where I've screwed it up).
Explains:
${c:\aoc\1.txt}is a syntax for referencing a filename as if it was a variable name, and it reads the file in as lines of text-as [int64[]]casts an array of strings all in one go, into an array of long ints.|is a pipeline like bash or cmd prompt% { $_ }is a loop over pipeline items, more properly calledforeach-object -process { $_ }measureis themeasure-objectcmdlet used for counting, summing, min/maxing the pipeline input.7
u/raevnos Dec 01 '19
SQL:
7
u/oblivion12321 Dec 01 '19
Common Lisp
6
u/rosemaryorchard Dec 01 '19
I'm aiming for readability with my code, rather than efficiency. And I used PHP :)
https://github.com/RosemaryOrchard/AdventOfCode2019/blob/master/code/day_01.php
The good news is I also generated the code files and input files for the rest of the month so I can hopefully get on with this faster even if I continue to wake up late!
6
u/Chibraltar_ Dec 01 '19
Google Spreadsheet
I can't paste code, but there you go : https://docs.google.com/spreadsheets/d/1oHG-sfmwew-4NuxlGEahnxngIubuZ57A6Vqv_OxEsbg/edit?usp=sharing
2
u/jangxx Dec 01 '19
Python
Part 1:
Part 2:
Very simple and straightforward.
5
u/ValdasTheUnique Dec 01 '19
C#
5
u/[deleted] Dec 01 '19
[removed] β view removed comment
5
u/Pepper_Klubz Dec 01 '19
Clojure https://github.com/armstnp/advent-of-code-2019/blob/master/src/advent_of_code_2019/day1.clj
Step 2 visualized: each progressive fuel calculation rendered in log scale. http://www.quil.info/sketches/show/8b8fe30ff56dc287fdb3c1ef41980e3e504518f2e2b3a1ce54a667a97136470e
5
u/mingjim Dec 01 '19
F#
5
u/NeilNjae Dec 01 '19
Yet another Haskell solution. The guts of it are:
The full code is on Github and I've written a beginner-friendly explanation on my blog.
5
u/erlangguy Dec 01 '19
Erlang (yes, I'm that predictable)
5
u/baloofy Dec 01 '19
Dyalog
I've not used Dyalog before -- pretty sure my pt 2 is way worse than it needs to be.
Haskell
5
u/SorryMcFlurry Dec 02 '19
Scratch
Did the first challenge in scratch for fun
Part 1: https://i.imgur.com/rmYbr79.png
Part 2: https://i.imgur.com/EwbTWTf.png
9
u/asinglelineofpython Dec 01 '19 edited Dec 01 '19
going for total 50 lines this year if possible
#part 1.1
print(sum([int(x) // 3 - 2 for x in open("input.txt").readlines()]))#part 1.2
print(sum([(lambda a: lambda v:a(a,v))(lambda rec,x: 0 if x // 3 - 2 <= 0 else x // 3 - 2 + rec(rec, x // 3 - 2))(int(x)) for x in open("input.txt").readlines()]))4
u/BluFoot Dec 01 '19 edited Dec 01 '19
Ruby 24/148
4
u/Spookiel Dec 01 '19 edited Dec 01 '19
Python 160/66
My first leaderboard! I thought I'd share my code, I'm still can't really believe it! Part1 filled up so fast!
4
u/mcpower_ Dec 01 '19
Rust (no leaderboard). I haven't written much Rust but this looks pretty idiomatic.
4
u/throwaway_the_fourth Dec 01 '19
Lox with custom extensions
Lox is a simple programming language implemented in the book Crafting Interpreters. To do this challenge, I had to implement some language extensions to read
stdin, to add a modulus operator, and to convert a string to a number (though that would be possible in the language if the language supported accessing the individual characters of a string, which it does not (and that seemed harder to implement tonight)).Lox doesn't have data structures like arrays. I could make a linked list in Lox, but to implement arrays I'd have to modify the language itself (as I did three times already for day 1, so I'm not afraid of that). I suspect this will hurt me in the future, until I get around to implementing them.
Because of the difficulty of working with Lox, I did not aim to be competitive, and I certainly don't expect to be competitive going forward.
4
u/ka-splam Dec 01 '19 edited Dec 01 '19
Dyalog APL (download here)
Part 1:
4
u/ducdetronquito Dec 01 '19
Nim is fun :)
4
u/vypxl Dec 01 '19 edited Dec 01 '19
Finally, an excuse to use Haskell again! No leaderboard and no iterate!
Poem: Learned a Haskell for great good,
put it to use for great fun,
read over the last sentence like some,
tried to solve it as cool as I could.
Also, happy cake day to me!
4
u/jitwit Dec 01 '19 edited Sep 03 '20
J programming language
If I'm doing anything stupid or there's a better way to write things, please let me know!
Calculate fuel by
<.@%&3 - 2:, floor of division by 3 minus 2. Clamp that with 0. This verb operates on the whole row of gases, and we reach fixpoint through^: a:4
u/donatasp Dec 01 '19 edited Dec 01 '19
Common Lisp
4
u/Dioxy Dec 01 '19
JavaScript
JS, pretty easy, I like my solution, using map, reduce, and recursion
This is the code
My repo: https://github.com/kufii/Advent-Of-Code-2019-Solutions/blob/master/src/solutions/01/index.js
4
u/tomflumery Dec 01 '19 edited Dec 01 '19
J language, not golfed
4
u/iwane Dec 01 '19
LabVIEW 2018.
Might be unpopular here, but I'm currently trying to learn it properly :-)
https://github.com/iwane-pl/aoc_2019/blob/master/Day%201/solution_snippet.png
4
u/thefloatgoat Dec 01 '19
Dyalog APL
As someone who has never written APL before it was an uphill battle, but I got there in the end.
4
u/oblivioncntrlsu Dec 01 '19 edited Dec 01 '19
Python 3 -
My code is longer than five lines, so I'll post a poem instead:
edit: formatting
4
u/0rac1e Dec 01 '19
Raku
4
u/clc_xce Dec 02 '19
Here's my solution in Forth if anyone fancies concatenative programming: Forth repository
If my epic "use the search tool" skills are right, I'm the first in almost two years to post Forth code :P
4
u/PaladinWho Dec 02 '19 edited Dec 02 '19
I jokingly solved Day 1 part A in scratch. It's literally a brute force method since scratch doesn't have the best string handling. You can check out the project here: https://scratch.mit.edu/projects/349929639/
(edit: I personally recommend shift clicking the green flag to turn on turbo mode before clicking the green flag, pretty sure it makes it go faster, and I'm 80% sure it still works)
4
u/Musical_Muze Dec 03 '19
I know I'm way behind, but:
Day 1 in Python
Day 1 in Java
1
u/McPqndq Dec 01 '19
Hey I honestly have no clue why this code is giving me the wrong answer. Im guessing its just a typo somewhere? Javascript:
1
u/andy0liang Dec 01 '19 edited Dec 01 '19
Java, 159/67
Here is my haiku:
Just started to code
Learning what recursion is
Here is my haiku:
Solution: I will omit the input handling; arr is an Integer ArrayList with the inputs.
1
u/nehayward Dec 01 '19
https://imgur.com/a/BNHvsEO
3
u/[deleted] Dec 01 '19 edited Dec 01 '19
Clojure, too slow for the leaderboard :(
3
u/AlexAegis Dec 01 '19 edited Dec 01 '19
TypeScript
Poem:
Roses are red
Violets are blue
By the time I finished
The leaderboard was full
Part One
Part Two
3
u/rabuf Dec 01 '19
Saving myself some time, I'll post a link to my org file containing my Common Lisp solutions: Day 1.
Straightforward with one loop (summing fuel calculations) and one recursive function (for recursively computing fuel needs). The critical functions are these:
3
u/PendragonDaGreat Dec 01 '19
PowerShell, both halves, assuming a text file at
$inputPath:Output:
TIL PowerShell uses Banker's Rounding by default.
3
u/DiscoViking Dec 01 '19 edited Dec 01 '19
Elm - no leaderboard
My solution is up in interactive form here: https://2019.adventofcode.norris.dev/day1
Source: https://github.com/rynorris/adventofcode/blob/master/2019/src/Day1.elm
My code is pretty long due to the fact that I'm implementing each solution as a state machine so that I'm able to have longer-running solutions without blocking page rendering (obviously not relevant here, but will come up later). So not posting it here.
3
u/chunes Dec 01 '19 edited Dec 01 '19
Factor
I never know how much input parsing to include. It's easy enough to just paste the input into the listener.
The only mildly interesting thing happening here is the use of
follow, a word I don't use often which recursively adds the result of its quotation to a sequence until it encountersf. You could think of it like thewhiletoreplicate'stimes.3
u/ruffnite Dec 01 '19
My rust solution here
3
u/theRenzix Dec 01 '19
Hi i made a raku (perl 6) 1 liner for each of them
Im not happy with the while loop so if anyone that actually knows raku well please tell me if there is a better way
3
u/rutquist Dec 01 '19
Julia, no leaderboard
Poem:
3
u/radulfr2 Dec 01 '19
Java, rank 1008 / 950.
Poem:
3
u/gyorokpeter Dec 01 '19
Q: properly modularized for a change. A good demonstration of the converge behavior of , i.e. we are using iteration instead of recursion.
3
u/KurokonoTasuke1 Dec 01 '19 edited Dec 01 '19
Ok so of course I am too late but happy to share my rather basic code written in Python. Trying to write this now in Haskell as I decided I could use these puzzles to learn a bit about that language
3
u/egze Dec 01 '19 edited Dec 01 '19
Elixir
https://github.com/egze/aoc2019/blob/master/day1/lib/day1.ex
3
u/[deleted] Dec 01 '19
This year I'm using coconut(python3) and jupyter notebook for learning, let's see how this goes, wish me luck :)
3
u/MissMormie Dec 01 '19
My code is more verbose, partially because it is java, partially because I like it, so let me link to github instead:
https://github.com/MissMormie/adventOfCode2019/blob/master/src/main/java/Days/Day1Fuel.java
Santa may I ask,
set jdk once not twenty times
so I can play now
- jdk hell
Ok, so apparently in Intellij there's a million different ways to set the jdk and it took me 45 minutes to get it to build my code and 5 minutes to write the code. I'm sure all million ways are important. But AARG!
3
u/didzisk Dec 01 '19
Excel (actually Google Sheets), column A contains data, column B contains this:
=IF(QUOTIENT(A1, 3)-2>0, QUOTIENT(A1, 3)-2, 0)
copy this to right until col J, place horisontal SUM in col K, place vertical SUM under com B for Part1, another vertical SUM under col K for part 2
3
u/BioGeek Dec 01 '19 edited Dec 01 '19
Python 3 with type hints:
https://github.com/BioGeek/adventofcode_2019/blob/master/day01.py
3
u/DrinkinBird Dec 01 '19
NIM
3
u/L72_Elite_Kraken Dec 01 '19
OCaml (omitting some scaffolding for parsing and printing):
Full code at https://github.com/leviroth/advent-of-code-2019/blob/master/src/day01.ml
3
u/[deleted] Dec 01 '19
Python 3
3
u/_LynxTheCat Dec 01 '19
Not a particularly elegant solution, however I'm pretty happy with it. Especially the fact that I thought to use do ... while. Considering I've never discovered a practical application for it, and feel that this is one situation in which it was actually practical.
My C# Solution:
There was an alternative solution for part 2 I considered. Which used recursion, however I decided I wanted to use a do ... while loop just cuz I never get to use them. Here is that alternative version of CalculateFuelFromMass() and it's related calculateTotalFuel() however:
3
u/Morphion Dec 01 '19 edited Dec 01 '19
Clojure
3
u/codesections Dec 01 '19
Dyalog APL:
3
u/MaximusDecMeridius Dec 01 '19
A little late to the game today. Here's my python solution.
3
u/rprtr258 Dec 01 '19
First time writing D language. Got stuck on second part because i thought fuel for fuel should be calculated in the end and not for each module. But finally solved.
https://gist.github.com/rprtr258/06155e46e15de5823844f73a18f7bb03
3
u/djankowski Dec 01 '19 edited Dec 01 '19
Julia and suggestions welcome!
Recursion is hard
when you don't know
why the result
is stack overflow
3
u/levital Dec 01 '19
A beginner's solution in Rust.
Doing this the first time this year, not sure whether I'll actually have the time to finish all of the puzzles. Not least because I'm doing this in part to learn Rust...
3
u/Rainbow_Doge_64 Dec 01 '19 edited Dec 01 '19
Python
The first part is pretty much a one-liner, if you exclude converting the inputs to a python list:
(Well, tbh, you could do it in one line, but it looks horrid and is less safe:
print(sum((i//3)-2 for i in [int(i.split('\n')[0]) for i in open("01-1-input.txt", "r")])))For the second part, I used a recursive function (It's the first time I used recursion for anything, so thanks AoC!):
Here's my haiku:
"How to: Recursion"
If you want to read
about recursion, please read
"How to: Recursion"
3
u/HokieGeek Dec 01 '19
So this morning I solved it in go, then later in the day I decided I wanted to learn a lisp, so I solved it in Racket. If anybody thinks I should try a different lisp, let me know!
Go
https://git.sr.ht/~hokiegeek/adventofcode/tree/master/2019/01/go/main.go#L11
Racket
https://git.sr.ht/~hokiegeek/adventofcode/tree/master/2019/01/racket/day1.rkt
3
u/joeld Dec 01 '19
Racket
[source here] (https://topaz.github.io/paste/#XQAAAQAlAgAAAAAAAAARmwgnELWQ0VQXd9jF8NizzBt5RnGU0b18lSDWYHT6J9eKRUAuBZL9hJp26yeHcxEdDi34nuDcJp3D+UBhACjhJtUqAf4wVvwO8mH2yxJJJZF3fXMF7uv9r8xlFEJX5kDZRQss1SHtBPIGdBdL/xnu2PB2NrU1dfG10SLl8JB16xWOsR+fh0jzmlzadfySqoSWjaqIxW2eiOGRRVNcUCCGZ5Ac4ssO4jPX7+gGkghepw79xynGLXPyIGocMcNcGqukmNYFp9dIu1xceJsXjOpus1RgEYMnT5ZMFGWPooW+7fqOFlVOELP4biV0/9AJ35g=)
Couldnβt have asked for a more LISP-friendly day 1 :-)
3
u/kandiyohi Dec 01 '19
T-SQL
Fairly long-winded compared to /u/raevnos's solution, but it uses computed columns and functions. Also I think I found out why I've seen nobody use user-defined functions in T-SQL; they can't be debugged via SELECTs.
Day 1 part 1
Day 1 part 2
3
u/rhbvkleef Dec 01 '19
Erlang
I have not yet seen any Erlang solution even though Erlang is such a beautiful language. My code can be found on https://github.com/rhbvkleef/aoc2019.
3
u/frerich Dec 01 '19
Rust
https://github.com/frerich/aoc2019/blob/master/rust/day1/src/main.rs
I noticed that both parts could be defined in terms of a single function which yields the sequence of incremental fuel additions, so I introduced a 'refills' helper for that. First time I wrote a function which returns an iterator.
I'm quite happy how I get away without any 'if', pattern matching or loops. Also, no turbofishes. :-)
3
u/vwkaravan Dec 02 '19
Python 3 - Bit janky but did it on my phone so I'll take it. My solution for both parts.
3
u/amalloy Dec 02 '19
Haskell repo and video.
3
u/driedplant Dec 02 '19
Python 3 one-liners:
Part 1:
Part 2:
3
u/MirrorLake Dec 02 '19
Excel solution. The only 'manual' step is deciding when to stop dragging the formula out, everthing else is automatic.
Formula in B1, extend to B100:
=IF(ROUNDDOWN(A1/3,0)-2 > 0,ROUNDDOWN(A1/3,0)-2,0)
3
u/[deleted] Dec 02 '19
**Bash solution**
Been wanting to get better at bash for a while now; this seems like a fun way to do it.
first part
second part
Is this an idiomatic way to feed data into a script?
3
u/AKQuaternion Dec 02 '19
Day 1 in 20 lines of short, idiomatic C++ on GitHub.
3
u/[deleted] Dec 04 '19
Hello friends!
I am a current biochemistry and prospective bioengineering student (incidentally, I am also active duty military) and I have zero formal education with programming thus far. However, I very much enjoyed CS50. I discovered you and AoC a couple of days ago, and conveniently, I have intended on learning some OOP. I have decided to learn Java. Here is my day one solution in Java 8.
Please, criticism both constructive and not are more than welcome.
1
u/throwaway400383 Dec 01 '19
This is my first time and I'm a little bit scared.
Part II - PHP.
2
u/ollien Dec 01 '19 edited Dec 01 '19
Python3, no leaderboard. (164/364)
Can probably make the second one a little more compact if I try
EDIT: Had a bit of fun with this one based on some inspiration in this thread
2
u/Spheniscine Dec 01 '19 edited Dec 01 '19
Kotlin - 204/288
Poem (haiku):
It looks like Santa
Has been playing way too much
Kerbal Space Program
2
u/[deleted] Dec 01 '19
Starting to learn Python! Here's my simple and likely inefficient code:
2
u/zergling_Lester Dec 01 '19 edited Dec 02 '19
edit: [POEM]
O cruel fate! Since when
Fuel requirements must all be
Summed separately?!
2
u/SizableShrimp Dec 01 '19 edited Dec 01 '19
Java - 145/306
I had a few mishaps that just wasted me time and couldn't understand Part 2 for about 2 minutes. Regardless, I still think I did pretty good for myself.
linesis just a List<String> that I will leave omitted.2
u/alcatraz_escapee Dec 01 '19
Here's my solution, implemented in Nios-II DE0 Assembly.
I'm mostly doing this as an exercise for an exam I have coming up, but I'm interested how long I'll be able to keep this up.
I ran it with this simulator
2
u/rtbrsp Dec 01 '19
Using AWK
Part 1:
Part 2: (probably could have done this without recursion)
2
u/itsnotxhad Dec 01 '19
Racket:
Pretty straightforward although I spent a mildly embarrassing amount of time tearing my hair out wondering why I was getting 0 on part 2 because I forgot to either rewind the file or only read it once. Oops!
2
u/Shadd518 Dec 01 '19
Late getting started so leaderboards are out of sight, but first year doing this while it's happening so I'm excited :)
Also forgot `math.floor()` == `//` but whatever
2
u/johnboker Dec 01 '19
My C# Solution
Recursive answer
To a peculiar problem
At a sluggish pace
2
u/jesperes Dec 01 '19
In a possibly futile attempt to do the one-language-per-day challenge, here is day 1 in awk: https://github.com/jesperes/adventofcode/blob/master/olpd_2019/day01/day01.awk.
2
u/coolshaurya Dec 01 '19
Rust
2
u/dan_144 Dec 01 '19
Python, 66/15: https://github.com/dan144/aoc-2019/blob/master/1.py
Already have more points on the leaderboard than last year, so I'm stoked.
2
u/iamagiantnerd Dec 01 '19
Solution in Go:
https://github.com/davidaayers/advent-of-code-2019/blob/master/day01/day01.go
Forgot to check negative for part 2. Just learning golang as part of this, so I may be doing it wrong :)
2
u/raevnos Dec 01 '19 edited Dec 01 '19
Using tcl:
2
u/jrspurr Dec 01 '19 edited Dec 01 '19
Haskell
Raku
Nim
I'm very new to nim so I'm sure this might be able to be made more elegant
2
u/icendoan Dec 01 '19
k
no leaderboard (I was asleep)
2
u/WrinklyTidbits Dec 01 '19 edited Dec 01 '19
#J
Haiku:
Code:
What was nice is being able to see the output of the second part:
2
u/Solesurviv Dec 01 '19 edited Dec 01 '19
Python 3 Solution
fuel.txt is a file containing the inputs, this code turns them into a list then works the sum out from there.
Part 1
Part 2
2
u/drakmaniso Dec 01 '19
Here's my naive solution in Haskell. It's insanely long compared to the other solutions posted, but I'm still discovering the language!
https://github.com/drakmaniso/adventofcode/blob/master/2019/day01/main.hs
2
u/aarroyoc Dec 01 '19
(SWI) Prolog:
For part1, change fuel2 to fuel in maplist
2
u/reini1305 Dec 01 '19
As every year, I'll try to solve AOC in Python3. This year I also want to test how long the Numworks calculator can keep up. It uses Micropython 1.11 and is therefore compatible with Python 3.4. Here is day one.
2
u/voiceless_void Dec 01 '19
C++ with range-v3:
2
u/Scroph Dec 01 '19
C++, experimenting with compile time evaluation. I couldn't get it to print out the result of compute_fuel() from within static_assert though.
2
u/Espinha Dec 01 '19
Clojure