Jul 14 2026
Write a function that takes an uppercase word consisting of English letters and counts how many leading consonants it has. For the purposes of this problem, use 'AEIOU' as your list of vowels (non-consonants).
{+/β§\1-β¨βΏ'AEIOU'β.=β΅}
We build a table of vowel occurrences and do a logical OR along the columns to get an array of vowel occurrences (0 for consonants and 1 for vowels). Then we NOT the array and use +/β§\ to count how many leading 1s it has.
Write a function that takes an uppercase word consisting of English letters and returns the first vowel followed by the first consonant. The word is guaranteed to contain at least one vowel and one consonant.
{β΅[1 0β³β¨β¨βΏ'AEIOU'β.=β΅]}
As before β¨βΏ'AEIOU'β.=β΅ generates an array of vowel occurrences. Call the βresult v. vβ³1 0 gives us the indices of the first vowel and first consonant, and we pick those indices from β΅.
{β’ βͺ β\ β΅}
{+/ β β\ β΅}
Compute the max-scan, then ask how many unique elements there are.
Another nice idea is to compare pairs of adjacent numbers in the max-scan and add up the points of difference. We'll need add 1 to get the right answer, and also special-case the empty array case.
{β¬β‘β΅: 0 β 1+ +/ 2</ β\ β΅}
This is more efficient because there's no hashing involved. We're making use of the structure of the max-scan (strictly increasing). We can use cmpx to profile these implementations.
The fractional part is the remainder modulo 1, and we can subtract that from the input to get the integral part.
{(β΅-rem),remβ1|β΅}
We can use β to compute the integral part, and then subtract that from the input to get the fractional part.
{β , β΅-ββ΅}
We can rewrite the right argument to , as a 3-train β’-β and then go one step further and turn the entire thing into a 5-train.
β , β’ - β
Combining with the previous idea:
β , 1β|
Or just use the encode function:
0 1ββ€This uses the idiom βΊβ¨Β¨β΅ which creates an array in the "shape" of β΅, with each element being βΊ. The actual shape of the result will be different if βΊ is itself an array.
{{βΊ ('*'β¨Β¨β΅)} βΈ , +/Β¨ β³β΅}
For example, try
(2 4 β΄ β³ 8) β¨Β¨ β³ 3
To avoid the problem of generating high-rank matrices (which caps us at inputs of length 15 or less), we can use encode:
{{βΊ ('*'β¨Β¨β΅)}βΈ+βΏ1+(,β΅)β€Β―1+β³Γ/β΅}
Notice how we have to use ,β΅ instead of β΅ as the left arugment to β€ (encode). This handles the case of when β΅ is a scalar.