Xah Talk Show 2024-12-01 Ep597, Wolfram Language, Advent of Code 2024, Day 1
By Xah Lee. Date: .
grok draw me cat warrior 2024-12-01
xinput = "3 4
4 3
2 5
1 3
3 9
3 3";
xinput = Import[ "http://xahlee.info/comp/advent/advent_of_code_2024_1_input.txt" ];
Total @ Abs@ Apply[ Subtract, Map[Sort, Transpose @ Partition[ ToExpression @ StringSplit[ xinput ], 2 ] ]]
part 2
xinput =
"3 4
4 3
2 5
1 3
3 9
3 3";
xinput = Import[ "http://xahlee.info/comp/advent/advent_of_code_2024_1_input.txt" ];
xinput = Transpose @ Partition[ ToExpression @ StringSplit[ xinput ], 2 ];
Total@ With[ { col1 = xinput[[1]], col2 = xinput[[2]] }, Map[ Function[{x}, x * Count[ col2, x ]] , col1 ] ]