An APL a day! - Put It In Reverse

Without much ado, today’s problem - Put it in Reverse The find function X⍷Y identifies the beginnings of occurrences of array X in array Y. In this problem, you’re asked to return a result that identifies the endings of occurrences of array X in array Y. To keep things simple, X and Y will be at most rank 1, meaning they’ll either be vectors or scalars. Write a function that: takes a scalar or vector left argument takes a scalar or vector right argument returns a Boolean result that is the same shape as the right argument where 1’s mark the ends of occurrences of the left argument in the right argument Examples: 'abra' findEnd 'abracadabra' 0 0 0 1 0 0 0 0 0 0 1 'issi' findEnd 'Mississippi' 0 0 0 0 1 0 0 1 0 0 0 'bb' findEnd 'bbb bbb' 0 1 1 0 0 1 1 (,42) findEnd 42 0 42 findEnd 42 1 (,42) findEnd ,42 1 'are' 'aquatic' findEnd 'ducks' 'are' 'aquatic' 'avians' 0 0 1 0 Solution See the solution {⌽(⌽⍺)⍷⌽⍵} We use ⍷ to find beginning of reversed array ⌽⍺ in ⌽⍵ We reverse this to get the ending of ⍺ in ⍵ Taking example 'abra' {⌽(⌽⍺)⍷⌽⍵} 'abracadabra' ...

February 21 2025 · 2 min · Raunak

An APL a day! - Elimination Sort

I’ve started dabbling with APL. It has been a lot of fun solving the current batch of challenges. Archive. I loved how each challenge focuses on a small set of operators and makes us use them in various (devious!) combinations to solve the problems. I’m going through some of the older challenges to learn about more operators. The past challenges can be found at APL Quest. Today, we’ll be solving the first problem from the 2023 challenge. Use tryapl.org as an online interactive REPL. Elimination Sort 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. For example: EliminationSort 1 3 7 3 5 8 5 8 1 6 1 8 1 10 8 4 3 4 1 4 1 3 7 8 8 8 10 Write a function that: takes a non-empty numeric vector right argument returns an “Elimination-sorted” vector of the right argument Hint: The progressive-maxima idiomatic phrase ⌈, the greater or equal function ≥, and the replicate function / could be helpful in solving this problem. ...

February 20 2025 · 2 min · Raunak