Xah Talk Show 2024-12-03 Ep599, Wolfram Language, Advent of Code 2024, Day 3
By Xah Lee. Date: .
xah talk show 2024-12-03 wolf girl
part 1
xinput = "xmul(2,4)%&mul[3,7]!@^do_not_mul(5,5)+mul(32,64]then(mul(11,8)mul(8,5))";
xinput = Import @ "http://xahlee.info/comp/advent/advent_of_code_2024_3_input.txt";
xinput = StringCases[ xinput, RegularExpression[ "mul\\(\\d+,\\d+\\)" ] ];
xinput = ToExpression @ StringCases[ xinput, RegularExpression[ "\\d+" ] ];
Total @ Map[ Function[{x}, Apply[ Times, x ]] , xinput]
part 2
xinput = "xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))" ;
xinput = Import @ "http://xahlee.info/comp/advent/advent_of_code_2024_3_input.txt";
xinput = StringReplace[ xinput , RegularExpression[ "(?s)don't\\(\\).*?do\\(\\)" ] -> "" ];
xinput = StringReplace[ xinput , RegularExpression[ "(?s)don't\\(\\).+$" ] -> "" ];
xinput = StringCases[ xinput, RegularExpression[ "mul\\(\\d+,\\d+\\)" ] ];
xinput = ToExpression @ StringCases[ xinput, RegularExpression[ "\\d+" ] ];
Total @ Map[ Function[{x}, Apply[ Times, x ]] , xinput]