Xah Talk Show 2022-12-23 Advent of Code Day 7 B, in WolframLang, Live Coding


is it possible to determine a given full is a dir or file, from out xpaths. the answer seems no. because:

(* problem: turn x1 into a nested Association *)

x1 = {
 {"/"},
 {"/", "cprq.fmm"},
 {"/", "lthcng.gnf"},
 {"/", "nblfzrb.mrr"},
 {"/", "sfrbjmmh.jnj"},
 {"/", "vmpgqbcd"},
 {"/", "btsgrbd"},
 {"/", "btsgrbd", "qwnml.bqn"},
 {"/", "btsgrbd", "sdwnsgwv.mjm"},
 {"/", "btsgrbd", "vzgwwjq.zbp"},
 {"/", "btsgrbd", "zvspnvfr.zbc"},
 {"/", "btsgrbd", "cmfdm"}
};

dirTree = Association[  ];

Map[
 f ,
 {
  {"/"},
  {"/", "cprq.fmm"}
 }
]

(* first, check if the fullpath is a file or dir, by checking sizeLookupTable *)

curPath
isFileQ = KeyExistsQ[ sizeLookupTable, curPath ]
fileSize = Lookup[ sizeLookupTable,  curPath]

dirTree["/"] = If[isFileQ, fileSize , Association[ ] ]
dirTree["/"]["cprq.fmm"] = If[isFileQ, fileSize , Association[ ] ]
dirTree["/"]["b"]["c"] = If[isFileQ, fileSize , Association[ ] ]

we want to turn this
{"a", "b", "c"}

into this
dirTree["a"]["b"]["c"]

how to do it

ssss---------------------------------------------------

{"a", "b", "c"} //. f_[{a_, rest__}] -> f[a]

f[{1,2,3,4,5}]  //. f_[{a_, rest__}] -> f[a][{rest}]

into this
dirTree["a"]["b"]["c"]

(((dirTree["a"])
 ["b"])
  ["c"])

tr @@

Next[ f,  ]

Fold[ f[#1][#2] &, {"a", "b", "c"} ]

Fold[ f[#1] &, {"a", "b", "c"} ]

a, b
f[a][b]

f[a][b], c
f[a][b][c]

f
f[a]
f[a][b]

Nest[  ]

Lookup[Lookup[Lookup[assoc, "a"], "b"], "c"]

dirTree["a"]["b"]["c"] = x
Lookup[Lookup[assoc, "a"], "b"]["c"] = x

assocVar[key]=val
AssociateTo[ assocVar, key -> val ]

FullForm[Hold [ assocVar[key]=val ] ]

[dirname2][dirname3] = val

dirTree[dirname1][dirname2][dirname3] = val
f[{1, 2, 3, 4, 5}] //. f_[{a_, rest___}] -> f[a][{rest}]

2022 Advent of Code