# Advent of code, last puzzle

And this is the solution for the last day of advent of code 2021

``````reuse [L42.is/AdamsTowel]

Cell = Collection.Enum:{
Right={},Down={},Empty={}
}
Map = (
var I col = 0I
var I row = 0I
for s in input.split(S.nl()) (row+=1I)
for s in input.split(S.nl())().split() (col+=1I)
Collection.matrix(Cell.List,row=row,col=col)
)//row=137, col=139

Right = {class method Map.Coord (Map.Coord that) =
that.with(col=(\col+1I).mod(139I))
}
Down = {class method Map.Coord (Map.Coord that)=
that.with(row=(\row+1I).mod(137I))
}

StepRight = {class method Map (Map map) =(
res = Map(\()(for v in map \add(v)))
for c in map.coords(), v in map if v==Cell.Right() (
cr = Right(c)
go = map.val(cr)==Cell.Empty()
if go (
res.set(cr val=v)
res.set(c val=Cell.Empty())
)
)
res
)}
StepDown = {class method Map (Map map) =(
res = Map(\()(for v in map \add(v)))
for c in map.coords(), v in map if v==Cell.Down() (
cd = Down(c)
go = map.val(cd)==Cell.Empty()
if go (
res.set(cd val=v)
res.set(c val=Cell.Empty())
)
)
res
)}

Main=(
var imm map = Map(\()(
for s in input.split(S.nl()) for c in s.split()(
)))
res = 0I.acc()(while Bool.true() (
new = StepDown(map=StepRight(map=map))
if new==map ( Break() )
map:=new
v=\val
))
Debug(res)
``````

Overall, this adventure guided me to try many different kinds of algorithms in 42, and by doing so I discover a bunch of bugs and missing features in AdamsTowel.

Still, this programming style is very far from the ultimate goal of 42: Enforcing modular security.
This is where 42 shines, but this mostly emerges when the program is large enough that can not be reasonably done by a single programmer and where long term maintenance is kept into account.

I will be back to Dev.to after the new year break to talk more about the details of 42 and on how it enforces modular security.

Marco! 