Live data from Hacker News

Arthur Whitney's one liner sudoku solver (2011)

dfns.dyalog.com

161–170 of 210 posts

Re: Arthur Whitney's one liner sudoku solver (2011)

#161
For me one of the most important things here is the clarity of the problem -maker- at the top. That's the difference between the "Iversonian" symbolic languages (J and K included) and others. It doesn't have the elegance and power of a one line solution, but it's just so clean and comprehensible even without the disciplined commenting. (Although I really think lamp is not a good comment glyph. Sorry about the sacred cow I just took a swipe at fellow array nerds.)

One line solutions are incredible, and tacit is mind-bendingly cool. To use the unique compactness of a glyph-based language as a way to efficiently describe and perform functional programming - then to do that all over arrays!? - whoever had these ideas [0] is utterly genius.

But as someone trying to make time to write a program ground up in APL, knowing that I won't be able to make it just a set of really good one liners, that example is also significant for me.

[0] https://www.jsoftware.com/papers/fork.htm

Re: Arthur Whitney's one liner sudoku solver (2011)

#162
post #94

Earlier quoted context omitted.

I've been messing with Uiua ( https://www.uiua.org/ ) a good amount recently, and find its sort of dance between having a stack and being an array language somehow gets you to a nice level of legibility despite being a combo of two styles that tend to generate line noise.

Cool language. I happened to notice the ⍜ operator, which operates on a transformed array, then reverts the transformation. Not sure if other array languages include this, but it's a really cool idea. I always found the traditional map/filter operators to be limiting in this regard, kind of like trying to write expressions without using parentheses.

It's in several, particularly newer APL dialects; see https://aplwiki.com/wiki/Under#History . Proud to say I originated the "structural" form used by Uiua, which is able to deal with transformations like filtering that lose parts of the input. Every language now seems to have its own take on what exactly Under means, with different implementations leading to different supported functions and various ways to relax the theory to be more convenient or handle intuitively expected things better.

Re: Arthur Whitney's one liner sudoku solver (2011)

#163
post #133

Earlier quoted context omitted.

Legitimately curious how APL programmers think about maintainability and readability. Is code just thoroughly commented or otherwise documented?

Once you've learned the syntax of the language, long expressions like that are about as readable as however-many-dozen lines of JS/Python with 1-to-3-character variable names; i.e. some parts may be obvious if they're a common pattern or simple enough, but the big picture may take a while to dig out. Probably the biggest readability concern of overly-golfed expressions really is just being dynamically typed, a proble…

I am kind of curious if you have to mentally keep track of the rank/shape/dimensions in your head or if there is some implicit/explicit convention for conveying that to the reader. Does tracking rank/shape become second nature after awhile?

I'm also wondering about things like (APL-style) inner products -- they are undeniably powerful, but it's hard for me to conceptual use cases above rank 3.

Re: Arthur Whitney's one liner sudoku solver (2011)

#164

Earlier quoted context omitted.

Well this is pretty much the goal of the BQN website so my best attempts are there. I might point to the quick start page https://mlochbaum.github.io/BQN/doc/quick.html as a way to feel more comfortable with the syntax right away. And the community page https://mlochbaum.github.io/BQN/community/index.html collects links by others; Sylvia's blog in particular focuses on the sorts of flat array techniques that are usef…

Just looked at the github -- wait, you wrote BQN? My God. Is there any prior art on this -- arraylangs with first class functions? I don't think very many people realize how incredible the semantic power of BQN is. The idea of an arraylang with first class functions... it truly staggers the imagination. I feel like if I were able to wrap my head around it I would never want to code in anything else. Thanks again and…

K, for a start. Whitney's earlier dialect A+ too. See https://aplwiki.com/wiki/First-class_function .

Re: Arthur Whitney's one liner sudoku solver (2011)

#165

I’ve often wondered about languages like APL/k, are the programmers actually able to think about problems more efficiently?

For some classes of problems that are easily vectorized, using an array-focused language can certainly make thinking about them and their solutions more efficient, since you can abstract over the data structure and iteration details. As a quant, I used kdb+/q quite a bit for 5+ years for mid-frequency strategies, but as I moved towards higher frequency trading that required calculations on the order book that couldn'…

What did you switch to after that?

Re: Arthur Whitney's one liner sudoku solver (2011)

#166

It's cool in a novelty way that it’s so short, but I would infinitely prefer something like this for actual work and understanding: def solve(grid): def find_empty(grid): for r in range(9): for c in range(9): if grid[r][c] == 0: return r, c return None def is_valid(grid, num, pos): r, c = pos if num in grid[r]: return False if num in [grid[i][c] for i in range(9)]: return False box_r, box_c = r // 3 * 3, c // 3 * 3 f…

Why is this getting down-voted without comment? Comparative analysis is taboo, now? I don't think Arthur Whitney would feel the least bit threatened by some Python code.

Speculation, but maybe because there is nothing of interest or to note in the comment.

It's not clear why the poster prefers that other implementation, or that they understand APL or array programming.

So as a result the comment reads as "it's in a language I don't know. I'd prefer it in a language I do know." Which is a fairly useless comment.

If that's not what they intended, it would be helpful for them to add some context to their comment.

Re: Arthur Whitney's one liner sudoku solver (2011)

#167
post #98
post #90

Lines 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.

The preferred measure of information content is simply number of bits as used for instance in Algorithmic Information Theory [1]. [1] https://en.wikipedia.org/wiki/Algorithmic_information_theory

By that measure naming a variable “objUser” instead of “user” is better because it has more information, and naming the same variable “cgjkkytdvjkftujmhffetb” is even better because it contains more information.

The parse tree approach is trying to get at a fuzzy notion of useful information and useful density of information.

Re: Arthur Whitney's one liner sudoku solver (2011)

#168
post #141

Earlier quoted context omitted.

This oneliner was obviously done for the giggles, and nobody pretends it's reasonably readable code. Getting anal about definitions here is entirely missing the point. (which is "look, K lets you write extremely dense code!")

I don’t know if that’s the case, simply because all code that I see written by array language programmers looks like code golf. Even the language implementation itself! https://code.jsoftware.com/wiki/Essays/Incunabulum

https://news.ycombinator.com/item?id=39546175

Re: Arthur Whitney's one liner sudoku solver (2011)

#169

Earlier quoted context omitted.

Well this is pretty much the goal of the BQN website so my best attempts are there. I might point to the quick start page https://mlochbaum.github.io/BQN/doc/quick.html as a way to feel more comfortable with the syntax right away. And the community page https://mlochbaum.github.io/BQN/community/index.html collects links by others; Sylvia's blog in particular focuses on the sorts of flat array techniques that are usef…

Just looked at the github -- wait, you wrote BQN? My God. Is there any prior art on this -- arraylangs with first class functions? I don't think very many people realize how incredible the semantic power of BQN is. The idea of an arraylang with first class functions... it truly staggers the imagination. I feel like if I were able to wrap my head around it I would never want to code in anything else. Thanks again and…

Don't most array languages have first class functions?

Re: Arthur Whitney's one liner sudoku solver (2011)

#170

For me one of the most important things here is the clarity of the problem -maker- at the top. That's the difference between the "Iversonian" symbolic languages (J and K included) and others. It doesn't have the elegance and power of a one line solution, but it's just so clean and comprehensible even without the disciplined commenting. (Although I really think lamp is not a good comment glyph. Sorry about the sacred…

Just because you can write everything on one line without any spaces doesn't mean you should.

You can ofcourse removethe capability to do thatand you'll effectively force the programmer to write more venous code, but then its strength as an interfacing tool is very much reduced.

The Iversonian languages has the capability to write incredibly terse code which is really useful when working interactively. When you do, your code truly is write-only because it isn't even saved. This is the majority of code that at least I write in these languages.

When writing code that goes in a file, you can choose which style you want to use, and I certainly recommend making it a bit less terse in those cases. The Iversonian languages are still going to give you organs that are much shorter than most other languages even even it's written in a verbose style.

Post reply on HN