Files
advent-of-code-2023/mathematica/day_21.m
patrick 7646fb71c3
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/all-checks-complete Pipeline was successful
Day 19 (#19)
Can't be bothered to get it faster

Co-authored-by: Smaug123 <patrick+github@patrickstevens.co.uk>
Reviewed-on: #19
2023-12-23 19:58:35 +00:00

31 lines
778 B
Mathematica

(* ::Package:: *)
(* ::Input:: *)
(*s="...........*)
(*.....###.#.*)
(*.###.##..#.*)
(*..#.#...#..*)
(*....#.#....*)
(*.##..S####.*)
(*.##..#...#.*)
(*.......##..*)
(*.##.#.####.*)
(*.##..##.##.*)
(*...........";*)
(* ::Input:: *)
(*reachable[grid_,{row_Integer,col_Integer}]:=reachable[grid,{row,col}]=Select[{{row+1,col},{row-1,col},{row,col+1},{row,col-1}},*)
(*1<=#[[1]]<=Length[grid]&&1<=#[[2]]<=Length[First@grid]&&grid[[#[[1]],#[[2]]]]!="#"&*)
(*]*)
(* ::Input:: *)
(*f[grid_,pos_,0]:={pos}*)
(*f[grid_,pos_,timestepsRemaining_Integer]:=*)
(*f[grid,pos,timestepsRemaining]=DeleteDuplicates@Flatten[f[grid,#,timestepsRemaining-1]&/@reachable[grid,pos],1]*)
(* ::Input:: *)
(*With[{grid=Characters/@StringSplit[s,"\n"]},f[grid,FirstPosition[grid,"S"],64]//Length]*)