mirror of
https://github.com/ershisan99/advent-of-code.git
synced 2025-12-16 20:49:24 +00:00
2015 day 2
This commit is contained in:
@@ -1,4 +1,11 @@
|
|||||||
input = open("input.txt").read()
|
import os
|
||||||
|
|
||||||
|
script_dir = os.path.dirname(__file__) # <-- absolute dir the script is in
|
||||||
|
rel_path = "./input.txt"
|
||||||
|
abs_file_path = os.path.join(script_dir, rel_path)
|
||||||
|
|
||||||
|
input = open(abs_file_path).read()
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
for i, char in enumerate(list(input), start=1):
|
for i, char in enumerate(list(input), start=1):
|
||||||
if char == "(":
|
if char == "(":
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
input = open("input.txt").read()
|
import os
|
||||||
|
|
||||||
|
script_dir = os.path.dirname(__file__) # <-- absolute dir the script is in
|
||||||
|
rel_path = "./input.txt"
|
||||||
|
abs_file_path = os.path.join(script_dir, rel_path)
|
||||||
|
|
||||||
|
input = open(abs_file_path).read()
|
||||||
|
|
||||||
count = 0
|
count = 0
|
||||||
for i, char in enumerate(list(input), start=1):
|
for i, char in enumerate(list(input), start=1):
|
||||||
if char == "(":
|
if char == "(":
|
||||||
|
|||||||
1000
2015/day-2/input.txt
Normal file
1000
2015/day-2/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
22
2015/day-2/part-1.py
Normal file
22
2015/day-2/part-1.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
script_dir = os.path.dirname(__file__) # <-- absolute dir the script is in
|
||||||
|
rel_path = "./input.txt"
|
||||||
|
# rel_path = "./test-input.txt"
|
||||||
|
|
||||||
|
abs_file_path = os.path.join(script_dir, rel_path)
|
||||||
|
|
||||||
|
input = open(abs_file_path).read()
|
||||||
|
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
lines = input.splitlines()
|
||||||
|
for line in lines:
|
||||||
|
dimensions = list(map(int, line.split("x")))
|
||||||
|
dimensions.sort()
|
||||||
|
area1 = dimensions[0] * dimensions[1] * 2
|
||||||
|
area2 = dimensions[1] * dimensions[2] * 2
|
||||||
|
area3 = dimensions[0] * dimensions[2] * 2
|
||||||
|
total = area1 + area2 + area3 + int(area1 / 2)
|
||||||
|
count += total
|
||||||
|
print(count)
|
||||||
24
2015/day-2/part-2.py
Normal file
24
2015/day-2/part-2.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
script_dir = os.path.dirname(__file__) # <-- absolute dir the script is in
|
||||||
|
rel_path = "./input.txt"
|
||||||
|
# rel_path = "./test-input.txt"
|
||||||
|
|
||||||
|
abs_file_path = os.path.join(script_dir, rel_path)
|
||||||
|
|
||||||
|
input = open(abs_file_path).read()
|
||||||
|
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
lines = input.splitlines()
|
||||||
|
for line in lines:
|
||||||
|
dimensions = list(map(int, line.split("x")))
|
||||||
|
dimensions.sort()
|
||||||
|
[l, w, h] = dimensions
|
||||||
|
|
||||||
|
perimiter = l * 2 + w * 2
|
||||||
|
volume = l * w * h
|
||||||
|
count += perimiter + volume
|
||||||
|
print(count)
|
||||||
|
|
||||||
|
# 48
|
||||||
2
2015/day-2/test-input.txt
Normal file
2
2015/day-2/test-input.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
2x4x3
|
||||||
|
1x1x10
|
||||||
Reference in New Issue
Block a user