/ https://introcs.cs.princeton.edu/java/assignments/percolation.html / john earnest: / hash marks represent impermeable walls. / a fluid flows from the top edge and can only spread / directly down or horizontally in empty space. / does any fluid make it to the bottom of the grid? b: ("## #### ##" "# # ##### #" " ##### ########" " ## # # ##" "## ### # # ##" "###### ##### # ##" "## # ##" "## ########### ##") f: {(x|y;-1)y=-1} s: {1=|f\|f\(x&1=y)-0=y} `0:" #."2 _sv/:+(s\;0=)@\:" "=b / display flow |/s/" "=b / does the flow exit? / michal wallace: leaky:{[b] / b is a char picture of spaces (which conduct downward and left/right) / and other characters (which block the flow) / returns boolean indicating whether fluid can leak out the bottom. g: ,/ { _[;x] 0,&0,~=':x}' b=" " / group alternating strings of 0s and 1s n: #[^b;]@ ,/g * +\*:' g / 2d map with numbered horizontal groups e: + {x@ &~ 0 _in/: x}@ |:' ? ,/,'': n / edges of digraph of flow between groups pos: {x@&x>0} / positive values only flow: {(e[1],0) @ e[0]?/: x} / flow 1 step starting with groups in x a: pos[?n 0] / starting nodes z: pos[?,/ flow\ a] / list of all reached nodes r: |/ pos[?n[-1+#n]] _lin z / final answer: any groups from the last row in z? :r} / david sanchez: / A slightly different take. / I modified the question slightly for my entertainment: simply display water versus air. I:{ (!#x)=\:!#x} / Identity matrix R:{ |/(-1,0,1)!\:I@*x} / Elementary column transforms L:{ |/(-1,0)!\:I x} / Elementary row transforms T:{y&x+L[x]_dot\:x _dot\:R x} / left,right multiply, apply bounds / Display, with water as "~", air as " ", walls as "#" `0:"# ~"@(" "=b)+A:{T[x;" "=b]}/+(#*b)#,1,1_&#b \ ~~~~~~~~~~~~~~~~~ ##~~~~~~~~####~## #~~~#~~#####~~~~# ~~~##### ######## ~~~## # # ## ##~~~~~### # # ## ######~##### # ## ##~~~~~~~~~~~# ## ##~########### ##