Xah Talk Show 2022-12-15 Advent of Code Day 3, in WolframLang, Live Coding

vidthumb uCOED-QfEf8

problem 1

vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw
Clear[ xinput, xLines, xlen, xpouch1, xpouch2, x2, xlist ]

xinput = "vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw";

Clear[ charToNum ]

(* charToNum = Function[ char, If[ UpperCaseQ[ char ], ToCharacterCode[char]-64 + 26, ToCharacterCode[char]-96 ] ] *)

(* xlist = Map[charToNum,  *)
(*   Map[StringCases[Last@#,  *)
(*      RegularExpression[StringJoin["[", First@#, "]"]], 1] &,  *)
(*    Map[StringPartition[#, StringLength[#]/2] &,  *)
(*     StringSplit[xinput]]], {2}] *)

xlist =
Map[ If[ UpperCaseQ[ # ], ToCharacterCode[#]-64 + 26, ToCharacterCode[#]-96 ]&,
(StringCases[Last@#, RegularExpression[StringJoin["[", First@#, "]"]], 1] & )
/@ (StringPartition[#, StringLength[#]/2] &) /@ StringSplit[xinput] , {2}]

Total[xlist]

problem 2

Clear[ xinput, x1, x2, x3, x4, x5 ]

xinput = "vJrwpWtwJgWrhcsFMMfFFhFp
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL
PmmdzqPrVvPwwTWBwg
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn
ttgJtRGJQctTZtZT
CrZsJsPPZsGzwwsLwLmpwMDw";

x1= StringSplit[ xinput ]
x2 = Partition[ x1, 3 ]
x3 = Map[ Characters , x2 , {-1} ]
x4 = Map[ Intersection@@#& ,x3 , {1} ]
x5 = Map[ Function[ char, If[ UpperCaseQ[ char ], ToCharacterCode[char]-64 + 26, ToCharacterCode[char]-96 ] ] , x4 , {2} ]
x6 = Total[ x5 ]
advent of code 2022 day 3 2022-12-15 Btjy8
advent of code 2022 day 3 2022-12-15 Btjy8

2022 Advent of Code