[erlang-questions] Maze alternate example for Rosetta Code
Richard A. O'Keefe
ok@REDACTED
Fri Aug 26 07:03:41 CEST 2016
How large should Erlang code for the Rosetta "maze generation"
task be? I don't know, but here's a data point. I did it in
my Smalltalk.
- roughly 90 lines
- 12 lines of comments
- 25 lines are devoted to generating the output,
including terminal ESC sequences.
- I used the algorithm described in the task page.
- I wrote shamelessly compact code instead of well
documented stuff. Maintainability shmaintainability.
- I proudly avoided creating any objects other than one
mutable 2D array of bytes.
- It would have been better to copy the F# code. Sigh.
Here's another data point: it's going to be hard to beat
Haskell (67 lines). The J answer manages it because J is
particularly expressive (if you can call it that...) with
arrays, like its ancestor APL. Erlang is not.
If you can write *maintainable* Erlang code for this problem
in 120 lines, you deserve some sort of prize. (I do not call
the Haskell answer particularly readable.)
You could, of course, cheat a bit by copying the F# version
and using the process dictionary to hold the maze.
E.g.,
let removeWallBetween (x1,y1) (x2,y2) =
if x1 <> x2 then
horizWalls.[min x1 x2, y1] <- false
else
vertWalsl.[x1, min y1 y2] <- false
=>
remove_wall_between(X, Y1, X, Y2) ->
put({v,X,min(Y1,Y2)}, false);
remove_wall_between(X1, Y, X2, Y) ->
put({h,min(X1,X2),Y}, false).
Not a thing I'd normally recommend, but if this is in its
own process, you might get away with it.
More information about the erlang-questions
mailing list