I don’t even understand BQN, and I agree it is objectively better than the Python solution. Seems like the extra time learning the glyphs is well worthwhile for these sorts (pun intended) of elegant solutions
The alternatives for sorted(nums)[::-1] are either: sorted(nums, reverse=True) reversed(sorted(nums)) These also return iterators whereas the slice notation does not.
Once again, for me, Haskell strikes the perfect balance between readability and conciseness: length . filter (> 0) . scanl1 (+) . reverse . sort (sort from Data.List)
For bonus madness, we do not need to sort the positive elements, nor do we need to process negative elements after the value drops below 0. length . takeWhile (> 0) . scanl1 (+) . sortOn (negate . min 1)
Love BQN! Looks like a bridge between “functional” and Iversonian languages. import pandas as pd pd.Series(nums).sort_values(ascending=False).cumsum().gt(0).sum()
I like the BQN solution, but what I feel is difficult isn't just learning the glyphs, but also the semantics of the trains. I don't quite understand why you need to add a nothing at 4:37, what are the regular precedence semantics?
It's only readable once you understand how to read it or what they mean. That's like when Ruby advocates used to say (used to because no one uses that language for anything new anymore) that their random operator symbols were oh so easy to pick up and read. Only if you don't learn them first you have no idea what they mean.
Because this won’t solve the problem. In order to maximise the prefix you want the numbers arranged in reverse order. We are essentially creating the optimal arrangement of numbers then calculating the length of the prefix.
BQN FTW again. IMO, the best counter to the "it's hieroglyphics" complaint is to imagine doing math in "natural" language. For example "x plus 2 times y divided by 1 minus x plus the square root of y". Is that really more readable? Obviously not, and yet that is essentially the argument. Also what is "natural" language is a bias towards a specific set of symbols (typically a Latin alphabet) and a specific vocabulary (typically English) that people forget took them years in their youth to fully comprehend.
there is a big difference between symbols that are pervasive throughout human life from kindergarten, of which there are only a handful, versus a set of alien wingdings that encapsulate complex procedures.
@@NEO97online True, but the glyphs can vary drastically in clarity as well. An example here is the descending sort being the vertical mirror of the ascending sort. The reduction and scan are also related, albeit not as clearly. Meanwhile, "phi combinator" is just an awful name; phi is just a glyph from another context. Some of those gain traction, like pi for a circle constant or c for the speed of light. You may even be more familiar with capital sigma as a sum operator than as a letter.
Would be nice a video on Nial, it seems like a nice language for introducing array programming without the 'scare' of such a terse syntax, and the function atlas feature seems like an interesting way of function composition using the array themselves (i.e doing `[f, g] x` results in '[f(x), g(x)]')
mr code_report can you solve this in BQN in a video? "You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N. Write a method that takes the array as an argument and returns this "outlier" N."
I just realized BQN is the next letter for APL... oops. (Your channel is my first interaction with array programming, though I seem to struggle to find much resources on YT abt it, I just get taught what arrays are again and again)
Hey I've come across a problem that required me to implement the flood fill algorithm and it got me wondering how a flood fill could be done in APL/BQN. I came up empty-handed. How would you implement flood fill in BQN?
My first thought would use a convolution to grow a mask recursively until it stopped growing. Hardly efficient, but this series focuses on terse source over anything else, it seems. It would also translate easily to GPUs.
Been programming in python and I just started learning J, so this vid is a perfect step-by-step of array language concepts. (A YT search for 'j language' showed many of your vids up top, easily the best produced of the lot IMHO). I love the conciseness of array languages; a possible quick-n-dirty J version of the BQN solution might be: +/ 0< +/\ (\: nums) { nums No doubt you could improve it (I'm still fuzzy on forks, hooks, etc.). Great stuff 👍🏻
I disagree with your argument that it's readable. I think having short English names will be useful in larger programs. There are lots of functions. You're not going to be able to have an op for all of them. Aside from this, whitespace delimiting is good practice as well because when looking at the BQN source, it's not immediately obvious how the op apply semantics works just from the syntax. Imo other languages make this more explicit. This could be familiarity, but I doubt that very much. A good way to test this would just be to write one reasonably sized project in both languages using the same algorithms and see if you're struggling more to understand what you've written in one than the other.
Why have a function (operator) for all of them? You can *compose* operators in APL-type languages. I agree about the white space. I'm not a fan of BQN, to be honest.
@@Evan490BC Even with composition, you're not going to get all the functions you'd want into some op or composition of ops. I personally prefer languages that keep the ops list short and similar to the ordinary arithmetic ops everyone already knows.
Without using the itertools: def maxScore(nums): prefix_sum = 0 return sum(1 for num in sorted(nums, reverse=True) if (prefix_sum := prefix_sum + num) > 0)
I'm sitting here, sober and awake... Understanding very little of BQN. I can't wait to see what kind of whack stuff drunk and tired me will come up with.
I really don’t see how you could argue that it’s more readable. Sure accumulate is not a great name, but the bqn solution looked like a curse word in a comic book.
It takes 0 thought to remember what sorted(nums) does in python, its literally in the name. [::-1] is dumb and requires memory though, you are right there.
Would anyone actually use BQN for large code bases that do more than solving interesting problem sets? I mean I wouldn't use Python for that either, but still.
The BQN solution is cute, however, why should we have sort as a primitive? Even the APL-likes can't agree on the set of combinators/other primitives to include. The equivalent Haskell/Factor solution would be much more readable.
One one hand I enjoy this youtube channel... ... on the other hand I can't help but to think that no one should care about how short (as measured in the number of characters) a code like this is. No only software development consistents maybe in .1% (max) of writing code doing computations like this, but also the Python example here is easily much more readable for an average human being or an average software developer. After watching couple of these BQN related videos, I really see no point in it, other then a novelty of sorts.
Complaining about "accumulate" being a poorly named function is intensely hypocritical when you consider that BQN functions are named after random squiggles.
Connor, don't know how to leave feedback with you through ArrayCast (not going to send an email through "Contact") so I'm leaving a comment here. Why did you invite Nick Psaris to go on about Q and Python integration when it's not available to the free personal license edition of Q? No one in your audience is going out to purchase a kdb Insights license to use that facility and a 30 day "free trial" doesn't cut it. Please stop promoting pay to play because this kind of tech space is way out of anyone's personal affordability.
I would disagree with the argument that it makes it readable. Even though I know why you love BQN and especially "tight and concise" represenation of functions. But Reality is that when it comes to industry adoption and hiring people, "verbose languages" will always come on the top of the chart. Also, even after this much "verbosity", most people don't know how to program. And if we start using BQN in front of them, they would thought that we are some sort of aliens 😂😂. You could understand if I took a different example. Most people who have degree in Maths, don't use concise mathematical language while teaching. And there are some books, who are actually thick and still uses concise language. Ultimately, While we respect for your choice of programming language, the reality is no language is better than another. And they are just tools.
Exactly. Perl used to have lots of shorthand operators which leads to very short codes. But they don't call it write once read never for nothing. I can look at my self written Perl scripts now and have zero idea how they work. I'd never go back to shorthand symbology again. Give me verbose, easy to understand code anytime.
BQN stuff is cool, but I personally prefer Python solution cause for me understanding verbose code is much easier than code composed of symbols. Though, I am just rookie in programming and it is very possible that my opinion will change in the future.
With Python it would be much better to use a module which provides array-programming. With nums being a pandas.Series for example the solution is: nums.sort_values(ascending=False).cumsum().gt(0).sum()
Wait, I thought APL was your favorite language? Don't tell me you are one of those fly by night language guys that can't commit to a language and never find a long term working relationship.
Or even better, again in Julia: nums |> sort |> reverse |> cumsum .|> >(0) |> sum Produces exactly the same assembly code as the previous one. Supreme readability, at least to my eyes. Someone who does not know Julia may find only the second-last function confusing. Apart from that, the data flows through smoothly.
I don’t even understand BQN, and I agree it is objectively better than the Python solution. Seems like the extra time learning the glyphs is well worthwhile for these sorts (pun intended) of elegant solutions
The alternatives for sorted(nums)[::-1] are either:
sorted(nums, reverse=True)
reversed(sorted(nums))
These also return iterators whereas the slice notation does not.
Once again, for me, Haskell strikes the perfect balance between readability and conciseness:
length . filter (> 0) . scanl1 (+) . reverse . sort
(sort from Data.List)
For bonus madness, we do not need to sort the positive elements, nor do we need to process negative elements after the value drops below 0.
length . takeWhile (> 0) . scanl1 (+) . sortOn (negate . min 1)
BQN feels like Regex but as a language
Love BQN!
Looks like a bridge between “functional” and Iversonian languages.
import pandas as pd
pd.Series(nums).sort_values(ascending=False).cumsum().gt(0).sum()
I told you already, the Egyptians built the great pyramids, invented APL and vanished.
i’m pretty sure Egypt still exists
the 111 million Egyptians right now :
I like the BQN solution, but what I feel is difficult isn't just learning the glyphs, but also the semantics of the trains. I don't quite understand why you need to add a nothing at 4:37, what are the regular precedence semantics?
It's only readable once you understand how to read it or what they mean. That's like when Ruby advocates used to say (used to because no one uses that language for anything new anymore) that their random operator symbols were oh so easy to pick up and read. Only if you don't learn them first you have no idea what they mean.
or when english speakers insist that programming languages need to be in english using only the english alphabet
Could someone please explain, why we need to sort that array?
Why couldn't we just do:
sum(num for num in nums if num > 0)
Because this won’t solve the problem. In order to maximise the prefix you want the numbers arranged in reverse order. We are essentially creating the optimal arrangement of numbers then calculating the length of the prefix.
BQN FTW again. IMO, the best counter to the "it's hieroglyphics" complaint is to imagine doing math in "natural" language. For example "x plus 2 times y divided by 1 minus x plus the square root of y". Is that really more readable? Obviously not, and yet that is essentially the argument. Also what is "natural" language is a bias towards a specific set of symbols (typically a Latin alphabet) and a specific vocabulary (typically English) that people forget took them years in their youth to fully comprehend.
good argument
there is a big difference between symbols that are pervasive throughout human life from kindergarten, of which there are only a handful, versus a set of alien wingdings that encapsulate complex procedures.
@@NEO97online True, but the glyphs can vary drastically in clarity as well. An example here is the descending sort being the vertical mirror of the ascending sort. The reduction and scan are also related, albeit not as clearly. Meanwhile, "phi combinator" is just an awful name; phi is just a glyph from another context. Some of those gain traction, like pi for a circle constant or c for the speed of light. You may even be more familiar with capital sigma as a sum operator than as a letter.
They are not alien after just a little bit of usage and practice.
What does accumulate/+` do exactly?
EDIT: Nevermind I figured it out lol
Would be nice a video on Nial, it seems like a nice language for introducing array programming without the 'scare' of such a terse syntax, and the function atlas feature seems like an interesting way of function composition using the array themselves (i.e doing `[f, g] x` results in '[f(x), g(x)]')
mr code_report
can you solve this in BQN in a video?
"You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer N. Write a method that takes the array as an argument and returns this "outlier" N."
I just realized BQN is the next letter for APL... oops. (Your channel is my first interaction with array programming, though I seem to struggle to find much resources on YT abt it, I just get taught what arrays are again and again)
Hey I've come across a problem that required me to implement the flood fill algorithm and it got me wondering how a flood fill could be done in APL/BQN.
I came up empty-handed. How would you implement flood fill in BQN?
My first thought would use a convolution to grow a mask recursively until it stopped growing. Hardly efficient, but this series focuses on terse source over anything else, it seems. It would also translate easily to GPUs.
Which gives one more nerd cred? BQN or Haskell?
Been programming in python and I just started learning J, so this vid is a perfect step-by-step of array language concepts. (A YT search for 'j language' showed many of your vids up top, easily the best produced of the lot IMHO). I love the conciseness of array languages; a possible quick-n-dirty J version of the BQN solution might be:
+/ 0< +/\ (\: nums) { nums
No doubt you could improve it (I'm still fuzzy on forks, hooks, etc.). Great stuff 👍🏻
I disagree with your argument that it's readable. I think having short English names will be useful in larger programs. There are lots of functions. You're not going to be able to have an op for all of them. Aside from this, whitespace delimiting is good practice as well because when looking at the BQN source, it's not immediately obvious how the op apply semantics works just from the syntax. Imo other languages make this more explicit. This could be familiarity, but I doubt that very much. A good way to test this would just be to write one reasonably sized project in both languages using the same algorithms and see if you're struggling more to understand what you've written in one than the other.
Why have a function (operator) for all of them? You can *compose* operators in APL-type languages. I agree about the white space. I'm not a fan of BQN, to be honest.
You may prefer Q, which is a "cousin" of BQN. With Q, you'd write this as MaxScore: sum 0< sums desc @
@@abrudz Nial is also nice.
@@Evan490BC Even with composition, you're not going to get all the functions you'd want into some op or composition of ops. I personally prefer languages that keep the ops list short and similar to the ordinary arithmetic ops everyone already knows.
@@hardknockscoc I lost you there... Why not? APL is a Turing-complete language. Can you explain what you mean?
Without using the itertools:
def maxScore(nums):
prefix_sum = 0
return sum(1 for num in sorted(nums, reverse=True) if (prefix_sum := prefix_sum + num) > 0)
Does BQN easily produce std::partition and std::stable_partition ?
Hey!
Have you heard about Standard ML(SML)?
Could you someday solve a problem using this language, please?
I'd appreciate that.
Love these videos! Thanks
I'm sitting here, sober and awake... Understanding very little of BQN.
I can't wait to see what kind of whack stuff drunk and tired me will come up with.
in python you should be doing sorted(nums, reverse=True)
Bro I don't have those on my keyboard
sorted takes the arg "reverse=True"
You should try this in numpy or pandas which implements array programming.
I really don’t see how you could argue that it’s more readable. Sure accumulate is not a great name, but the bqn solution looked like a curse word in a comic book.
New trend unlocked: Array languages.
its incredible how ungrounded from reality this type of programming is.
for a fair comparison with Python, I suggest to implement a web-server in BNQ. I hope, there is no ready made glyph for that, lol.
APL is no longer your favorite language? :)
APL : Math = Python : Natural language = C : Assembly ?
Would be nice if you would use dark mode on all your views/webpage.. black on white is hard for the coder eyes
I totally agree, LeetCode dark mode doesn't apply to the problem statement pages atm.
@@code_report Maybe you can add a user-style saying :root{filter:invert(1)hue-rotate(180deg)}
It takes 0 thought to remember what sorted(nums) does in python, its literally in the name. [::-1] is dumb and requires memory though, you are right there.
missing your videos ! plz release more (your life nonblocking)
Would anyone actually use BQN for large code bases that do more than solving interesting problem sets? I mean I wouldn't use Python for that either, but still.
6:11 it IS hard to read. It's like learning kanji as opposed another alphabet (let's say Cyrillic if your native language uses Latin).
The BQN solution is cute, however, why should we have sort as a primitive? Even the APL-likes can't agree on the set of combinators/other primitives to include. The equivalent Haskell/Factor solution would be much more readable.
Do fizzbuzz
One one hand I enjoy this youtube channel...
... on the other hand I can't help but to think that no one should care about how short (as measured in the number of characters) a code like this is.
No only software development consistents maybe in .1% (max) of writing code doing computations like this, but also the Python example here is easily much more readable for an average human being or an average software developer.
After watching couple of these BQN related videos, I really see no point in it, other then a novelty of sorts.
I mean, BQN sounds cool and all, but this syntax feels way too much like regex to my liking.
Complaining about "accumulate" being a poorly named function is intensely hypocritical when you consider that BQN functions are named after random squiggles.
In python 3.10+ you can replace 'List' with 'list'
Gibson Streets
Connor, don't know how to leave feedback with you through ArrayCast (not going to send an email through "Contact") so I'm leaving a comment here. Why did you invite Nick Psaris to go on about Q and Python integration when it's not available to the free personal license edition of Q? No one in your audience is going out to purchase a kdb Insights license to use that facility and a 30 day "free trial" doesn't cut it. Please stop promoting pay to play because this kind of tech space is way out of anyone's personal affordability.
I would disagree with the argument that it makes it readable. Even though I know why you love BQN and especially "tight and concise" represenation of functions. But Reality is that when it comes to industry adoption and hiring people, "verbose languages" will always come on the top of the chart. Also, even after this much "verbosity", most people don't know how to program. And if we start using BQN in front of them, they would thought that we are some sort of aliens 😂😂. You could understand if I took a different example. Most people who have degree in Maths, don't use concise mathematical language while teaching. And there are some books, who are actually thick and still uses concise language.
Ultimately, While we respect for your choice of programming language, the reality is no language is better than another. And they are just tools.
Exactly. Perl used to have lots of shorthand operators which leads to very short codes. But they don't call it write once read never for nothing. I can look at my self written Perl scripts now and have zero idea how they work.
I'd never go back to shorthand symbology again. Give me verbose, easy to understand code anytime.
BQN stuff is cool, but I personally prefer Python solution cause for me understanding verbose code is much easier than code composed of symbols. Though, I am just rookie in programming and it is very possible that my opinion will change in the future.
Christiana Rapids
BQN is just unreadable
Just use Julia s 💀
what is this monstrosity!!!
Must be the most unreadable language i have ever seen
With Python it would be much better to use a module which provides array-programming.
With nums being a pandas.Series for example the solution is:
nums.sort_values(ascending=False).cumsum().gt(0).sum()
Wait, I thought APL was your favorite language? Don't tell me you are one of those fly by night language guys that can't commit to a language and never find a long term working relationship.
import itertools
import toolz
from typing import List
def max_score(nums: List[int]) -> int:
return toolz.pipe(
nums,
sorted,
reversed,
itertools.accumulate,
lambda xs: (x > 0 for x in xs),
sum,
)
Julia:
findfirst(
Julia: sort(nums,rev=true) |> cumsum .|> >(0) |> sum
This looks way more readable in a font that has a ligature for |>
Or even better, again in Julia: nums |> sort |> reverse |> cumsum .|> >(0) |> sum
Produces exactly the same assembly code as the previous one. Supreme readability, at least to my eyes. Someone who does not know Julia may find only the second-last function confusing. Apart from that, the data flows through smoothly.
𓀃𓈬𓋏𓉮𓀠𓆘 We are so back