mirror of
https://github.com/Smaug123/advent-of-code-2021
synced 2025-10-05 03:58:39 +00:00
8 lines
324 B
Mathematica
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},#]&;
|