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.

By the way I have an exam all day tomorrow so someone else make the thread thanks

Jump in the discussion.

No email address required.

k lol

Jump in the discussion.

No email address required.

Yeah... Yeah... :marseyrope:

Jump in the discussion.

No email address required.

good morning I hate parsing problems

N←≢r←5↓¨⊃⎕NGET'i2.txt'1 ⋄ s←~⍤∊⍨⊆⊢
m←{a←','∘s¨';'s 2⊃':'s ⍵ ⋄ b←∊¨¯1∘↑¨¨a ⋄ c←3↑¨⍎¨¨∊¨¨(∊∘⎕D⊆⊢)¨¨a ⋄ {⌈/(b⍳¨⍵)⌷¨c}¨'dne'}¨r
⎕←+/(⍳N)/⍨∧/¨12 13 14∘≥¨m ⋄ ⎕←+/×/¨m
Jump in the discussion.

No email address required.

I'd probably get fired if I started coding in wingdings at work :marseydisagree:

Jump in the discussion.

No email address required.

I think something went wrong when you pasted the code.

:#marseysweating:

Do you find golf languages like these are easier in some ways or is every problem always more of a challenge?

Jump in the discussion.

No email address required.

APL is unironically a great language. It was created as handwritten maths notation, it's not one of the meme langs designed around using as few characters as possible. Only part that sucks is parsing the input.

Jump in the discussion.

No email address required.

I'd rather KMS than use APL

Jump in the discussion.

No email address required.

>it's not one of the meme langs designed around using as few characters as possible

BIPOC that's what maths notation is

Jump in the discussion.

No email address required.

I mean shit like 05AB1E, where programs look like:

|»©ÐÙSDŠ¢øΣθ}R€н¬®sÅ?iD2£RDŠKsì}J©žLR‡®gö₅B®s"•ÿ•“ÿ“ÅвJ"

APL is a practical/"real" language, it wasn't designed to metagame golf at the expense of readability.

Jump in the discussion.

No email address required.

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

!codecels be amazed :marseymesmerized:

Jump in the discussion.

No email address required.

Heh, nothing personel kid:

public static void main(String[] args) {

System.out.println("Hello dorks.");

}

:#marseydab:


:#marseydisintegrate: :!#marseyflamewar::space::!marseyagree:

Jump in the discussion.

No email address required.

:#marseykneel:

Jump in the discussion.

No email address required.

whoa

Jump in the discussion.

No email address required.

I thought this would be more like interview questions where it's testing your brainpower instead of do you know how regex works

anyway here is my solution for part 2

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

Jump in the discussion.

No email address required.

From what I remember doing this a few years ago, the first few are just parsing, then it transitions into more interesting stuff.

Jump in the discussion.

No email address required.

It happens really fast too, they're all so easy you start getting a big head, then around day 10 shit gets real out of nowhere. I don't even know why I'm bothering with these right now when I'm almost positive I'll just rage quit again the first time I can't do it in half an hour.

Jump in the discussion.

No email address required.

Jump in the discussion.

No email address required.

When you realize the first few days are there to give the brainlets like me a sense of accomplishment before getting destroyed :#marseycrygenocide:

Jump in the discussion.

No email address required.

Could these descriptions be any longer?

:#marseylongpost:

Jump in the discussion.

No email address required.

You're not using GDscript are you :marseysquint:

Jump in the discussion.

No email address required.

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

Jump in the discussion.

No email address required.

I was sleeping when the new advent of code dropped so you'll look at my solution even if you missed it !codecels, I don't care that pinging the group will cost me a lot of coins.

Jump in the discussion.

No email address required.

I should probably learn regex someday this is clean af...

:marseykneel:

Jump in the discussion.

No email address required.

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

Note that games is const this time; apparently readLines is available at compile time. :marseyokay:

Jump in the discussion.

No email address required.

Lmao it's about a third of the lines of mine...

Learning Nim's syntax and std is kicking my butt, I'm spending all my energy in the docs and coming up with awful constructions.

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

I probably should have made loadGame an iterator.

Jump in the discussion.

No email address required.

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

If we ignore all the boilerplate it is almost small

Jump in the discussion.

No email address required.

Someday I will learn regex for real and leave the standard library behind, that's not today though.

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

Jump in the discussion.

No email address required.

Frick using c++ for this I'm going to sleep

Jump in the discussion.

No email address required.

:#marseythumbsup:

Jump in the discussion.

No email address required.

one liner for part 1

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

before some smartass comments this is one line WITHOUT LINEBREAKS yes I know it wraps lol

part 2 is a genuine monstrosity

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

Jump in the discussion.

No email address required.

With modern Python the one liner question is not if you could, but if you should

Jump in the discussion.

No email address required.

True. If I didn't have lambdas it probably would've been impossible. Or, at least, impossible in the constraint of not producing an identical complex value more than once

Jump in the discussion.

No email address required.

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

not the worst one to reason about. parsing the strings was the hardest part and python makes that 2ez.

Jump in the discussion.

No email address required.

does everyone text editor look like that or is that a special way to screenshot

Jump in the discussion.

No email address required.

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

It's the link from the OP

Jump in the discussion.

No email address required.

I learned that newer versions of Python got s.removeprefix('Game ') btw, yesterday, just in time for this. Otherwise a pretty uneventful day.

Jump in the discussion.

No email address required.

:#marseyowl:

Jump in the discussion.

No email address required.

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

There are those among us RIGHT NOW trying to write nice looking code (not me I just wanna go get lunch)

Jump in the discussion.

No email address required.

ngl I think last years were better

Jump in the discussion.

No email address required.

27 and 29 mins

https://files.catbox.moe/zjxyov.jpg

Jump in the discussion.

No email address required.

# Part One
bag = dict(red=12, green=13, blue=14)
total = 0
for line in data.splitlines():
   gid = re.search(r'Game (\d+)', line).group(1)
   cubes = re.findall(r'(\d+) ([a-z]+)', line)
   for count, color in cubes:
       if int(count) > bag[color]:
           break
   else:
       total += int(gid)
print(total)

# Part Two
total = 0
for line in data.splitlines():
   gid = re.search(r'Game (\d+)', line).group(1)
   cubes = re.findall(r'(\d+) ([a-z]+)', line)
   bag = dict(red=0, green=0, blue=0)
   for count, color in cubes:
       bag[color] = max(bag[color], int(count))
   p = bag['red'] * bag['green'] * bag['blue']
   total += p
print(total)
Jump in the discussion.

No email address required.

way easier than yesterday https://i.rdrama.net/images/1701497069318822.webp

Jump in the discussion.

No email address required.

Jump in the discussion.

No email address required.

aw jeez

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

Jump in the discussion.

No email address required.

You're using nano for show right? Nobody would actually write code on that thing.

Jump in the discussion.

No email address required.

nano is like that friend you've known since you were a kid

like that rando you got along with almost immediately

doesn't try to do extra stuff for you, will occasionally help you out, and although they improve on themselves a lot they never stop being who they are

friendly with a lot of people even though most people would prefer something extra, more popular, more flashy

nano just be nano

i fw nano unironically till the end

Jump in the discussion.

No email address required.

Foray into regex for me as a guy whose only experiencing importing files for coding is to work with very easily organized tabled data. I probably could have cleaned up the color finding into a function instead of dropping it under both the if and elif statement but oh well. I only had to add a single line to all of this multiplying the maxes for each game to get the answer for the second puzzle.

Python's documentation also really sucks for newbies, I think it's my biggest complaint with the language.

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

Jump in the discussion.

No email address required.

I'd be so much more open to python if I didn't have to give up whitespace and indent control

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.

This couldn't have come at a nicer time, I did these years ago and I haven't done any programming in so long

Going to brush up on some Kotlin because I've forgotten it entirely and I fell in love with it after dealing with Java

Jump in the discussion.

No email address required.

Part 2:

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

Jump in the discussion.

No email address required.

tl;dr

Jump in the discussion.

No email address required.

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

Not bad! Kind of wish I thought of a better way over iterating each of the colours every time but this works.

Also frick regex, I'm never learning it, it seems gay. String manipulation and parsing is the worst part of programming, anyone who thinks it's real programming should rope

Jump in the discussion.

No email address required.

#include <iostream>
#include <fstream>
#include <string>
#include <map>

using std::string;
using std::ifstream;
using std::cout;
using std::map;

auto main(int argc, char * argv[]) -> int
{
   ifstream readfile("day2_input.txt");
   string readline;
   int result1 = 0;
   int result2 = 0;
   int count = 0;
   map<string,int> limits{{"red", 12}, {"green", 13}, {"blue", 14}}; 

   while(getline(readfile, readline)){
       readline.erase(0, readline.find(": ")+2);
       readline.pop_back();
       readline += ";";
       bool is_possible = true;
       map<string,int> minimal = {{"red", 0}, {"green", 0}, {"blue", 0}};

       while(readline.size() > 0\. {
           string game_state = readline.substr(0, readline.find(";"));
           readline.erase(0, readline.find(";")+2);
           map<string,int> current = {{"red", 0}, {"green", 0}, {"blue", 0}};

           while(game_state.size() > 0\. {
               int n = std::stoi(game_state.substr(0, game_state.find(" ")));
               game_state.erase(0, game_state.find(" ")+1);
               string color = game_state.substr(0, game_state.find(" ")-1);
               current[color] += n;
               minimal[color] = std::max(minimal[color], n);
               game_state.erase(0, color.size()+2);
               if(limits["red"] < current["red"] || limits["green"] < current["green"] || limits["blue"] < current["blue"]) 
                   is_possible = false;
           }
       }
       count += 1;
       result2 += minimal["red"]*minimal["blue"]*minimal["green"];
       if(!is_possible)
           continue;
       result1 += count;
   }
   cout << result1 << '-' << result2 << '\n';
}
Jump in the discussion.

No email address required.

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