Skip to content

Commit a81dad9

Browse files
committed
day1 solved
1 parent 7edeaa4 commit a81dad9

File tree

9 files changed

+141
-6
lines changed

9 files changed

+141
-6
lines changed

2019/day_04/Python/team_not_here/part2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ def count_possible_passwords(min_: str, max_: str) -> int:
4646
input_ = get_input()
4747
print(input_)
4848
result = count_possible_passwords(input_.min, input_.max)
49-
print(result)
49+
print(result)
File renamed without changes.

2020/day_01/Python/expenses.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from typing import Any, Union
2+
3+
4+
def read_input(filepath):
5+
6+
with open(filepath) as f:
7+
return list(map(int, f.readlines()))
8+
9+
def sum_to_target(transactions, target=2020):
10+
11+
transactions = set(transactions)
12+
# also makes a set {1,2,3}, but {} is an empty dictionary
13+
for bill in transactions:
14+
# sorry dave!
15+
if (target - bill) in transactions:
16+
return tuple(sorted((bill, (target - bill))))
17+
# defining a tuple
18+
19+
def find_target(transactions, target=2020):
20+
for number in transactions:
21+
new_target = target - number
22+
other_numbers = sum_to_target(transactions, new_target)
23+
if other_numbers is not None:
24+
return tuple(sorted((number, *other_numbers)))
25+
# * unpacks the tuple output by sum_to_target
26+
#
27+
28+
def main():
29+
30+
transactions = read_input('../input.txt')
31+
# print(transactions)
32+
33+
num1, num2 = sum_to_target(transactions)
34+
35+
part1_answer = num1 * num2
36+
37+
print(part1_answer)
38+
39+
num1, num2, num3 = find_target(transactions, target=2020)
40+
41+
part2_answer = num1 * num2 * num3
42+
43+
print(part2_answer)
44+
45+
46+
if __name__ == '__main__':
47+
main()
48+

2020/day_01/Python/expenses_part1.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from typing import Any, Union
2+
3+
4+
def read_input(filepath):
5+
6+
with open(filepath) as f:
7+
return list(map(int, f.readlines()))
8+
9+
def sum_to_2020(transactions):
10+
11+
transactions = set(transactions)
12+
# also makes a set {1,2,3}, but {} is an empty dictionary
13+
for bill in transactions:
14+
# sorry dave!
15+
if (2020 - bill) in transactions:
16+
return tuple(sorted((bill, (2020 - bill))))
17+
# defining a tuple
18+
19+
20+
21+
def main():
22+
23+
transactions = read_input('../input.txt')
24+
# print(transactions)
25+
26+
num1, num2 = sum_to_2020(transactions)
27+
28+
answer = num1 * num2
29+
30+
print(answer)
31+
32+
if __name__ == '__main__':
33+
main()
34+

2020/day_01/Python/test_expenses.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from expenses import sum_to_target
2+
from expenses import find_target
3+
4+
def test_sum_to_target():
5+
testnumbers=[1721,979,
6+
366,
7+
299,
8+
675,
9+
1456]
10+
11+
expected = (299, 1721)
12+
13+
actual = sum_to_target(testnumbers)
14+
assert expected == actual
15+
16+
def test_find_target():
17+
testnumbers=[1721,979,
18+
366,
19+
299,
20+
675,
21+
1456]
22+
23+
expected = (366, 675, 979)
24+
25+
actual = find_target(testnumbers)
26+
assert expected == actual
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from expenses_part1 import sum_to_2020
2+
3+
def test_sum_to_2020():
4+
testnumbers=[1721,979,
5+
366,
6+
299,
7+
675,
8+
1456]
9+
10+
expected = (299, 1721)
11+
12+
actual = sum_to_2020(testnumbers)
13+
assert expected == actual

2020/day_01/input.txt

-1
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,3 @@
198198
1442
199199
1082
200200
1071
201-

2020/day_01/instructions_part1.txt

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
--- Day 1: Report Repair ---
22

3-
After saving Christmas five years in a row, you've decided to take a vacation at a nice resort on a tropical island. Surely, Christmas will go on without you.
3+
After saving Christmas five years in a row, you've decided to take a vacation at a nice resort on a tropical island.
4+
Surely, Christmas will go on without you.
45

5-
The tropical island has its own currency and is entirely cash-only. The gold coins used there have a little picture of a starfish; the locals just call them stars. None of the currency exchanges seem to have heard of them, but somehow, you'll need to find fifty of these coins by the time you arrive so you can pay the deposit on your room.
6+
The tropical island has its own currency and is entirely cash-only.
7+
The gold coins used there have a little picture of a starfish; the locals just call them stars.
8+
None of the currency exchanges seem to have heard of them, but somehow,
9+
you'll need to find fifty of these coins by the time you arrive so you can pay the deposit on your room.
610

711
To save your vacation, you need to get all fifty stars by December 25th.
812

9-
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
13+
Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar;
14+
the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
1015

11-
Before you leave, the Elves in accounting just need you to fix your expense report (your puzzle input); apparently, something isn't quite adding up.
16+
Before you leave, the Elves in accounting just need you to fix your expense report (your puzzle input);
17+
apparently, something isn't quite adding up.
1218

1319
Specifically, they need you to find the two entries that sum to 2020 and then multiply those two numbers together.
1420

2020/day_01/instructions_part2.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
--- Part Two ---
2+
3+
The Elves in accounting are thankful for your help;
4+
one of them even offers you a starfish coin they had left over from a past vacation.
5+
They offer you a second one if you can find three numbers in your expense report that meet the same criteria.
6+
7+
Using the above example again, the three entries that sum to 2020 are 979, 366, and 675. Multiplying them together produces the answer, 241861950.
8+
9+
In your expense report, what is the product of the three entries that sum to 2020?

0 commit comments

Comments
 (0)