This language was Zimbu (http://www.zimbu.org/). Two things stood out about Zimbu that made me want to use it: a) it was at the bottom of the list, being last in alphabetical order and b) it was written by the author of vim, my favorite command line text editor. So, using Zimbu. It was easy to build, run, yada yada, its a compiled language that compiles to C with pretty C-like syntax, yep, pretty solid in the basics. Neat advantage: it was written by the author of vim: therefore, even though it is crazily uncommon, it has beautiful syntax highlighting / autocorrect / autoindenting in vim. And I kind of like the language in principle, it has some neat little things about it, including bringing us back to the 70s with ALL CAPS reserved words, which, actually, I found to be something of a nice feature, the caps help to make them stand out. However, the one main complaint I had with the language that it is aggressively whitespace sensitive. The language description seems to say this is so that code is easy to read, but this language takes whitespace sensitivity to kind of a pedantic level that enforces an exact style of code. The main issue here is that all operators must be separated by whitespace. So in the below, where I have updated[row - 1][col], it is a syntax error to write updated[row-1][col]. Similarly, there must be a space after the comma in a list. So yeah, just annoying stuff like that...this discussion makes me think that maybe I should at some point try to kind of formally review the languages I use, maybe I will implement something like a grading system, 1 to 5 stars on various categories...we shall see. Anyway, my code is below, runs in about .13s on my machine, and now I can start using languages that don't have easy ways of defining matrices again.
FUNC Main() int list<list<int>> matrix = [[4445, 2697, 5115, 718, 2209, ...]] list<list<int>> updated = NEW(80, NEW(80, 0)) FOR row IN 0 TO 79 updated[row] = NEW(80, 0) } updated[0][0] = matrix[0][0] FOR diag IN 1 TO 159 int h = diag IF h > 79 h = 79 } int l = diag - 79 IF h < 0 h = 0 } FOR col IN l TO h int row = diag - col int lp = matrix[row][col] IF row > 0 lp += updated[row - 1][col] ELSE lp += 1000000 } int rp = matrix[row][col] IF col > 0 rp += updated[row][col - 1] ELSE rp += 1000000 } IF rp < lp updated[row][col] = rp ELSE updated[row][col] = lp } } } DO bool mchanged = FALSE FOR col IN 0 TO 79 DO bool changed = FALSE FOR row IN 0 TO 79 IF row > 0 IF updated[row - 1][col] < updated[row][col] - matrix[row][col] updated[row][col] = matrix[row][col] + updated[row - 1][col] changed = TRUE } } IF row < 79 IF updated[row + 1][col] < updated[row][col] - matrix[row][col] updated[row][col] = matrix[row][col] + updated[row + 1][col] changed = TRUE } } } mchanged = mchanged || changed UNTIL !changed } FOR row IN 0 TO 79 DO bool changed = FALSE FOR col IN 0 TO 79 IF col > 0 IF updated[row][col - 1] < (updated[row][col] - matrix[row][col]) updated[row][col] = matrix[row][col] + updated[row][col - 1] changed = TRUE } } IF col < 79 IF updated[row][col + 1] < updated[row][col] - matrix[row][col] updated[row][col] = matrix[row][col] + updated[row][col + 1] changed = TRUE } } } mchanged = mchanged || changed UNTIL !changed } UNTIL !mchanged IO.write(updated[79][79]) IO.write("\n") RETURN 0 }
No comments:
Post a Comment