[Jprogramming] detecting string anagrams

Henry Rich henryhrich at gmail.com
Tue Aug 7 16:29:43 UTC 2018


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



More information about the Programming mailing list