Earlier quoted context omitted.
That sounds like 100+ lines in python or similar languages…
A few years back I made a modest attempt at writing a concise yet readable sudoku solver in Python - in about 29 lines: https://github.com/hrzn/sudoku/blob/master/sudoku.py Could have been made shorter at the price of readability.
Arthur Whitney's one liner sudoku solver (2011)
131–140 of 210 posts
Re: Arthur Whitney's one liner sudoku solver (2011)
#132Earlier quoted context omitted.
You could also say that the average bank/company should have learned from previous mistakes doing exactly that for many decades. Select a language that is well tested, understood and supported. Set a limit on cleverness and instead focus on maintainability and simplicity.
If only. In my experience, banks end up building a solution that is maintained by 100 mediocre developers that a reasonably smart developer can't make sense of when it behaves erratically or has extremely poor performance.
Re: Arthur Whitney's one liner sudoku solver (2011)
#133I'll sometimes gauge code complexity by comparing the number of lines of code against the output of tar -cf - . | gzip | base64 | wc -l IE "how much does it compress?" Looking at APL -- I'm reminded of what happens if I accidentally send the gzipped output to my tty... I'm impressed that there's anyone who can follow along (can you find the bug?) to code like p←{(↑⍵)∘{(⍺∨.=⍵)/⍳n×n∘}¨,⍵},(n*÷2){⍵,⍺⊥⌊⍵÷⍺}'⍳n n←⍴⍵ It re…
Legitimately curious how APL programmers think about maintainability and readability. Is code just thoroughly commented or otherwise documented?
Probably the biggest readability concern of overly-golfed expressions really is just being dynamically typed, a problem shared with all dynamically-typed languages. But array languages have the problem worse, as nearly all operations are polymorphic over array vs number inputs, whereas in e.g. JS you can use 'a+b' as a hint that 'a' and 'b' are numbers, & similar.
If you want readable/maintainable code, adding comments and splitting things into many smaller lines is just as acceptable as in other languages.
Re: Arthur Whitney's one liner sudoku solver (2011)
#134Most people are put off by the symbols, that wasn't really the issue I had. So I do love APL and arraylangs, and learning them was really helpful in a lot of other languages. But they never became a daily driver for me not because of the symbols, which were honestly fine if you stick with it long enough, but after about 3-4 years of dabbling on and off I hit a wall with APL I just couldn't get past. Most other langua…
You're not wrong. It's very easy to get that impression when trying to learn the array languages. It's very easy for someone who's used these languages for a long time to look at a problem, and say "why did you use that really elaborate solution, when you can just use ⍸⍣¯1?". No one probably ever told you that ⍸ has an inverse, and how you could use it. Even today, after having worked in these languages for years, I…
Re: Arthur Whitney's one liner sudoku solver (2011)
#135I’ve often wondered about languages like APL/k, are the programmers actually able to think about problems more efficiently?
Re: Arthur Whitney's one liner sudoku solver (2011)
#136I'll sometimes gauge code complexity by comparing the number of lines of code against the output of tar -cf - . | gzip | base64 | wc -l IE "how much does it compress?" Looking at APL -- I'm reminded of what happens if I accidentally send the gzipped output to my tty... I'm impressed that there's anyone who can follow along (can you find the bug?) to code like p←{(↑⍵)∘{(⍺∨.=⍵)/⍳n×n∘}¨,⍵},(n*÷2){⍵,⍺⊥⌊⍵÷⍺}'⍳n n←⍴⍵ It re…
Legitimately curious how APL programmers think about maintainability and readability. Is code just thoroughly commented or otherwise documented?
The compiler's whole state is a bunch of integer vectors, and •Show [a,b,c] prints some equal-length vectors as rows of a table, so I usually use that. The relevant code is usually a few consecutive lines, and the code is composed of very basic operations like boolean logic, reordering arrays with selection, prefix sum, and so on, so they're not hard to read if you're used to them. There are a few tricks, which almost all are repeated patterns (e.g. PN, "partitioned-none" is common enough to be defined as a function). And fortunately, the line prefaced with "Permutation to reverse each expression: more complicated than it looks" has never needed to be debugged.
Basically, when you commit to writing in an array style (you don't have to! It might be impossible!) you're taking an extreme stance in favor of visible and manipulable data. It's more work up front to design the layout of this data and figure out how to process it in the way you want, but easier to see what's happening as a result. People (who don't know APL, mostly) say "write only" but I haven't experienced it.
[0] https://github.com/mlochbaum/BQN/blob/master/src/c.bqn
[1] https://mlochbaum.github.io/BQN/implementation/codfns.html#i...
Re: Arthur Whitney's one liner sudoku solver (2011)
#137Earlier quoted context omitted.
You're not wrong. It's very easy to get that impression when trying to learn the array languages. It's very easy for someone who's used these languages for a long time to look at a problem, and say "why did you use that really elaborate solution, when you can just use ⍸⍣¯1?". No one probably ever told you that ⍸ has an inverse, and how you could use it. Even today, after having worked in these languages for years, I…
Very nice! I like the readability-- not sure if thats just indicative of your style or the language, and the map construct is also nice. I don't remember any off-the-shelf map construct, at least not in Dyalog.
Re: Arthur Whitney's one liner sudoku solver (2011)
#138Lines of code is a poor metric, because languages use lines differently. A much better measure would be the number of nodes in a parse tree, of semantically meaningful non-terminals like "a constant" or "a function call". An even better measure would also involve the depth and the branching factor of that tree.
Re: Arthur Whitney's one liner sudoku solver (2011)
#139Earlier quoted context omitted.
That sounds like 100+ lines in python or similar languages…
A few years back I made a modest attempt at writing a concise yet readable sudoku solver in Python - in about 29 lines: https://github.com/hrzn/sudoku/blob/master/sudoku.py Could have been made shorter at the price of readability.
Re: Arthur Whitney's one liner sudoku solver (2011)
#140https://codegolf.stackexchange.com/questions/tagged/sudoku?t...