3 ms·
This is the TXR Lisp interactive listener of TXR 285. Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet. TXR's sound system features 120 d
by kazinator 4y ago
This is the TXR Lisp interactive listener of TXR 285.
Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
TXR's sound system features 120 dB separation between quarreling audiophiles.
1> (flow "/usr/share/dict/words"
file-get-lines
(group-by sort)
hash-values
(keep-if cdr)
(sort @1 : [chain car len]))
(("ho" "oh") ("am" "ma") ("em" "me") ("no" "on") ("ah" "ha") ("it" "ti")
("mu" "um") ("eh" "he") ("ate" "eat" "eta" "tea") ("bar" "bra")
[...]
("certification" "rectification") ("accouterments" "accoutrements")
("peripatetic's" "precipitate's") ("amphitheaters" "amphitheatres")
("colonialist's" "oscillation's") ("enumeration's" "mountaineer's")
("imperfections" "perfectionism") ("antiparticles" "paternalistic")
("broadcaster's" "rebroadcast's") ("impressiveness" "permissiveness")
("conservation's" "conversation's") ("tablespoonfuls" "tablespoonsful")
("certifications" "rectifications") ("amphitheater's" "amphitheatre's")
("certification's" "rectification's") ("impressiveness's" "permissiveness's"))
- pavlov 4y agoWaiting for someone to post a 4-symbol APL version (which makes use of a language feature added by an eccentric hedge fund millionaire in 2002 and removed in 2017, to ensure nobody ever runs it).
- zirkonit 4y agoAccording to GPT-4, an equivalent APL one-liner is: (⊢⌷⍨∘⍋∘≢¨)↑1<≢¨⊢⌸(⍋⊢)¨⎕NGET'/usr/share/dict/words'1
- pavlov 4y agoAI-assisted APL could totally be a thing. Why shouldn’t my programs be intense neutron stars of weird symbols, if there’s a superhuman intelligence always at hand to explain and improve the code?
- kazinator 4y agoAssembly language generation by symbolic AI (compilers) has been here for 60 years. The "prompts" are very precise and predictably behaved, but requiring the users to learn a specialized language. (Most such languages tend to be concerned with the "how" rather than "what".) With the new AI, you just specify the "how". Then you get a buggy program, in one of the above specialized languages for the old AI, and the rest of the prompts in the chat are edit instructions on how the AI should fix the code to make it work.
- jodrellblank 4y agoThat doesn't work in Dyalog APL, comes back with RANK ERROR. It's idiomatic to pick ⊃ the first result of ⎕NGET to get just the lines to work on, and not the other things like file encoding. Then grade-up-right-train-each (⍋⊢)¨ is redunant, it's the same as grade-up-each ⍋¨ The grade is an array of which indices to take to put the argument in sorted order and I don't think it makes sense to group ⌸ by that since the grade isn't the same for different arrangements of letters, so the whole approach breaks down there. I think the words have to be sorted, e.g to pick out 'bat' and 'tab' as the same letters: {⍺, ≢⍵}⌸{⍵[⍋⍵]}¨words ← 'bat' 'dog' 'tab' 'cow' 'wok' abt 2 dgo 1 ... Then 1<≢¨ would be "1 is less than the count (tally) of each" which fits somewhere in the solution, but not there and won't work on my array. We don't need to know the actual sorted letters so we can inline the bitmask of which answers matter or not in the first column: {(1<≢⍵),⍵}⌸{⍵[⍋⍵]}¨words ← 'bat' 'dog' 'tab' 'cow' 'woka' ┌→────┐ ↓1 1 3│ │0 2 0│ │0 4 0│ │0 5 0│ └~────┘ Any with a 1 in the first column are anagrams, and 0 in the first column are not. And the other columns are indices into the wordlist where the matching words are, so words[1,3] picks out 'bat' and 'tab' and it's probably possible to filter rows with 1 in the first column: {⍵[;1]⌿⍵}{(1<≢⍵),⍵}⌸{⍵[⍋⍵]}¨words←'bat' 'dog' 'tab' 'cow' 'bta' 'racecar' 'carrace' and then drop the first column: 1↓[2]{⍵[;1]⌿⍵}{(1<≢⍵),⍵}⌸{⍵[⍋⍵]}¨words Then uhh filter out the zeros to avoid index error, and index into the word list, so: {words[⍵/⍨⍵>0]}¨⊂[2]1↓[2]{⍵[;1]⌿⍵}{(1<≢⍵),⍵}⌸{⍵[⍋⍵]}¨words←⊃⎕NGET 'wordlist.txt' 1 ┌→─────────────────────────────────────────────────── │ ┌→────────────┐ ┌→────────────────┐ ┌→────────────┐ │ │ ┌→──┐ ┌→──┐ │ │ ┌→────┐ ┌→────┐ │ │ ┌→──┐ ┌→──┐ │ │ │ │aah│ │aha│ │ │ │aahed│ │ahead│ │ │ │aal│ │ala│ │ [...] │ │ └───┘ └───┘ │ │ └─────┘ └─────┘ │ │ └───┘ └───┘ │ │ └∊────────────┘ └∊────────────────┘ └∊────────────┘ └∊─────────────────────────────────────────────────── It can probably be done shorter and cleaner with more skill than I have. It's a lot quicker to execute than the PowerShell version I commented, but took a lot longer to code.
- rak1507 4y ago(⊢⊢⍤/⍨1<≢¨)({⍵[⍋⍵]}¨⊢∘⊂⌸⊢)words or something like that maybe
- 4y ago
- abecedarius 4y agoCan you explain that last line (sort @1 : [chain car len])?
- kazinator 4y agoYes. @1 indicates where the first argument of the implicit function is inserted. (It's like _ in some partial application syntaxes, but more general because there can be multiple implicit arguments.) The previous steps produced a list of word lists, so we indicate that this giant list, which is the implicit first argument of this function of the pipeline, is going into the first argument position of sort. The : symbol causes argument 2 of sort to be defaulted, as if it were omitted. That's the comparison function, which defaults to less. In TXR Lisp, you can explicitly default optional arguments with : which enables you to give arguments to later optional arguments to the right of those. We then specify argument 3, the function for selecting the key to sort by for each element. Each element is a list of words (anagrams fo equal length). We pick the first one with car, and take its length: chain will compose those functions for us. We use square brackets because the function names are in the function namespace: square brackets provide a function application language in which variables and functions are in one namespace.
- abecedarius 4y agoThanks! It's interesting to see some ideas from other Lisp dialects. Maybe I'll learn a bit more TXR.
- jodrellblank 4y agoPowerShell 7: PS C:\> get-content wordlist.txt | group { -join ([char[]]$_ | sort) } | where count -ge 2 | sort {$_.Name.Length} Count Name Group ----- ---- ----- 2 ho {ho, oh} 2 do {do, od} 2 ay {ay, ya} [...] 2 aeghhiiloooppssty {pathophysiologies, physiopathologies} 2 aacghhiilloooppsty {pathophysiological, physiopathological} 2 aceghhiimooopprrst {microphotographies, photomicrographies}