APL Wins (vs C++, Java & Python)

preview_player
Показать описание


Рекомендации по теме
Комментарии
Автор

Been learning APL, Its kind of refreshing when what would be a library function in another language is just a primitive in APL.

remyclarke
Автор

You can make it a one-liner in Python too using unpacking and sets and the re package:
{*map(int, re.findall(r"\d+", string))}

MatteoCampinoti
Автор

3:29 the description of partition.

It makes perfect sense and it’s super simple! I wish I had a video like that for each and every APL symbol! Reading about them just isn’t the same as having hands-on experience playing with them.

Maybe I should try making a video or two about APL glyphs…

arisweedler
Автор

I don't like programming C++ and have been cheering for APL and it's descendants for some time. But after running into a "limit error" for the first time in J the other day, I'm now suspicious of the scalability of idiomatic array language solutions. I've also seen articles in Vector magazine where they acknowledge that over-computation is an inevitable part of the array programming approach and hand wave it away by saying you'll get the time back through some other aspect of the design.

But the point of these challenges is to learn good ways of programming that sort of problem in that language for whatever data you have, and the C++ solution is a pattern you could use at any scale of data. The imperative language solutions using sets only store the original string, unique elements found so far, and iterate exactly once over the input string. This is almost ideal use of space and time.

So here's my challenge for you: Do these separate operations for masking and partitioning have special code? What would you do about the belated integer conversion+uniqueness check if you had enough memory for just the unique elements and the original string was half full of duplicates?

What is your realistic time and space complexity for very large strings?

dukereg
Автор

JS:
new

Python:
len(set(re.findall("\d+", inputStr)))

AbuTarik
Автор

In PHP of all languages it can be solved like this:
fn($e) => count(array_unique(preg_split('/[^\d]+/', $e, -1, PREG_SPLIT_NO_EMPTY), SORT_NUMERIC))

Almost as elegant as APL, but in a more clumsy syntax. More readable though.

mikkolukas
Автор

It might look nice indeed but doesn't it use more memory space and time? Probably O(n²) compared to O(n) in the other solutions

LazieKat
Автор

One-liner in Python that you can actually read:

tests = ["a123bc34d8ef34", "leet1234code234", "a1b01c001"]
solve = lambda s: len(set(map(int, re.findall("\d+", s))))
print(list(map(solve, tests)))

gives [3, 2, 1] as expected

mbgdemon
Автор

Really liked the APL solution - I started learning APL few days back and then got to know about these cool videos! Btw my initial solution for this one would be a regex based thing done in Ruby, like so:
require 'set'
def count_nums(x)
Set.new(x.scan(/\d+/).map {|s| s.to_i}).count
end

SouravDatta
Автор

APL failed to become popular because it is a "write-only" language. It is not possible to read an APL program unless you have memorized all of the APL characters and know what they do. We can easily read the other programming languages and can infer their function even if we are not completely fluent with the languages. APL does a number of things very well but it was never a general purpose programming language.

KevinInPhoenix
Автор

Hey. I was wondering what settings do you have in your IDE so it looks that good? I downloaded Dyalog and it looks like it came straight from 1998

johk
Автор

One liners
modern JS - [...new => x != '').map(x => parseInt(x)))].length
C# - Regex.Split(str, "[^\\d]+").Where(p => p != "").Select(p =>

readable, maintainable

danilmoscow
Автор

6:08, I wrote a template f() in C++ for this, and solved the algorithm in 2 middle-level lines + the returning 1; resulting in 27 asm cmds (O2 and O3). If adding 2 more lines, to handle edge cases, like empty strings, results in 44 asm cmds (O2 and O3). And then I smashed those 2 algorithmic lines into 1 low-level line (with only 1 necessary white space, btw), yielding 62 characters.

MrAbrazildo
Автор

My god you have infested my brain. My first thought was which algorithms to use on C++. Then I recognized you could iterate though the string but I remembered how much I hate operating on strings. I'm not thinking in algorithms too well yet though, I thought maybe there's something to split chains of characters and maybe filter with isdigit, then transform them into a vector of the desired result format, I guess in this as the length of the vector. Or maybe it should be a container that doesn't have duplicates.

Although I missed the requirement to replace the characters with spaces, which seems kinda silly.

Yupppi
Автор

how do you make the Dyolog apl program look so great? you have cool text and stuff and i want it just like that

brian-bed
Автор

fyi, one of the test cases uses two large numbers, 192383183928778851682383 and 2089984061937879119; when converted to uint64s, they evaluate to the same number. To pass all the tests, you either need to use bigints (Python solution) or use strings and trim the leading zeros (C++ solution). Does APL implicitly convert to bigints? If not, your program has a bug.

gnuvince
Автор

love these short videos with their nifty apl one-liners so well explained by you!

tommybandzaw
Автор

Less lines is neither better nor worse.
Is it actually faster than C++ or how is this "winning"?

svenvancrombrugge
Автор

I started in APL language and I ended my programming there .. 24hrs back never looked back

torajeshkg
Автор

My first thought is if all the non number chars were spaces. You could use stringstream and >> into the integers.

Sebanisu