This is my first ever challenge and I was amazed by the challenges. I am proficient in Python so all codes will be on Python3.
Day 1 seems to be easier to tackle.
I am saving my input as day1.txt
on same directory as my Jupyter Notebook is.
with open("day1.txt", "r") as fp:
num = fp.readlines()
# print(num)
num = [int(i.split("\n")[0]) for i in num]
print("Solution: 1\n")
# solution 1
for i in num:
if 2020-i in num:
print(i, 2020-i, i*(2020-i))
print("Solution: 2\n")
# solution 2
for i in num:
for j in num:
if (2020-i - j) in num:
print(2020-i-j, i, j)
Result of above code is given below:
Solution: 1
933 1087 1014171
1087 933 1014171
Solution: 2
566 59 1395
1395 59 566
566 1395 59
59 1395 566
1395 566 59
59 566 1395
I write blogs about Computer Vision projects on my GitHub page q-viper.github.io and if you got some time please share yours too.
Top comments (2)
Who's setting these challenges?
Please follow adventofcode.com