with open('AdventOfCode2022/input.txt', 'r') as input:
commands = input.read().split('\n')
def new_dict(name, parent=None):
return {
'name': name,
'parent':parent,
'files': 0,
'dirs': {}
}
root_dict = new_dict(name='/', parent=None)
curr_dict = root_dict
#Build tree of dicts
for i in range(len(commands)):
command_parts = commands[i].split(' ')
if command_parts[0] == '$':
if command_parts[1] == 'cd':
if command_parts[2] == '..':
curr_dict = curr_dict['parent']
elif command_parts[2] == '/':
pass
else:
curr_dict = curr_dict['dirs'][command_parts[2]]
elif command_parts[0] == 'dir':
if command_parts[1] not in curr_dict:
curr_dict['dirs'][command_parts[1]] = new_dict(name=command_parts[1], parent=curr_dict)
elif command_parts[0] == '':
pass
else:
curr_dict['files'] += int(command_parts[0])
#PART ONE
MAX_THRESHOLD = 100000
FINAL_COUNTER = 0
dict_list = []
def parse_dict(t_dict):
folder_total = t_dict['files']
for c_dict in t_dict['dirs'].keys():
folder_total += parse_dict(t_dict['dirs'][c_dict])
global dict_list
dict_list.append(folder_total)
if folder_total < MAX_THRESHOLD:
global FINAL_COUNTER # this is the most embarrassing thing I've ever done
FINAL_COUNTER += folder_total
return folder_total
total_used = parse_dict(root_dict)
print(FINAL_COUNTER)
#PART TWO
TOTAL_SPACE = 70000000
WANTED_SPACE = 30000000
curr_wanted = WANTED_SPACE - (TOTAL_SPACE - total_used)
larger_than_wanted = []
for i in dict_list:
if i > curr_wanted:
larger_than_wanted.append(i)
print(min(larger_than_wanted))
Advent of Code 2022: Day 7
https://adventofcode.com
- 59
- 32
Jump in the discussion.
No email address required.
Finally into the fun problems Congrats to whichever one of you is Sneeds-Feeduck-And-Seeduck! Per usual, cleaned up a bit before posting.
Jump in the discussion.
No email address required.
More options
Context
I got the recursive functions to one line of barely legible python
Jump in the discussion.
No email address required.
Some people are able to display their intelligence by going on at length on a subject and never actually saying anything. This ability is most common in trades such as politics, public relations, and law. You have impressed me by being able to best them all, while still coming off as an absolute idiot.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
worried a bit about full paths but they never appeared
Jump in the discussion.
No email address required.
God i didnt even want to think about what part 2 would be. I just banked on it being a 2-3 line modification like the others.
Once that stops im gonna get reamed
Jump in the discussion.
No email address required.
More options
Context
More options
Context
I guess I'm smart enough to code this, but dumb enough to try to submit the directory name for part 2 over and over and then get angry when it won't accept my answer. Apparently, I have forgotten how to read.
Jump in the discussion.
No email address required.
More options
Context
trans lives matter
I ended up taking a break halfway through. Coding in C was always going to be a challenge but I wanted to do it because I like C . Overall my program is super incomplete - I didn't bother freeing any of the memory and I think I still have some errors in valgrind. I need to learn to use gdb one day. For the second part I didn't even bother writing a sorting algorithm - I just listed all the numbers and used an online sorter because I was tired .
Jump in the discussion.
No email address required.
do c-cels really
Jump in the discussion.
No email address required.
true programmers don’t need generics, they simply use macros
Jump in the discussion.
No email address required.
More options
Context
More options
Context
All them words won't bring your pa back.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
Excel stopped being viable day 3, but gl my programmer sock friends
Jump in the discussion.
No email address required.
More options
Context
I did this during a conference call and people kept asking me questions and i kept losing my place but I got there eventually
Jump in the discussion.
No email address required.
More options
Context
APLchads....
Jump in the discussion.
No email address required.
More options
Context
it got super messy, but i had fun solving this one tbh. the way i built my all_dirs list in particular is pretty hacky and scuffed, please tell me the smarter way to do it
Jump in the discussion.
No email address required.
You are the first dramatard who managed to subtract 3 from 7 LMAO.
Jump in the discussion.
No email address required.
But that's a magic number! Those are bad!
Jump in the discussion.
No email address required.
hey atheists, if you don't believe in magic, how come you are afraid of magic numbers? checkmate
Jump in the discussion.
No email address required.
More options
Context
More options
Context
Jump in the discussion.
No email address required.
Don't get too proud of yourself,
if line[0] in tuple("1234567890")
is unnecessary on several levels, alsofor _ in range(1000):
is quite pointless.Jump in the discussion.
No email address required.
which way is better?
true it's r-slurred but it just werked
Jump in the discussion.
No email address required.
if line[0] in "1234567890"
would work but at that point why not just force-cast the whole thing to int and see what happens?I honestly don't get what it does: is it the megatard way of building subdirectory trees?
Jump in the discussion.
No email address required.
oh
it gets a layer deeper every pass. i decided to do that because i thought of it fast. unlike many other (cowardly) uses here, i dont change my code at all before posting other than adding # part 1 and # part 2. embrace the megatard within.
Jump in the discussion.
No email address required.
tardking shit my neighbor
Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context
Have you owned the libs yet?
Jump in the discussion.
No email address required.
More options
Context
More options
Context
Jump in the discussion.
No email address required.
Is this (picrel) the same language? If yes that's quite the mogging
Jump in the discussion.
No email address required.
They're using dyalog APL (still being developed today), I'm stuck with GNU APL (was cutting edge in the 1980s). If you have a choice definitely go for dyalog.
Jump in the discussion.
No email address required.
do you own an apl keyboard?
also i checked out https://www.dyalog.com/uploads/documents/MasteringDyalogAPL.pdf and had a hearty chuckle at this considering what most apl looks like.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
What language?
Ah, APL?
Jump in the discussion.
No email address required.
More options
Context
More options
Context
C++chads simply cannot stop winning
Jump in the discussion.
No email address required.
More options
Context
javascript needs a standard library, and rust-style pattern matching (just a combination of switch statements and struct unpacking), and also pattern matching on strings (like - match (string) { "$ ls": ...; "$ cd ${f}": ...; "dir ${f}": ...; "${size} ${file}": ...; })
you could combine the parsing and directory creating parts to make it shorter - that's bad code in a larger piece of software because you'll need to read it later, but this is throwaway code lol
Jump in the discussion.
No email address required.
More options
Context
c++
fml got stuck for minutes because I am too dumb to read. First I was looking for directories bigger than 100.000 and then looked for
70.000.000 - total_size
, instead of30.000.000 - 70.000.000 - total_size
Jump in the discussion.
No email address required.
Your C++ code looks pretty clean compared to my C code
Jump in the discussion.
No email address required.
Lua > C > all other programming languages > c++
@BeauBiden @SoreNoell @grizzly @MarseyIsMyWaifu @nekobit @jc @sneks discuss
Jump in the discussion.
No email address required.
i program in CMake
Jump in the discussion.
No email address required.
More options
Context
More options
Context
c is hard all that malloc
Jump in the discussion.
No email address required.
More options
Context
More options
Context
Are you feeling okay bud?
Jump in the discussion.
No email address required.
More options
Context
More options
Context
Jump in the discussion.
No email address required.
More options
Context
gonna need to start pastebinning these as the answers get longer. what's the nicest anonymous one? http://dpaste.org?
Jump in the discussion.
No email address required.
https://carbon.vercel.app/ is what I use
Jump in the discussion.
No email address required.
More options
Context
More options
Context
Oh FRICK I FORGOT ABOUT IT
Jump in the discussion.
No email address required.
More options
Context
wtf they added a timeout if you enter wrong things? and i wasnt even spamming stuff
Jump in the discussion.
No email address required.
Also you were spamming stuff lol.
Jump in the discussion.
No email address required.
More options
Context
i don't understand how people have this happen, just run your code against the dummy input they give you and verify you get the right output
Jump in the discussion.
No email address required.
Not necessarily, I'm getting the right answer with their testinput and the wrong answer on the real one
Jump in the discussion.
No email address required.
how tho
Jump in the discussion.
No email address required.
Not sure yet. I'm fairly certain I must be miscounting something as the file paths get deeper but haven't had time to hunt down exactly what I did wrong yet.
Jump in the discussion.
No email address required.
Not 100% sure, but I think you are forgetting that the size of a directory is the size of the files in it and all the files in directories beneath it. So, its recursive
Jump in the discussion.
No email address required.
More options
Context
That was a mistake. You're about to find out the hard way why.
Jump in the discussion.
No email address required.
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context
More options
Context
guess who does not know data structures and spent way too long looking at debug prints to figure out wtf was going on
Jump in the discussion.
No email address required.
More options
Context
Jump in the discussion.
No email address required.
More options
Context
i hate python i hate python i hate python
Jump in the discussion.
No email address required.
Me while trying to figure out why my str variables got saved to each constructed object but my array variables didn't
Jump in the discussion.
No email address required.
More options
Context
More options
Context
Frick it's gonna filter me so hard
I know how 2 tree in OCaml but I never even touched OOP in Matlab
Jump in the discussion.
No email address required.
ogey I've done it
too ashamed of my code so I'll clean it up after I sleep before posting
Jump in the discussion.
No email address required.
More options
Context
More options
Context
Completed it.
My code is really messy . I don't wanna sharenvm posted as OP without cleanup
Jump in the discussion.
No email address required.
More options
Context
Snapshots:
archive.org
ghostarchive.org
archive.ph (click to archive)
Jump in the discussion.
No email address required.
SNAPPY NOOOOOO
Jump in the discussion.
No email address required.
More options
Context
More options
Context
cleaned my MATLAB () code, merged both parts and made it a bit better
Jump in the discussion.
No email address required.
More options
Context
Probably went over the top on this one but was a fun step-up from the previous challenges so far.
Jump in the discussion.
No email address required.
If only you could put that energy into your relationships
Jump in the discussion.
No email address required.
More options
Context
More options
Context
Fricking graphs in Rust made me wanna keep myself safe and reconsider the choice of language for this shit
At least the task itself was pretty easy
(And the fricking site died just I was submitting solution for the 2nd part)
If anyone wants to see the code: https://pastebin.com/7vMxeBJN
Can't be bothered to clean it up
Jump in the discussion.
No email address required.
More options
Context
Jump in the discussion.
No email address required.
first Java programmer I’ve seen
Jump in the discussion.
No email address required.
More options
Context
I don't have enough spoons to read this shit
Jump in the discussion.
No email address required.
More options
Context
More options
Context
Start - 38345214
The file system for anyone interested.
Jump in the discussion.
No email address required.
K
Jump in the discussion.
No email address required.
More options
Context
More options
Context