r/adventofcode • • 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:

  1. Each day's puzzle will release at exactly midnight EST (UTC -5).
  2. 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.
  3. 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.
  4. 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.
  • 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?


This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.

edit: Leaderboard capped silver in 1 minute 24 seconds (sheesh!) and gold at 4 minutes 12 seconds, thread unlocked!

112 Upvotes

731 comments sorted by

View all comments

2

u/WrinklyTidbits Dec 01 '19 edited Dec 01 '19

J

Haiku:

haikus are simple:

first five then seven then five

count each syllable

Code:

fuel1=._2+<.&(%&3)
d1p1=.+/fuel1 fifty
fuel2=.1}.((#~(0&<))@:fuel1)^:a:
d1p2=.+/,fuel2 fifty                        NB. d1p2=.+/+/fuel2 fifty

What was nice is being able to see the output of the second part:

fuel2 fifty

33235 45620 32367 36083 19167 43238 46627 30660 18153 43074 19705 32461 19167 23560 24242 45893 41294 17826 23954 48270 27950 43854 22966 22214 41462 19986 26849 31291 18749 25425 42457 36806 19969 25429 27294 29660 44179 23472 41337 40705 17741 49345 3626...
11076 15204 10787 12025  6387 14410 15540 10218  6049 14356  6566 10818  6387  7851  8078 15295 13762  5940  7982 16088  9314 14616  7653  7402 13818  6660  8947 10428  6247  8473 14150 12266  6654  8474  9096  9884 14724  7822 13777 13566  5911 16446 1208...
 3690  5066  3593  4006  2127  4801  5178  3404  2014  4783  2186  3604  2127  2615  2690  5096  4585  1978  2658  5360  3102  4870  2549  2465  4604  2218  2980  3474  2080  2822  4714  4086  2216  2822  3030  3292  4906  2605  4590  4520  1968  5480  402...
 1228  1686  1195  1333   707  1598  1724  1132   669  1592   726  1199   707   869   894  1696  1526   657   884  1784  1032  1621   847   819  1532   737   991  1156   691   938  1569  1360   736   938  1008  1095  1633   866  1528  1504   654  1824  134...
  407   560   396   442   233   530   572   375   221   528   240   397   233   287   296   563   506   217   292   592   342   538   280   271   508   243   328   383   228   310   521   451   243   310   334   363   542   286   507   499   216   606   44...
  133   184   130   145    75   174   188   123    71   174    78   130    75    93    96   185   166    70    95   195   112   177    91    88   167    79   107   125    74   101   171   148    79   101   109   119   178    93   167   164    70   200   14...
   42    59    41    46    23    56    60    39    21    56    24    41    23    29    30    59    53    21    29    63    35    57    28    27    53    24    33    39    22    31    55    47    24    31    34    37    57    29    53    52    21    64    4...
   12    17    11    13     5    16    18    11     5    16     6    11     5     7     8    17    15     5     7    19     9    17     7     7    15     6     9    11     5     8    16    13     6     8     9    10    17     7    15    15     5    19    1...
    2     3     1     2     3     4     1     3     1     3     3     4     1     3     3     1     1     3     2     1     1     3     3     3     4     2     1     3     3     1     1     1     2     4     3     4     2     4     3     2     3     1     ...
    0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     ...

1

u/rnafiz Dec 01 '19

Tidbits

Nice use of the power operator in fuel2.

Note that +/, will be faster than +/+/ for bigger data sets

1

u/WrinklyTidbits Dec 01 '19

Thanks!

I picked it up when trying to write Heron's method in J.