sln_2022_07
Copyright(c) Eric Mertens 2022
LicenseISC
Maintaineremertens@gmail.com
Safe HaskellNone
LanguageHaskell2010

Main

Description

https://adventofcode.com/2022/day/7

The immediate size of a directory is the list of the files contained in it directly, while the total size includes the files that are contained within subdirectories.

>>> :{
:main +
    "$ cd /\n\
    \$ ls\n\
    \dir a\n\
    \14848514 b.txt\n\
    \8504156 c.dat\n\
    \dir d\n\
    \$ cd a\n\
    \$ ls\n\
    \dir e\n\
    \29116 f\n\
    \2557 g\n\
    \62596 h.lst\n\
    \$ cd e\n\
    \$ ls\n\
    \584 i\n\
    \$ cd ..\n\
    \$ cd ..\n\
    \$ cd d\n\
    \$ ls\n\
    \4060174 j\n\
    \8033020 d.log\n\
    \5626152 d.ext\n\
    \7214296 k\n"
:}
95437
24933642
Synopsis

Documentation

type Path = [String] Source #

File paths are represented as a list of directory components in reverse order to make it quicker to manipulate.

type Input = [Either String [Either (Int, String) String]] Source #

The input is a list of directory change commands and directory listings.

main :: IO () Source #

>>> :main
1477771
3579501

lsToTotalSizes :: [(Path, Int)] -> [Int] Source #

Generate all the total sizes of directories given the list of immediate sizes of directories.

summarizeLs Source #

Arguments

:: Path

current working directory

-> Input 
-> [(Path, Int)]

list of directories and their immediate sizes

Given a list of cd commands and directory lists, generate a list of directories and total size of immediate files.