Live data from Hacker News

Arthur Whitney's one liner sudoku solver (2011)

dfns.dyalog.com

61–70 of 210 posts

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

#61

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't be easily or efficiently vectorized, then continuing to use array-focused languages would have only complicated reasoning about those problems.

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

#62
post #60

[flagged]

Gemini also identifies it as J and this is the output for comparison:

The programming language used in the code is *J* (pronounced "Jay"). It's a concise, array-oriented programming language known for its expressive syntax and powerful capabilities.

Here's a breakdown of the code:

*1. Verb Definition:* * `x(,/{@[x;y;]'(!10)^x|/p[;y]=p,:,3/:-3!p:!9 9}')/&~x` defines a verb (a function in J terminology) and assigns it to the variable `x`.

*2. Verb Structure:* * `x( ... )/&~x` is the basic structure of the verb. `x( ... )` applies the verb defined within the parentheses to its argument, which will be `x` itself. * `/&~x` is a hook, a control flow construct in J. It applies the verb defined within the parentheses to each element of `x` and then applies the verb `&~x` to the resulting array.

*3. Verb Body:* * `,/{@[x;y;]'(!10)^x|/p[;y]=p,:,3/:-3!p:!9 9}` is the body of the verb. Let's break it down further: * `{@[x;y;]` creates a gerund (a verb-like noun) that takes two arguments, `x` and `y`. * `'(!10)^x` generates an array of `x` elements, each raised to the power of `!10` (factorial of 10). `/p[;y]=p` is a conjunction that appends the value of `p` to itself for each element in `y`. * `,:,3/:-3!p:!9 9}` generates an array of 3 elements, each of which is the factorial of `-3` (which is undefined and results in an error) followed by the number 9.

*4. Overall Functionality:* * The verb takes an array `x` as input. * It applies the gerund to each element of `x`, creating an array of arrays. * It then applies the conjunction to each of these arrays, appending the value of `p` (which is likely defined elsewhere in the code) to itself. * Finally, it generates an array of 3 elements with errors and 9s. * The hook `/&~x` applies the verb to each element of `x` and then applies a function that is likely defined elsewhere in the code (since `&~x` is not defined within this verb).

*Note:* Without more context about the definitions of `p` and other variables or functions used in the code, it's difficult to provide a more precise explanation of the verb's exact behavior. However, the breakdown above should give you a general understanding of the code's structure and logic.

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

#63
post #62
post #60

[flagged]

Gemini also identifies it as J and this is the output for comparison: The programming language used in the code is *J* (pronounced "Jay"). It's a concise, array-oriented programming language known for its expressive syntax and powerful capabilities. Here's a breakdown of the code: *1. Verb Definition:* * `x(,/{@[x;y;]'(!10)^x |/p[;y]=p,:,3/:-3!p:!9 9}')/&~ x` defines a verb (a function in J terminology) and assigns i…

Please kindly delete your account, destroy your devices, and move to the woods far away from technology.

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

#64
post #63
post #62

Earlier quoted context omitted.

Gemini also identifies it as J and this is the output for comparison: The programming language used in the code is *J* (pronounced "Jay"). It's a concise, array-oriented programming language known for its expressive syntax and powerful capabilities. Here's a breakdown of the code: *1. Verb Definition:* * `x(,/{@[x;y;]'(!10)^x |/p[;y]=p,:,3/:-3!p:!9 9}')/&~ x` defines a verb (a function in J terminology) and assigns i…

Please kindly delete your account, destroy your devices, and move to the woods far away from technology.

Sure. but please elaborate ..

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

#65
post #64
post #63

Earlier quoted context omitted.

Please kindly delete your account, destroy your devices, and move to the woods far away from technology.

Sure. but please elaborate ..

I cannot comprehend the mindset of people who decide to spam (because that is what your comment is) any forum with a page of bullshit GPT slop. Do you think it's helpful or interesting?

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

#66
post #36
post #32

"one line in your custom language" is not one line at all lol

To be fair K is a real language that's used by more than just him. Why array languages seem to gravitate to symbol soup that makes regex blush I'll never know.

[flagged]

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

#67

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

one nice thing about the array language style is that it's possible to talk about variations on algorithms where the relevant code snippets, being a few characters, fits inline into the discussion; more traditional vertically-oriented languages that take handfuls or dozens of lines to say the same things need to intersperse code display blocks with expository prose

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

#68
post #55

Does anyone have any thoughts on what motivates people to play sudoku or write solvers for sudoku ? I have trouble finding motivation to solve artificial problems. That said I sink hundreds of hours into factorio.

For me personally, I have little motivation to do classical sudokus. They either have a not-so-elegant solve path (usually set by a computer) or are too difficult for me to solve. Variant sudokus on the other hand are a lot of fun. They often have very elegant solve paths and there are many neat tricks you can discover and reason about. Some fun ones, if you'd like to try: - https://logic-masters.de/Raetselportal/Rae…

I also mostly enjoy Sudoku variants, most of which I discovered via Geocaches, interestingly. After solving a few I then implemented a solver with customizable constraints, if anyone's interested, should still be available here:

https://www.sudoku-solver.ch/

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

#69

Earlier quoted context omitted.

[flagged]

"Debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?" — Kernighan, Brian. The Elements of Programming Style (2e) . McGraw-Hill, 1978.

> how will you ever debug it?

By being so smart that your program has obviously zero bugs in it!

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

#70
post #24

Earlier quoted context omitted.

I work with it daily in a bank, and I couldnt find a better way to express it. Many colleagues throwing their keyboard in despair at this stupid impossible to remember syntax.

[flagged]

The average bank/company would rather have an average solution maintained by 10 easily replaceable average developers than a nutty, smart solution only understood by 1 highly talented developer.
Post reply on HN