I love this! I do feel like APL instructions tend to map to lines in other languages, somewhat (though of course instructions can be combined onto lines in other languages too, e.g. you can do 2 + 3 * 4 in almost every language). APL instructions are one character, and not counting the parentheses (since those probably wouldn't be necessary, splitting it up onto lines) the solution given in the video has 11 characters. APL definitely looks much more concise-and it is, for sure-but if you mapped the APL instructions to Python words, and added back in the necessary variables, you'd have a Python solution. What I love about APL most isn't the fact that the solution is 13 characters; what I love is that there's no redundancy.
Just be obligatory reminder, that beeig verbose is not necessarily a bad thing. I much rather read in German than in Ithkuil. And i can mich easier comprehend what's happening in a Rust programm than Perl or even APL.
This is an APL fan account, sir, please take your correct opinions about scalable software elsewhere (jokes aside the obligatory reminder is received and respected) Terse code can be fun, and more truthful than verbose. Bad code is the real only enemy
It's also nice to add that good code is always code that is maintainable, following clean code principles, when working in big companies, it's always good bein verbose when you gain simplicity with it, making other devs comfortable to maintain and improve your code. Just as a reminder that we don't write code for ourselves, but actually for other devs to be able to maintain and grow our codebase ☺️
Reminds of another code_report video about a problem with two apl solutions, one slightly less "verbose" than the other, but also less performant. There's beauty and ungliness in both sides. Both ends can either make it easy on the eye and mind, but also they can obscure everything. Maybe, like in most things in life, the key is balance
Superb! I've been listening to all of the ArrayCast podcasts and been hungering for more of these videos from you. It would be especially nice to get more stuff on BQN since you have convinced me that it is the best array language to use.
It will be great if you or someone provide separate tutorials on how to use BQN, J, and APL for very beginners. I would find more useful to learn how to install the programs and how to use each command (explained in a series of videos), and then some basic demonstrations/samples. That means: from zero to intermediate to advanced. The ones you are currently providing are advanced.
@@code_report Thank you, but that one is to install Dyalog on Ubuntu. It would be nice to have a tutorial specific to BQN that shows how to install it on Windows and the explanations on at least the most important commands. I did not find BQN tutorials on UA-cam that show the basics of BQN.
@@code_report Thank you for the getting started video with APL, but that one is mainly about how to install Dyalog in Ubuntu and only a few commands. I have not found a UA-cam tutorial that shows the basics of BQN: How to install it in Windows, what editor is most recommended to type the commands, and an explanation of the commands specific to BQN. The same for J. Yes, I can visit websites related to those, but it will be nice to have UA-cam videos that actually show how.
Negating the entire boolean array and then re-summing everything seems inefficient. You would get the same result by simply subtracting the row and column sums from their axis lengths. Incorporating that shortcut into the final outer product cleverly may in fact eliminate the need for outer product, I think. Also, in my opinion, the problem statement is needlessly obscure and difficult to follow. It’s like they’re trying too hard to not give away obvious candidate algorithms.
Something like this? +⌜´ ((2×+´)-≠)˘¨ ⋈⟜⍉ grid Take both the matrix and its transposition, subtract the axis length from twice the sum (since each 1 is a missing 0 also), and make a sum table from those two vectors.
This is all nice and everything, but a NumPy-based Python solution would be a two-liner and a **ton** more readable (and anyone doing serious matrix manipulation in Python would use NumPy anyway): y = 1 - x diff = np.add.outer(x.sum(axis=1) - y.sum(axis=1), x.sum(axis=0) - y.sum(axis=0))
If I don't know bqn or apl, and I learn bqn first, would there be any need to learn apl? Didn't bqn come from apl? Does apl offer something that bqn doesn't??
No. There are differences in features like first class functions, role conversions, namespaces, affine characters, leading axis model, how to overlap shared glyphs, etc. But they probably share considerably more.
My Julia code was "solution = sum(X, dims=1) .+ sum(X, dims=2) .- sum(X.==0, dims=1) .- sum(X.==0, dims=2)", but I'm not sure if I can reduce that any further. Weirdly I tested it with a 100x100 matrix and that version seems to scale better than the longer fully looped version (going from 6.5x slower with the 3x2 matrix to 74x faster).
@@jayantchoudhary1495 I don't know if you actually have used it or not. But Prolog is so limited and imo difficult, it's probably one of the few languages where making a compiler and interpreter for it would be easier than actually learning how to properly use it. I might not have enough experience with Prolog to be a proper judge but for me at least it's difficult and frustrating even for trivial tasks.
@@torarinvik4920 oh i have used it to solve may of the previous years advent of code problems. The problem usually is execution speed as I am still not good at optimization. For this particular problem just 1)take row wise and column wise sum (with accumulate) 2)subtract n from it ( from the n by n grid provided) to get sum of zeros 3) plug the formulas it's done.
Coming home from salsa dancing where I try not to break my legs to a video of Conor where I try not to overload my brain. Perfekt evening :)
I'm gonna have a crack at doing Advent of Code 2022 in BQN (starts in 4 hours)
You should do it too so I can learn from your solutions!
I plan on posting a few videos 🙂
@@code_report nice!
I love this! I do feel like APL instructions tend to map to lines in other languages, somewhat (though of course instructions can be combined onto lines in other languages too, e.g. you can do 2 + 3 * 4 in almost every language). APL instructions are one character, and not counting the parentheses (since those probably wouldn't be necessary, splitting it up onto lines) the solution given in the video has 11 characters. APL definitely looks much more concise-and it is, for sure-but if you mapped the APL instructions to Python words, and added back in the necessary variables, you'd have a Python solution. What I love about APL most isn't the fact that the solution is 13 characters; what I love is that there's no redundancy.
Just be obligatory reminder, that beeig verbose is not necessarily a bad thing. I much rather read in German than in Ithkuil. And i can mich easier comprehend what's happening in a Rust programm than Perl or even APL.
This is an APL fan account, sir, please take your correct opinions about scalable software elsewhere (jokes aside the obligatory reminder is received and respected)
Terse code can be fun, and more truthful than verbose. Bad code is the real only enemy
@@arisweedler4703 i know it is, and i kinda love it, thats why it's just the reminder not a rant essay. Sometimes i just need a little anger outlet.
It's also nice to add that good code is always code that is maintainable, following clean code principles, when working in big companies, it's always good bein verbose when you gain simplicity with it, making other devs comfortable to maintain and improve your code.
Just as a reminder that we don't write code for ourselves, but actually for other devs to be able to maintain and grow our codebase ☺️
Reminds of another code_report video about a problem with two apl solutions, one slightly less "verbose" than the other, but also less performant.
There's beauty and ungliness in both sides. Both ends can either make it easy on the eye and mind, but also they can obscure everything. Maybe, like in most things in life, the key is balance
unless u go the other extreme .... toki pona
Yess code report is back spreading the array gospel
Superb! I've been listening to all of the ArrayCast podcasts and been hungering for more of these videos from you. It would be especially nice to get more stuff on BQN since you have convinced me that it is the best array language to use.
code report upload??? what a pleasant surprise!!
In BQN you can use the Cells 1-modifier instead of Rank 1.
Oops, I forgot 🙃
Yeah I was thinking the same thing
I don't understand a character that's there, but it's BEAUTIFUL!
It will be great if you or someone provide separate tutorials on how to use BQN, J, and APL for very beginners. I would find more useful to learn how to install the programs and how to use each command (explained in a series of videos), and then some basic demonstrations/samples. That means: from zero to intermediate to advanced. The ones you are currently providing are advanced.
I have a getting started video with APL: ua-cam.com/video/eACzuQGp3Vw/v-deo.html
@@code_report Thank you, but that one is to install Dyalog on Ubuntu. It would be nice to have a tutorial specific to BQN that shows how to install it on Windows and the explanations on at least the most important commands. I did not find BQN tutorials on UA-cam that show the basics of BQN.
@@code_report Thank you for the getting started video with APL, but that one is mainly about how to install Dyalog in Ubuntu and only a few commands. I have not found a UA-cam tutorial that shows the basics of BQN: How to install it in Windows, what editor is most recommended to type the commands, and an explanation of the commands specific to BQN. The same for J. Yes, I can visit websites related to those, but it will be nice to have UA-cam videos that actually show how.
I have a hunch that aliens might read this code easier than us.
While I have heard about APL, I still the title as a 'I love apple and bacon'.
BQN is bad for you. Too much potassium nitrate and salt.
Do you have recommendations on learning APL? I am on MacOS so it has to work on that platform.
Negating the entire boolean array and then re-summing everything seems inefficient. You would get the same result by simply subtracting the row and column sums from their axis lengths. Incorporating that shortcut into the final outer product cleverly may in fact eliminate the need for outer product, I think. Also, in my opinion, the problem statement is needlessly obscure and difficult to follow. It’s like they’re trying too hard to not give away obvious candidate algorithms.
Well, the whole expression should be optimised out into a single pass algorithm before execution so it's all good.
Something like this? +⌜´ ((2×+´)-≠)˘¨ ⋈⟜⍉ grid
Take both the matrix and its transposition, subtract the axis length from twice the sum (since each 1 is a missing 0 also), and make a sum table from those two vectors.
Bro really pulled out the standard galactic alphabet for this one
This is all nice and everything, but a NumPy-based Python solution would be a two-liner and a **ton** more readable (and anyone doing serious matrix manipulation in Python would use NumPy anyway):
y = 1 - x
diff = np.add.outer(x.sum(axis=1) - y.sum(axis=1), x.sum(axis=0) - y.sum(axis=0))
It's been 84 years...
Code golf is the best golf
😲 wowww Nice solution!!!
If I don't know bqn or apl, and I learn bqn first, would there be any need to learn apl?
Didn't bqn come from apl? Does apl offer something that bqn doesn't??
Less is more.
Flatter is better.
Unicode thighs save lives.
nice language and solution but the syntax uses goofy ahh symbols, which are nice in a way but hard to convey their meaning
Easily readable one liner numpy solution (as it is always possible):
2 * (grid.sum(axis=0) + grid.sum(axis=1, keepdims=True)) - sum(grid.shape)
Is BQN just a transliteration of APL, or of J for that matter?
No. There are differences in features like first class functions, role conversions, namespaces, affine characters, leading axis model, how to overlap shared glyphs, etc. But they probably share considerably more.
My Julia code was "solution = sum(X, dims=1) .+ sum(X, dims=2) .- sum(X.==0, dims=1) .- sum(X.==0, dims=2)", but I'm not sure if I can reduce that any further.
Weirdly I tested it with a 100x100 matrix and that version seems to scale better than the longer fully looped version (going from 6.5x slower with the 3x2 matrix to 74x faster).
I like Julia too
[sum(v+w) for v ∈ eachrow(2X.-1), w ∈ eachcol(2X.-1)]
(actually one should use a let to avoid computing twice 2X-1)
how dare you offend the (actually surprisingly sizeable) hoards of bqn-invested children.
beautiful, but not readable who cares!?
For some reason the algorithm (™) chose not to present me this video but I’m very happy I found it now! code_report Leetcodes are back bb!
If you want an extra challenge, try solving it in Prolog
why, seems pretty straightforward?
@@jayantchoudhary1495 I don't know if you actually have used it or not. But Prolog is so limited and imo difficult, it's probably one of the few languages where making a compiler and interpreter for it would be easier than actually learning how to properly use it. I might not have enough experience with Prolog to be a proper judge but for me at least it's difficult and frustrating even for trivial tasks.
@@torarinvik4920 oh i have used it to solve may of the previous years advent of code problems. The problem usually is execution speed as I am still not good at optimization.
For this particular problem just 1)take row wise and column wise sum (with accumulate)
2)subtract n from it ( from the n by n grid provided) to get sum of zeros
3) plug the formulas
it's done.
@@jayantchoudhary1495 Nice :)
This works, too: -⍥(+/∘.++⌿)∘~⍨
Basically, pass the argument to both tines of the fork, preprocessing the right side with negate.
solution
Where you have:
x ← ...
x
this also works:
⊢x←...