> An "Elimination Sort" is a somewhat farcical sorting algorithm which starts with the leftmost element and keeps subsequent elements that are at least as large as the previous kept element, discarding all other elements. Write a function that: • takes a non-empty numeric vector right argument • returns an "Elimination-sorted" vector of the right argument
@Richard This is about as good as it gets.
Although the explicit version is just as good: {⍵/⍨⍵=⌈\⍵}
I just can't wait for ⍛ Behind…
Since ⍵=⌈\⍵ is max-scan equal to self, it can be written ⌈\⍛=
And then we have the same pattern again; this ^ replicate self, so it can be written this⍛/
Putting both together, we'll have ⌈\⍛=⍛/ which is as elegant as it can get, imo.
The test framework even allows you to write Ⓞ←{⍺←⍵ ⋄ (⍺⍺ ⍺)⍵⍵ ⍵} ⋄ ⌈\Ⓞ=Ⓞ/⍵
Well, you could eliminate anything that is less than its neighbour on the left, then find the fix-point.
{⍵/⍨1,2≤/⍵}⍣≡
Ooh, here's an idea for those that found this too easy: Implement proper general elimination sort, not just for numeric vectors, but for any sortable array.
I'm still a bit bothered by how f⍛g Y is (f Y) g Y but f∘g Y is f g Y instead of Y f (g Y), especially since we're already recommended to use f⍤g Y for f g Y, but oh well.
Adám, when you say "do not use a dfn instead of naming a variable" in abrudz.github.io/style/#df, you mean specifically dfns, and tacit functions are not included, right? As in, {⍵⌿⍨{⍵=⌈\⍵}⍋⍋⍵} is not recommended, but {⍵⌿⍨(⊢=⌈\)⍋⍋⍵} is OK?
I have been "relearning" APL with Dyalog but thought I would
give GNU APL a try. I'm having a problem understanding the results of reading
a text file via ⎕FIO
The text lines output directly from ⎕FIO are different than when the output is
assigning to a variable.
I'm reading a text file that cont...