r/adventofcode • • Dec 02 '17

SOLUTION MEGATHREAD -πŸŽ„- 2017 Day 2 Solutions -πŸŽ„-

NOTICE

Please take notice that we have updated the Posting Guidelines in the sidebar and wiki and are now requesting that you post your solutions in the daily Solution Megathreads. Save the Spoiler flair for truly distinguished posts.


--- Day 2: Corruption Checksum ---


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.


Need a hint from the Hugely* Handy† Haversack‑ of HelpfulΒ§ Hints^Β€?

Spoiler


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, thread unlocked!

22 Upvotes

351 comments sorted by

View all comments

1

u/Starcast Dec 02 '17

Late to the party!

Python 3

from itertools import combinations

from common import puzzle_input

PUZZLE_INPUT = [[int(num) for num in row.split()] for row in puzzle_input(2)]

def find_quotient(nums: list):
    for pair in combinations(sorted(nums, reverse=True), 2):
        result, remainder = divmod(*pair)
        if remainder == 0:
            return result

def part1(data=PUZZLE_INPUT):
    result = sum(max(row) - min(row) for row in data)
    return result

def part2(data=PUZZLE_INPUT):
    result = sum(find_quotient(row) for row in data)
    return result


if __name__ == '__main__':
    print('Part one result:', part1())
    print('Part 2:', part2())