commit 506eb0488e149527292b08544d92b074e75ba2db
parent 772f53dd72502bb5a0aea7a3c9145dc7d27b6c0d
Author: bsandro <email@bsandro.tech>
Date: Wed, 7 Dec 2022 07:53:30 +0000
Day 07 part 1 + bonus useless solution for the misunderstood part
Diffstat:
A | day07/input.txt | | | 1047 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | day07/main.go | | | 143 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | day07/sample.txt | | | 23 | +++++++++++++++++++++++ |
3 files changed, 1213 insertions(+), 0 deletions(-)
diff --git a/day07/input.txt b/day07/input.txt
@@ -0,0 +1,1047 @@
+$ cd /
+$ ls
+dir dfmhjhd
+307728 ghpqs
+dir hztjntff
+dir rvstq
+dir sjt
+120579 whhj.pqt
+dir wrmm
+$ cd dfmhjhd
+$ ls
+301486 ngtqtf
+13488 wfgqtw.sqr
+$ cd ..
+$ cd hztjntff
+$ ls
+dir cwsf
+288227 ftq.cjn
+176977 hwtj
+234858 nzdgz.mpw
+157857 rhs.mbd
+dir sthqhrc
+$ cd cwsf
+$ ls
+dir msr
+272534 mvfclz.srm
+226182 nldtb
+252294 qnwzs
+$ cd msr
+$ ls
+272198 hwtj
+$ cd ..
+$ cd ..
+$ cd sthqhrc
+$ ls
+45847 vzntwhzl.htf
+$ cd ..
+$ cd ..
+$ cd rvstq
+$ ls
+9707 bqg
+296975 frcqrdm
+232225 hztjntff
+29794 ldmtcrq.dcs
+dir nzdgz
+dir vtlj
+dir wmjbt
+dir wrmm
+28366 wrmm.cjh
+dir wrsmnpwf
+$ cd nzdgz
+$ ls
+dir fplqm
+dir hzpqfj
+dir hztjntff
+dir jcszc
+dir nzwzq
+dir prbptvql
+117527 sdnvpt
+dir tnpshhml
+dir tsjsfg
+$ cd fplqm
+$ ls
+dir cwsf
+dir cwzstq
+216299 mdcnwnng
+109253 nzdgz
+$ cd cwsf
+$ ls
+dir fld
+$ cd fld
+$ ls
+dir jdpz
+dir trjltfq
+$ cd jdpz
+$ ls
+299969 fvgpbf.lps
+$ cd ..
+$ cd trjltfq
+$ ls
+30081 tdzjl.jrw
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd cwzstq
+$ ls
+305925 gjfbqpr.jjv
+$ cd ..
+$ cd ..
+$ cd hzpqfj
+$ ls
+119289 hwtj
+108285 lsb
+246049 svttl.bml
+dir sztz
+75119 zjnll.zjl
+200316 zwj
+$ cd sztz
+$ ls
+dir mjmbld
+dir nzdgz
+dir wrmm
+$ cd mjmbld
+$ ls
+101870 hwtj
+$ cd ..
+$ cd nzdgz
+$ ls
+86208 hwtj
+$ cd ..
+$ cd wrmm
+$ ls
+242305 wrmm.dlb
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd hztjntff
+$ ls
+124971 flmb
+dir hztjntff
+152045 lsb
+109123 nlwltp.mbg
+247323 qvqqw
+$ cd hztjntff
+$ ls
+dir hztjntff
+dir tfdnvnn
+$ cd hztjntff
+$ ls
+72064 lsjgcqvl.jtq
+138507 rqbjcrpv
+$ cd ..
+$ cd tfdnvnn
+$ ls
+108268 vwtj
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd jcszc
+$ ls
+94496 frcqrdm
+247067 vmhfdm.lrc
+$ cd ..
+$ cd nzwzq
+$ ls
+6875 dbqbstqp
+$ cd ..
+$ cd prbptvql
+$ ls
+177069 zjnll.zjl
+$ cd ..
+$ cd tnpshhml
+$ ls
+227272 jjdplm.wjb
+$ cd ..
+$ cd tsjsfg
+$ ls
+dir fjhjl
+215211 hwtj
+4695 lsb
+250283 lvssbtc.fwq
+$ cd fjhjl
+$ ls
+54983 swqt.jsm
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd vtlj
+$ ls
+103236 cmwpcdrj.zlc
+1640 fllj.vfg
+155765 frcqrdm
+250655 hwtj
+dir hztjntff
+82919 hztjntff.gzd
+dir tzwfnn
+dir wrmm
+$ cd hztjntff
+$ ls
+58108 lsb
+$ cd ..
+$ cd tzwfnn
+$ ls
+dir grznq
+$ cd grznq
+$ ls
+282278 pwmsds.vzr
+$ cd ..
+$ cd ..
+$ cd wrmm
+$ ls
+39404 frcqrdm
+73284 pnj.rvq
+$ cd ..
+$ cd ..
+$ cd wmjbt
+$ ls
+dir bpqjsnr
+dir bqg
+dir cwsf
+31392 ths.lpc
+dir vlhr
+dir wrmm
+dir zgljrz
+dir zgt
+$ cd bpqjsnr
+$ ls
+dir bqg
+132830 fjp
+$ cd bqg
+$ ls
+dir hztjntff
+dir jvzn
+219730 srrqlqq.fss
+285971 tcqwqsgz.vrl
+195936 vbmczm.pbn
+191537 wrmm.bgq
+$ cd hztjntff
+$ ls
+dir bqg
+dir hljm
+$ cd bqg
+$ ls
+188558 bqg.grm
+$ cd ..
+$ cd hljm
+$ ls
+dir clblt
+$ cd clblt
+$ ls
+dir qdjj
+47245 vzrpqlgs.zng
+181205 wpcp.rcw
+$ cd qdjj
+$ ls
+152548 rcjzld.zfv
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd jvzn
+$ ls
+265757 clvj.bmr
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd bqg
+$ ls
+76100 cwsf
+147481 dcmqw
+137704 wcflzwbt.vvz
+212362 zbqlrscd.nrc
+212170 zqlbt.cdf
+$ cd ..
+$ cd cwsf
+$ ls
+242327 bqg.mwf
+$ cd ..
+$ cd vlhr
+$ ls
+156011 nzdgz.gct
+$ cd ..
+$ cd wrmm
+$ ls
+dir cwsf
+dir ljpn
+dir vzwtzl
+dir wjsf
+$ cd cwsf
+$ ls
+dir bstnjc
+169487 cwsf
+298251 hcsrh.nrb
+$ cd bstnjc
+$ ls
+11588 lsb
+$ cd ..
+$ cd ..
+$ cd ljpn
+$ ls
+dir cgghhhlf
+204262 gzh.gww
+171620 lqtbm.zbg
+dir qfwrrp
+dir smpltb
+$ cd cgghhhlf
+$ ls
+14765 nvbvs.bnv
+$ cd ..
+$ cd qfwrrp
+$ ls
+256670 hwtj
+$ cd ..
+$ cd smpltb
+$ ls
+dir bgvfj
+$ cd bgvfj
+$ ls
+65336 fprgmh.psg
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd vzwtzl
+$ ls
+53337 fggqjqvs
+$ cd ..
+$ cd wjsf
+$ ls
+308476 nzsm.dfd
+99153 swhv.ghz
+241163 thpzp
+$ cd ..
+$ cd ..
+$ cd zgljrz
+$ ls
+134867 fmndz.mhf
+$ cd ..
+$ cd zgt
+$ ls
+132031 hwtj
+218404 zjnll.zjl
+$ cd ..
+$ cd ..
+$ cd wrmm
+$ ls
+dir clt
+257641 cwc.wwg
+dir mjpw
+dir nlwpspl
+dir qwvjnwsf
+282920 zjnll.zjl
+$ cd clt
+$ ls
+62449 jlwr.bds
+$ cd ..
+$ cd mjpw
+$ ls
+147523 wrmm
+$ cd ..
+$ cd nlwpspl
+$ ls
+dir bmmmhnbc
+244465 cqbq.qmw
+199707 hwtj
+dir jjjdlj
+45952 lsb
+274021 mhprtvb.jnf
+dir vctf
+$ cd bmmmhnbc
+$ ls
+dir bldfbzr
+dir cwsf
+dir dmj
+202405 frcqrdm
+77128 hnrc.dqv
+dir hztjntff
+242794 lqslmd
+198590 lsb
+87647 ngh.ljt
+dir wmgwfvq
+$ cd bldfbzr
+$ ls
+dir bqg
+224279 frcqrdm
+304382 hcfv.jpr
+dir nzdgz
+24190 psvfl.hlg
+dir qjzh
+95318 qpb.nzq
+$ cd bqg
+$ ls
+187091 hcfv.jpr
+$ cd ..
+$ cd nzdgz
+$ ls
+dir nhmts
+dir tqhthh
+$ cd nhmts
+$ ls
+105545 cwhlrfv.rlz
+$ cd ..
+$ cd tqhthh
+$ ls
+81739 sfmcss.rps
+14262 wmlmfzg.bqt
+$ cd ..
+$ cd ..
+$ cd qjzh
+$ ls
+162159 cmn.rtc
+$ cd ..
+$ cd ..
+$ cd cwsf
+$ ls
+dir bqg
+dir frc
+dir jbgrgz
+78485 lsb
+102492 nzdgz.psw
+79482 phhvggtg.mlj
+156154 qrcwwtz.dzn
+$ cd bqg
+$ ls
+269163 hztjntff
+$ cd ..
+$ cd frc
+$ ls
+dir wrmm
+$ cd wrmm
+$ ls
+dir ctrbwhpr
+dir shmjt
+$ cd ctrbwhpr
+$ ls
+94535 wrmm.fjl
+$ cd ..
+$ cd shmjt
+$ ls
+6523 svmsvg.vvc
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd jbgrgz
+$ ls
+152890 bnlprltj
+60156 dttwfgs
+dir frvlnww
+dir qszdtg
+$ cd frvlnww
+$ ls
+297025 cjbnqm
+126118 mpnnb.wqb
+$ cd ..
+$ cd qszdtg
+$ ls
+286900 fptpmp.fqb
+210489 qbpwdhqt.wtw
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd dmj
+$ ls
+dir bqg
+60042 gncqrjnr.nrp
+dir rhd
+106478 smgjczbq.mbh
+$ cd bqg
+$ ls
+223960 wrmm
+2863 wrmm.jvg
+152468 zjnll.zjl
+$ cd ..
+$ cd rhd
+$ ls
+104913 frcqrdm
+248815 lsb
+$ cd ..
+$ cd ..
+$ cd hztjntff
+$ ls
+172094 bqg.nqg
+14817 frcqrdm
+207015 hcfv.jpr
+34358 jjdrw.stq
+dir mczrpf
+dir mzd
+$ cd mczrpf
+$ ls
+19896 frcqrdm
+273870 gvrb.lff
+281909 tht.bhc
+$ cd ..
+$ cd mzd
+$ ls
+26174 sgbhjft
+$ cd ..
+$ cd ..
+$ cd wmgwfvq
+$ ls
+130936 gzm.wzc
+dir hztjntff
+61943 jdp
+dir rvwhms
+$ cd hztjntff
+$ ls
+dir bqg
+273566 lsb
+dir vhdqhfqv
+305672 whrsqpc.nwz
+dir wrmm
+$ cd bqg
+$ ls
+14092 hcfv.jpr
+$ cd ..
+$ cd vhdqhfqv
+$ ls
+193016 qgr
+157253 vbrc
+$ cd ..
+$ cd wrmm
+$ ls
+62936 bqg.mpb
+264687 dswswdzq
+dir grlgcgrl
+127974 lsb
+dir nmm
+75041 tfdbrqfw.lbd
+dir tlrztbh
+$ cd grlgcgrl
+$ ls
+164027 nzdgz.ptd
+$ cd ..
+$ cd nmm
+$ ls
+101722 bqg
+$ cd ..
+$ cd tlrztbh
+$ ls
+16955 cwsf
+196934 lvdsbss.lpr
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd rvwhms
+$ ls
+314729 bcgphtl.bsc
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd jjjdlj
+$ ls
+dir dnpf
+dir mwlvndml
+$ cd dnpf
+$ ls
+129865 pgczcz
+128274 zjtv.jml
+$ cd ..
+$ cd mwlvndml
+$ ls
+dir nzdgz
+255297 vdsmgqdg.sbj
+$ cd nzdgz
+$ ls
+111500 hcfv.jpr
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd vctf
+$ ls
+dir bqg
+4316 cwsf.vnq
+dir gcgqr
+139151 hztjntff
+270316 hztjntff.wng
+285602 mzzgnztv
+299195 nzdgz
+dir vbqjbq
+$ cd bqg
+$ ls
+219667 lsb
+$ cd ..
+$ cd gcgqr
+$ ls
+71948 wbhbbr.rbg
+$ cd ..
+$ cd vbqjbq
+$ ls
+dir sltqnp
+$ cd sltqnp
+$ ls
+5768 nvdmjq
+20296 qtb.tcs
+303095 zndbj.pgm
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd qwvjnwsf
+$ ls
+118347 bqg.csn
+dir hqlv
+107689 hwtj
+66314 nzdgz.dmw
+94334 sjc
+$ cd hqlv
+$ ls
+250002 qcdpnc
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd wrsmnpwf
+$ ls
+205662 lsb
+$ cd ..
+$ cd ..
+$ cd sjt
+$ ls
+dir cwsf
+dir nzdgz
+dir qsd
+dir rdzsr
+66525 tqqvtzz.gzq
+260979 wnbvvz
+dir zgrf
+dir zmtmr
+$ cd cwsf
+$ ls
+dir dtpf
+dir fjtsb
+14887 frcqrdm
+dir gdnnndj
+281647 hztjntff.clc
+152053 jbls.grs
+dir mfbp
+dir nzdgz
+dir zclzqz
+$ cd dtpf
+$ ls
+278443 frcqrdm
+138750 fslt.mmj
+$ cd ..
+$ cd fjtsb
+$ ls
+142873 frcqrdm
+230248 lbhs
+116760 zjnll.zjl
+$ cd ..
+$ cd gdnnndj
+$ ls
+dir sljmpls
+dir zhn
+$ cd sljmpls
+$ ls
+dir cnzhjqbm
+dir cttgctwb
+307652 hwtj
+dir rwwmcmt
+107266 zjnll.zjl
+$ cd cnzhjqbm
+$ ls
+196818 frcqrdm
+$ cd ..
+$ cd cttgctwb
+$ ls
+dir bqg
+$ cd bqg
+$ ls
+270727 hcfv.jpr
+$ cd ..
+$ cd ..
+$ cd rwwmcmt
+$ ls
+77395 hcfv.jpr
+286056 nssl
+$ cd ..
+$ cd ..
+$ cd zhn
+$ ls
+114122 dbcpsqn
+dir mpfvnslm
+dir zlqns
+$ cd mpfvnslm
+$ ls
+dir qvtr
+$ cd qvtr
+$ ls
+83650 bqg.qqh
+$ cd ..
+$ cd ..
+$ cd zlqns
+$ ls
+36937 bgzjvvc.szm
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd mfbp
+$ ls
+199935 qwsb.vcd
+$ cd ..
+$ cd nzdgz
+$ ls
+121541 jlncd.vgb
+$ cd ..
+$ cd zclzqz
+$ ls
+274497 zjnll.zjl
+$ cd ..
+$ cd ..
+$ cd nzdgz
+$ ls
+dir qscww
+dir tdthnm
+$ cd qscww
+$ ls
+224250 frcqrdm
+196936 hcfv.jpr
+$ cd ..
+$ cd tdthnm
+$ ls
+dir hmq
+dir tcdm
+$ cd hmq
+$ ls
+172261 nhpfqc.tgj
+$ cd ..
+$ cd tcdm
+$ ls
+188168 lsb
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd qsd
+$ ls
+dir bqg
+dir pbfc
+$ cd bqg
+$ ls
+268716 bdpdlp.sht
+253174 jjwlmnd.czs
+dir mnrrmcc
+261171 nzdgz.rdw
+285026 sbfcj.wnh
+$ cd mnrrmcc
+$ ls
+33961 lsb
+$ cd ..
+$ cd ..
+$ cd pbfc
+$ ls
+dir hwbdld
+$ cd hwbdld
+$ ls
+178868 hztjntff.gql
+108145 stqzdh.zdn
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd rdzsr
+$ ls
+45590 zjnll.zjl
+$ cd ..
+$ cd zgrf
+$ ls
+dir bqg
+dir cbc
+dir cclw
+dir cwsf
+dir fph
+258332 hcfv.jpr
+dir hvvvv
+dir hztjntff
+238272 nzwzmlqt.nvh
+dir tqqqv
+$ cd bqg
+$ ls
+143934 pgnvtcv.csm
+44611 zjnll.zjl
+$ cd ..
+$ cd cbc
+$ ls
+119981 bznnrjtt
+dir dsmmcjtg
+259268 hsgwqqz.lzc
+dir wrmm
+$ cd dsmmcjtg
+$ ls
+150156 lmtdgnll.bln
+192882 nzdgz.pzz
+$ cd ..
+$ cd wrmm
+$ ls
+207747 psmgbf
+$ cd ..
+$ cd ..
+$ cd cclw
+$ ls
+245438 nzdgz.bdv
+$ cd ..
+$ cd cwsf
+$ ls
+314457 hwtj
+293169 zrjbrhs
+$ cd ..
+$ cd fph
+$ ls
+dir hztjntff
+dir mbgv
+dir nbzvd
+dir tzjtsqlj
+313411 vwmsbfd.btp
+$ cd hztjntff
+$ ls
+118509 nwjgfdt.llb
+262025 tnvsm.wsj
+$ cd ..
+$ cd mbgv
+$ ls
+890 zjnll.zjl
+$ cd ..
+$ cd nbzvd
+$ ls
+95080 zvjf.zjq
+$ cd ..
+$ cd tzjtsqlj
+$ ls
+224995 frcqrdm
+$ cd ..
+$ cd ..
+$ cd hvvvv
+$ ls
+dir zrpvfzz
+$ cd zrpvfzz
+$ ls
+dir nlcds
+280153 slcjdqw.wms
+$ cd nlcds
+$ ls
+80960 cwsf.qtp
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd hztjntff
+$ ls
+133260 cbl
+dir fwmvqhj
+179412 hcfv.jpr
+dir hnwn
+260329 hrwqwc.cbg
+60953 lsb
+255753 tcl.zrz
+dir wrmm
+$ cd fwmvqhj
+$ ls
+dir cwsf
+209425 fcf.ncz
+139449 gllwzh.dzc
+dir hjgpzwf
+dir njtbnt
+$ cd cwsf
+$ ls
+309282 nzdgz.bsg
+242967 wqzjrpp.pqs
+$ cd ..
+$ cd hjgpzwf
+$ ls
+157649 jcw
+$ cd ..
+$ cd njtbnt
+$ ls
+dir lvhqrjzn
+dir mgtjfhvf
+31491 nzdgz.sgc
+$ cd lvhqrjzn
+$ ls
+11465 rrfpsjm.fsd
+$ cd ..
+$ cd mgtjfhvf
+$ ls
+dir wmnwrn
+$ cd wmnwrn
+$ ls
+44518 hwtj
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd hnwn
+$ ls
+265411 bftcf.hdj
+dir bqg
+$ cd bqg
+$ ls
+96072 zdh.gpp
+$ cd ..
+$ cd ..
+$ cd wrmm
+$ ls
+206383 bngf
+dir jgdjp
+15886 lsb
+263238 nzdgz.tgj
+183663 ppfr.mzj
+dir qzlt
+dir tmzgrts
+256721 wrmm.dwl
+$ cd jgdjp
+$ ls
+165322 vdpnqwq
+$ cd ..
+$ cd qzlt
+$ ls
+44763 cwsf.qqz
+dir jcgt
+dir vmsnrhb
+dir wrmm
+$ cd jcgt
+$ ls
+199928 hnl.chj
+$ cd ..
+$ cd vmsnrhb
+$ ls
+dir csvhwb
+dir mnwwdf
+dir pzwvh
+$ cd csvhwb
+$ ls
+82347 bqg.qlb
+76688 dtl.nws
+dir hztjntff
+151835 nwwdct.qlc
+dir prqf
+$ cd hztjntff
+$ ls
+146900 ncgnjp.zqb
+123665 zjnll.zjl
+$ cd ..
+$ cd prqf
+$ ls
+143916 hcfv.jpr
+60506 hztjntff
+295807 jqwmltv.dmb
+282209 qmzpbn.ntn
+$ cd ..
+$ cd ..
+$ cd mnwwdf
+$ ls
+161210 nzdgz.mjn
+$ cd ..
+$ cd pzwvh
+$ ls
+28510 cwgtzgjd.ghf
+dir jbhjjjs
+dir lql
+25334 lsb
+dir wcrsqtz
+$ cd jbhjjjs
+$ ls
+48808 mhshl
+$ cd ..
+$ cd lql
+$ ls
+dir tzcjpj
+$ cd tzcjpj
+$ ls
+101686 frcqrdm
+$ cd ..
+$ cd ..
+$ cd wcrsqtz
+$ ls
+71563 bqg.zmh
+270956 qgw
+dir rngvpc
+$ cd rngvpc
+$ ls
+220454 smfzwq.qgr
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd wrmm
+$ ls
+dir mvrqsc
+$ cd mvrqsc
+$ ls
+249653 frcqrdm
+257853 nzdgz.qbf
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd tmzgrts
+$ ls
+229931 djssmcdz.nzj
+dir jrbjdghc
+131107 rjtsdjqt.mht
+$ cd jrbjdghc
+$ ls
+85458 frcqrdm
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd tqqqv
+$ ls
+162333 bqg.mdz
+5054 hcfv.jpr
+172441 nzdgz
+dir qmwpfp
+18969 wrmm
+$ cd qmwpfp
+$ ls
+dir cwsf
+dir lndh
+dir nvjsvvln
+$ cd cwsf
+$ ls
+18202 ngmsjfj.bvs
+124907 snhqbcqc
+149910 snj.ltq
+253218 vppzwd.ztb
+dir wlpcb
+$ cd wlpcb
+$ ls
+280918 vllc.ztt
+$ cd ..
+$ cd ..
+$ cd lndh
+$ ls
+146958 lvsqcvlr.bcq
+286212 vcpgqbl.wbw
+$ cd ..
+$ cd nvjsvvln
+$ ls
+288486 hcfv.jpr
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd zmtmr
+$ ls
+18654 cwsf.qpj
+89300 fprft.wbq
+66999 hwtj
+110810 lmtdjgpv
+dir sms
+dir vdn
+dir vdqmtjw
+$ cd sms
+$ ls
+85804 dtsgp
+197739 hcfv.jpr
+$ cd ..
+$ cd vdn
+$ ls
+159126 tnmhfscw
+168030 wrmm.dvb
+$ cd ..
+$ cd vdqmtjw
+$ ls
+291828 hztjntff
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd wrmm
+$ ls
+212937 frcqrdm
+153487 zjnll.zjl
diff --git a/day07/main.go b/day07/main.go
@@ -0,0 +1,143 @@
+package main
+
+import (
+ "bufio"
+ "fmt"
+ "log"
+ "os"
+ "sort"
+ "strings"
+ "strconv"
+)
+
+type Dir struct {
+ Name string
+ Size int
+ Parent *Dir
+}
+
+type Dirs []*Dir
+func (d Dirs) Len() int { return len(d) }
+func (d Dirs) Swap(i, j int) { d[i], d[j] = d[j], d[i] }
+func (d Dirs) Less(i, j int) bool { return d[i].Size > d[j].Size }
+func (d Dirs) String() string {
+ var s string
+ for _, dir := range d {
+ s += dir.String() + "\n"
+ }
+ return s
+}
+
+func (dir Dir) String() string {
+ return fmt.Sprintf("%s:%d", dir.Name, dir.Size)
+}
+
+func main() {
+ if len(os.Args) > 1 {
+ day07(os.Args[1])
+ } else if len(os.Args) == 1 {
+ fmt.Printf("usage: %s inputfile.txt\n", os.Args[0])
+ } else {
+ fmt.Println("No input data")
+ }
+}
+
+func day07(input_file string) {
+ fmt.Printf("day 07 input filename: %s\n", input_file)
+ input, err := os.Open(input_file)
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer input.Close()
+ var dirs Dirs //[]*Dir
+ var cur *Dir = nil
+ scanner := bufio.NewScanner(input)
+ for scanner.Scan() {
+ in := scanner.Text()
+ if in[0] == '$' {
+ //fmt.Println("command", in)
+ cmd := strings.Split(in, " ")
+ //fmt.Printf("cmd: %v\n", cmd)
+ switch cmd[1] {
+ case "cd":
+ if cmd[2] == ".." {
+ // won't work if we do "cd .." from /
+ cur = cur.Parent
+ } else {
+ dir := &Dir{
+ Name: cmd[2],
+ Size: 0,
+ Parent: cur,
+ }
+ dirs = append(dirs, dir)
+ cur = dir
+ }
+ case "ls":
+ // do nothing
+ }
+ } else {
+ sizeStr, _, has := strings.Cut(in, " ")
+ if !has {
+ log.Fatal("invalid input")
+ }
+ if sizeStr == "dir" {
+ // ignore
+ } else {
+ size, err := strconv.Atoi(sizeStr)
+ if err!=nil {
+ log.Fatal(err)
+ }
+ for d:=cur; d!=nil; {
+ d.Size += size
+ d = d.Parent
+ }
+ }
+ }
+ }
+ if err = scanner.Err(); err != nil {
+ log.Fatal(err)
+ }
+
+ sort.Sort(dirs)
+
+ const sizeLimit = 100000
+ var dirsFiltered Dirs
+ size := 0
+ for _, d := range dirs {
+ if d.Size < 100000 {
+ dirsFiltered = append(dirsFiltered, d)
+ size += d.Size
+ }
+ }
+ //fmt.Println("---Dirs---")
+ //fmt.Println(dirsFiltered)
+ fmt.Printf("size: %d\n", size)
+
+ //fmt.Printf("max: %d\n", getMaxSize(dirsFiltered, 100000))
+}
+
+func getMaxSize(dirs Dirs, size int) int {
+ //fmt.Println("getMaxSize", size)
+ //fmt.Println(dirs)
+ maxSize := 0
+ for i, d := range dirs {
+ remSize := size - d.Size
+ sumSize := d.Size
+ var rem Dirs
+ // filter all remaining folders to be less sized
+ for j, d1 := range dirs {
+ if d1.Size <= remSize && i!=j {
+ rem = append(rem, d1)
+ }
+ }
+ if len(rem) > 0 {
+ //fmt.Printf("going down from %s (rem len %d)\n", d, len(rem))
+ sumSize += getMaxSize(rem, remSize)
+ }
+ if sumSize > maxSize {
+ maxSize = sumSize
+ }
+ }
+ fmt.Println("return maxSize", maxSize)
+ return maxSize
+}
diff --git a/day07/sample.txt b/day07/sample.txt
@@ -0,0 +1,23 @@
+$ cd /
+$ ls
+dir a
+14848514 b.txt
+8504156 c.dat
+dir d
+$ cd a
+$ ls
+dir e
+29116 f
+2557 g
+62596 h.lst
+$ cd e
+$ ls
+584 i
+$ cd ..
+$ cd ..
+$ cd d
+$ ls
+4060174 j
+8033020 d.log
+5626152 d.ext
+7214296 k