Unable to load image
Reported by:

rDrama Advent of Code Day *TWO*: High Turnout Edition

https://i.rdrama.net/images/17014924977518919.webp

Summary for those just joining us:

Advent of Code is an annual Christmas themed coding challenge that runs from December 1st until christmas. Each day the coding problems get progressively harder. We have a leaderboard and pretty good turnout, so feel free to hop in at any time and show your stuff!

Whether you have a single line monstrosity or a beautiful phone book sized stack of OOP code, you can export it in a nice little image for sharing at https://carbon.vercel.app

What did you think about today's problem?

https://adventofcode.com/2023

Our Code is 2416137-393b284c (No need to share your profile, you have the option to join anonymously if you don't want us to see your github)

50
Jump in the discussion.

No email address required.

Did it in Python. Too much string manipulation for me to waste time relearning it in C++. Might switch to Rust or something since it has better built-ins for that if more problems are like this.


def eatFile(fileName): 
  rawLines = []
  with open(fileName, 'r') as f:
     for line in f: 
        rawLines.append(line.strip('\n'))
  return rawLines

def processFile(rawData):
  powerSum = 0
  answer = ""
  badIds = []
  goodIds = []
  # Muh pythonics noooooo
  dataLen = len(rawData)
  for i in range(0, dataLen): 
     line = rawData[i]
     newLine = line.split(':')
     newLine[0] = newLine[0].split(' ')
     newLine[1] = newLine[1].split(';')
     lineLen = len(newLine[1])
     for j in range(0, lineLen):
        newLine[1][j] = newLine[1][j].split(',')
     gameId = newLine[0][1]
     goodIds.append(int(gameId))
     lineLen = len(newLine[1])
     gameMaxes = dict()
     gameMaxes["red"] = 0
     gameMaxes["green"] = 0
     gameMaxes["blue"] = 0
     for j in range(0, lineLen):
        subLineLen = len(newLine[1][j])

        for k in range(0, subLineLen):
           newLine[1][j][k] = newLine[1][j][k].strip(' ')
           num, type = newLine[1][j][k].split(' ')
           if gameMaxes[type] < int(num):
              gameMaxes[type] = int(num)

           # if maximums[type] < int(num) and gameId not in badIds:
           #    badIds.append(gameId)
           #    goodIds.remove(int(gameId))
     if gameId == "3":
        print(newLine[1][j])
        print(gameMaxes)
     powerSum += gameMaxes["red"] * gameMaxes["green"] * gameMaxes["blue"]
     rawData[i] = newLine
  # for line in enumerate(rawData): 
  #    newLine = line.split(':')
  #    newLine[0] = newLine[0].split(' ') #newLine[0][1] is the game ID
  #    newLine[1] = newLine[1].split(';') #Split between rounds
  #    for item in enumerate(newLine[1]):
  #       item = item.split(',')

  #       print(item)
  #    # print(newLine)
  # answer = sum(goodIds)
  print("Power Sum", powerSum)
  return powerSum

def main():
  # Total is 12 red cubes, 13 green cubes, and 14 blue cubes
  # Testing
  rawData = eatFile("testData.txt")
  answer = processFile(rawData)
  assert(answer == 2286)
  print(answer)

  # Real data
  rawData = eatFile("realData.txt")
  answer = processFile(rawData)
  print(answer)


maximums = dict()
maximums['red']= 12
maximums['green']= 13
maximums['blue']= 14
main()
Jump in the discussion.

No email address required.

:#bruh:

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.