There's a tricky and crucial difference between the example data and the real data!
Day 7 done ! ✅
And the pain is starting !
Workflow and macro :
Tough challenge! I struggled to create the logic.
Tricky! So many different scenarios to keep in mind. Got first wrong earlier because I didn't think same directory names in different paths.
Definitely one to work through while not sleepy and a day where having the example input made checking the logic much easier
And created a batch macro to add up the nested directories.
I had the example data working in 10 minutes, but like @clmc9601 mentioned there are some key differences to be aware of.
Can't wait to take a look at other solutions when I have some sleep under my belt!
After getting it easy for D6, D7 picks up again.
I have opted for flexibility and readability in building my solution, and inserted sort tools before Multi-row, as a best practice although they may not be strictly needed, so that I can flip between using/not using grouping in Multi-row. The downside is that a lot more tools are probably needed.
1) Step 1: Instead of getting the full path for every line, I opted to filter out the command lines to get the active directory at each command. Lesser lines = easier for me to read and debug the logic.
2) Step 2: Recombine the generate the full path for all files and sub-folders.
3) Generate (i) direct size and (ii) level for each file and sub-folder
4) Actual solving for Part 1 and Part 2
Iterative macro to calculate size of the sub-folders.
It's a tough one for me. Will have to figure out how the others managed to solve so parsimoniously!😎
My take for Day-7. I have the story first workflow worked with sample data but was failing with the actual data 😅🤣
Happy Analyzing Cheers and have a nice day!
I was a little surprised that my and @clmc9601 look so similar. Welcome surprise that I'm not building a stupid solution this time.
I was able to cut it down to a very similar solution to Claire, the only difference being, that I save another tool for Part 2 (she can probably reduce her solution as well. On a note: I think your solution ( @clmc9601 ) might have a small mistake in Part 2. I think you should use all elements and not only the ones that are larger than 100000, or I misread something. Either way, one of us was lucky today
This problem felt similar to some from the past.
EDIT: I could delete some redundant tools and get it down to this:
My refractor 2nd attempt, taking a lot of hints from @grossal and @clmc9601 . Concurred with @grossal on both the extra tool and the error in the WF (although not affecting the solution). Still have not figured out how the Tile tool works in @AkimasaKajitani solution
I managed to find a 6 tool solution to part 1. Still need to find time to look at part 2.
My 2nd solution. This is No Macro solution. Part 1 has 6 tools.
Missed a space in a formula ">😐
Originally I made an iterative macro to join directories onto previous levels, like Weekly challenge 12 - but the directory names are not unique so everything exploded.
I will not stop creating unique and hideous solutions and will not clean it up after the fact. Those tools were a process
Good catch, @grossal! I actually did that intentionally, although it makes it less dynamic. I knew that the needed disk space was >1000000 so all of those rows would exit the false anchor of the next filter anyway.
@DawnDuong Tile tool shows the folder level(depth).
/ x / y / z
x = depth level 1
y = depth level 2
z = depth level 3
Honeslty, my first solution is not elegant. It was the result of a struggle.
Fun one today with my favourite ever generate rows. I pulled the answers needed from both parts by skimming the output of the last tool rather than explicitly filtering down to it.
Finally got Day #7 done! This was honestly awful and took way longer than any human should spend on a workflow.
Finally! Big assist to Kelsey whose logic got me across the finish line.
My solution is not my most elegant. And I'm morally opposed to repeated folder names in the nesting.
what a mess - this took WAY longer than it should have - I was stuck on a bad RegEx path and had to abandon that.
Dirty solution below
This creates a folder for every file - and then duplicates each file for every level of parent.Much more painful than it needed to bePart 2:Just took the working data from part 1 and popped them into a different summary. Once I'd done part 1 - part 2 was a breeze.
My solution.
I am not good at macros, but this time it worked.
Main
Multi-Row Formula to get Path
IF [Field_1] = "$ cd /"THEN ""
ELSEIF [Field_1] = "$ cd .."THEN RegEx_Replace([Row-1:Path], "(.*/).*/", "$1")
ELSEIF StartsWith([Field_1], "$ cd ")THEN [Row-1:Path] + Replace([Field_1], "$ cd ", "") + "/"
ELSE [Row-1:Path]ENDIF
Macro to get total size of files under a Path
I didn't use a macro! Mostly because I was copy and pasting a set of tools to test my logic before building the macro, once I'd tested 4 levels it was one copy and paste and as much clicking as making the iterative macro to get to the answer. Already lost hours to it so stormed ahead with the "it ain't pretty but it works" approach, as with most of my AoC attempts. Stil. Got stars and that's what we're here for. Will return and do the macro properly soon...
I'm sure there's a more efficient Python solution than this #SnakingMyWayThroughChallenges
Thanks @balders-ie's hint, FileGetDir() is a life changer. Part 2 confused me quite a bit, after reading the questions over and over again, just used common sense for it.
This was definitely a tricky one!
Took inspiration from @clmc9601 's workflow
working through my backlog of old challenges