Avent of Code - Day 01 - Calorie CountingsteemCreated with Sketch.

in Witness Activities2 years ago (edited)

Advent of Code occurs at Dec 01 to 25 where each day, you will need to solve a puzzle. It is Festival and the problem statement is mostly related to Christmas.

image.png

You can join my leaderboard by entering this code 1019229-a302d391

Day 01 - Calorie Counting

Finding the Largest Sum of a Group
https://adventofcode.com/2022/day/2

The first few days are usually simple/easy/trivial. You don't need to submit code, but you would probably need to write code to get the answer. Some people can solve easy ones in Excel.

Q1 - the largest sum

file1 = open("0.txt", "r")
ans = []
cur = 0
while True:
        line = file1.readline()
        if not line:
                break
        line = line.strip()
        if not line:
                ans.append(cur)
                cur = 0
        else:
                cur += int(line)

ans.sort()
print(ans[-1] + ans[-2] + ans[-3])

Q2 - the largest 3 sums

file1 = open("0.txt", "r")
ans = []
cur = 0
while True:
        line = file1.readline()
        if not line:
                break
        line = line.strip()
        if not line:
                ans.append(cur)
                cur = 0
        else:
                cur += int(line)

ans.sort()
print(ans[-1] + ans[-2] + ans[-3])

Steem to the Moon!

Sort:  

I'd considered creating a STEEM AoC leaderboard, but in the end I'm doing my best to ignore AoC this year, as it can be such a timesink!

But it's really really fun and worth doing. I got 27 stars last year, and 50 in 2015!

Nice.. AoC is fun. Come join us.

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.029
BTC 60250.23
ETH 2335.37
USDT 1.00
SBD 2.52