Essentially the same program:
-:&(/:~ @: (-.&' '))
Henry Rich
On 8/7/2018 12:24 PM, Daniel Lyons wrote:
The following APL question on Stack Overflow piqued my curiosity:
https://stackoverflow.com/questions/51730263/length-error-while-creating-a-dfn-function-in-apl-to-check-for-anagrams
<https://stackoverflow.com/questions/51730263/length-error-while-creating-a-dfn-function-in-apl-to-check-for-anagrams>
Essentially, the user is looking for a dyad `anagram` which gives 1 for words
that are anagrams of each other, ignoring spaces, i.e.:
'ALBERT EINSTEIN' anagram 'TEN ELITE BRAINS'
1
'ALBERT EINSTEIN' anagram 'NOT ELITE BRAINS'
0
'ALBART EINSTEIN' anagram 'TEN ELITE BRAINS'
0
My solution:
hash =: [: /:~ ] #~ ' ' ~: ]
anagram =: *./ @: =&hash
I’d appreciate feedback if I’m missing an obvious way to increase the clarity
of this. I’m also wondering if the “anagram index” builtin A. can be used to
solve this problem somehow; it isn’t obvious to me that it can.
Thanks!
---
This email has been checked for viruses by AVG.
https://www.avg.com
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm