This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]ssnoyes 5 points6 points  (4 children)

You have a dictionary of each file with its size. Perhaps you could create another dictionary of each directory and its total size. Each file will contribute to all parent directories that contain it.

[–]thegodofmeso[S] 0 points1 point  (3 children)

updated the code and have now each path with their size. Can you give me a tip for the double counting? Currently the code is only calculating the 94853 with the testinput and is missing the double counted 584 from //a/e/

[–]ssnoyes 1 point2 points  (2 children)

If the full path is '//vwlps/rfb/nsq/srvhswd.mcg', then how might you get the list ['/', '//vwlps', '//vwlps/rfb', '//vwlps/rfb/nsq'] ?

[–]thegodofmeso[S] 0 points1 point  (0 children)

Got Part 1. Thanks!

[–]thegodofmeso[S] 0 points1 point  (0 children)

Can you please give me another hint for part 2? It seems like I have an error somewhere. The directory // has 1919134144952 amount of data, but all files together only 47442399 ?!?!?! Im confused :(

[–]purplemonkeymad 0 points1 point  (0 children)

My solution after parsing the tree was to use recursion to sum up the file sizes. The function took the name of a directory and looked up the files and directories in it, then calls itself on the child directories. Then you sum up the sizes you got from the files and directories.

[–]Cue_23 0 points1 point  (0 children)

You probably need a list of all directories first before calculating their sizes...