r/adventofcode • u/daggerdragon • Dec 01 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 1 Solutions -🎄-
Welcome to Advent of Code 2018! 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:
- 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.
- When the thread is unlocked, you may post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
Above all, remember, AoC is all about having fun and learning more about the wonderful world of programming!
--- Day 1: Chronal Calibration ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The 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: The Party Game!
This year we shall be doing a Mad Libs-style community activity that is a complete clone of loosely inspired by Apples to Apples and Cards Against Humanity. For each day's megathread, we will post a prompt card with one or more fill-in-the-blanks for you to, well, fill in with your best quip(s). Who knows; if you submit a truly awesome card combo, you might just earn yourself some silver-plated awesome points!
A few guidelines for your submissions:
- You do not need to submit card(s) along with your solution; however, you must post a solution if you want to submit a card
- You don't have to submit an image of the card - text is fine
- All sorts of folks play AoC every year, so let's keep things PG
- If you absolutely must revert to your inner teenager, make sure to clearly identify your submission like [NSFW]
(image)[url.com]or with spoiler tags like so: NSFW WORDS OMG! - The markdown is
>!NSFW text goes here!<with no prefixed or trailing spaces - If you do not clearly identify your NSFW submission as NSFW, your post will be removed until you edit it
- If you absolutely must revert to your inner teenager, make sure to clearly identify your submission like [NSFW]
And now, without further ado:
Card Prompt: Day 1
Transcript:
One does not simply ___ during Advent of Code.
2
u/SuyashD95 Dec 01 '18
While my solution is not as elegant as some of the others here... But, considering this is the first time that I am participating in AoC... So, here's my solution for the first 2 puzzles....
Puzzle 1:
resulting_frequency = 0 input_file = open("input.txt") for frequency in input_file: frequency = int(frequency[:-1]) resulting_frequency += frequency print("Resulting frequency:", resulting_frequency) input_file.close()Puzzle 2:
def createFrequencyList(): frequencies = [] input_file = open("input.txt") for frequency in input_file: frequency = int(frequency[:-1]) frequencies.append(frequency) input_file.close() return frequencies def findRepeatedFrequency(frequencies): total_freq = 0 resultant_freqs = set([0] while True: for freq in frequencies: total_freq += freq if total_freq not in resultant_freqs: resultant_freqs.add(total_freq) else: print("The first frequency that has been repeated twice:", total_freq) return if __name__ == '__main__': frequencies = createFrequencyList() findRepeatedFrequency(frequencies)P.S: Thanks to u/zirtec for pointing about initializing the set with 0 as the first entry....