RosettaCodeData/Task/Collections/Uiua/collections.uiua

21 lines
1.1 KiB
Text
Raw Permalink Normal View History

2026-04-30 12:34:36 -04:00
# Arrays are at the heart of Uiua, so lots to see here.
⇡6 # Range -> [0 1 2 3 4 5]
⇌ # Reverse -> [5 4 3 2 1 0]
⊂123 # Join -> [123 5 4 3 2 1 0]
˜⊂99 # Backjoin -> [123 5 4 3 2 1 0 99]
≡(+2) # Operate on every element -> [125 7 6 5 4 3 2 101]
-2 # Many operations are 'pervasive' i.e. act on every element at once.
# Destructive operations.
# ⟜(&p[⊃(..|..|...)]) means 'perform all ops on same data, collect results as array, print, restore original data'.
⟜(&p[⊃(⧻|⊢|⊣|⊡1|⊡¯2)]) # Access: len, first, last, second, second-from-end. Print -> [8 123 99 5 0]
⟜(&p[⊃(/+|/×|/↧|/↥)]) # Reduce: sum, product, min, max. Print -> [237 0 0 123]
⟜(&p[⊃(˜∊99|˜⨂99)]) # Membership, location. Print -> [1 7] (1 = true)
# Grouping
⟜(&p⊕□⊸◿2) # Group by odd/even -> [[4 2 0] [123 5 3 1 99]]
&p⊜□⊸>₂ # Partition(split) wherever element is <2 -> [123 5 4 3│99]
# So... split on space, get length of each word, find max, get that word.
°□⊡˜⨂⊸/↥⊸≡◇⧻⊜□⊸≠@\s "This is the longest word"