Created
January 19, 2024 03:21
-
-
Save justin2004/e4ea60ca0e3c8a9cf77ecec25b4a6eef to your computer and use it in GitHub Desktop.
`sort -n` in APL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# `sort -n` will treat as many leading characters as digits as it can and it will do a numeric sort with whatever it was | |
# able to treat as a number | |
# | |
# e.g. | |
$ echo -e '123 file.txt\n65 exit.c\n465 words.rtf' | |
123 file.txt | |
65 exit.c | |
465 words.rtf | |
$ echo -e '123 file.txt\n65 exit.c\n465 words.rtf' | sort -n | |
65 exit.c | |
123 file.txt | |
465 words.rtf | |
# here is an attempt to do something similar in Dyalog APL | |
######################### | |
(⊂⍋m)⌷m←↑'0' '1' '2' '3' '4' '5' '6' '7' '8' '9'∘{leadingNumber←⍵/⍨mask←∧\⍺∊⍨⍵ ⋄ (⍎leadingNumber) (⍵/⍨~mask)}¨'123 file.txt' '65 exit.c' '465 words.rtf' | |
┌───┬──────────┐ | |
│65 │ exit.c │ | |
├───┼──────────┤ | |
│123│ file.txt │ | |
├───┼──────────┤ | |
│465│ words.rtf│ | |
└───┴──────────┘ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment