Files
advent-of-code-2021/day_5/day_5.m
Patrick Stevens 68a7f890be Day 5 in Rust (#3)
2021-12-05 11:11:26 +00:00

8 lines
324 B
Mathematica

(* ::Package:: *)
nums=Import[StringJoin[NotebookDirectory[], "/input.txt"],"Table"];
part1 = 1##&@@Tr[1##&@@@(#/."up"->-"down")]&;
part2=1##&@@Rest@Fold[Function[{state,elt},Switch[elt[[1]],"forward",state+{0,elt[[2]],state[[1]] elt[[2]]},"down",MapAt[elt[[2]]+#&,state,1],"up",MapAt[#-elt[[2]]&,state,1]]],{0,0,0},#]&;