mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Move 2015 out of the way.
This commit is contained in:
21
2015/day-02/solution.py
Normal file
21
2015/day-02/solution.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from __future__ import print_function
|
||||
import fileinput
|
||||
from operator import mul
|
||||
from functools import reduce
|
||||
import itertools
|
||||
|
||||
totalArea = 0
|
||||
totalRibbon = 0
|
||||
for line in fileinput.input():
|
||||
parts = [int(i) for i in line.split('x')]
|
||||
parts.sort()
|
||||
|
||||
sides = [x * y for x, y in itertools.combinations(parts, 2)]
|
||||
totalArea += 2 * sum(sides) + min(sides)
|
||||
|
||||
totalRibbon += 2 * (parts[0] + parts[1])
|
||||
totalRibbon += reduce(mul, parts, 1)
|
||||
|
||||
print(totalArea, "paper")
|
||||
print(totalRibbon, "ribbon")
|
||||
|
||||
Reference in New Issue
Block a user