Using stdlib noun "Alpha_j_" and verb "tolower":
str=. 'Dr. K. E. Iverson'
Alpha_j_
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
str-.alpha_j_
'Dr. K. E. Iverson' -. alpha_j_
str-.Alpha_j_
. . .
str-.str-.Alpha_j_
DrKEIverson
tolower str-.str-.Alpha_j_
drkeiverson
So,
standardizeStr=: Alpha_j_&([: tolower ] -. -.~)
and
isAnagramOf=: ([: /:~ [: standardizeStr ]) -: [: /:~ [: standardizeStr [
'Dr. K. E. Iverson' isAnagramOf 'Knives Or Red'
1
'city sojourners up wry keg' isAnagramOf 'New York City J Users Group'
1
On Mon, Jun 8, 2015 at 9:33 AM, Roger Hui <[email protected]> wrote:
> Strings x and y are anagrams if x -:&(/:~)&(-.&'. ')&tolower y . That is,
> compare them after reducing them to a standard form, by (converting to
> lower case, then deleting spaces and dots (and whatever), then sorting
> them).
>
>
>
>
>
>
> On Mon, Jun 8, 2015 at 6:27 AM, Gian Medri <[email protected]> wrote:
>
> > Is there a shorter or better method of finding
> > if 2 strings are an anagram in one line code?
> >
> > Write an idiom that takes two character vectors as its left and right
> > arguments and returns 1 if they are anagrams of each other. An anagram
> > of a string uses all of the letters
> >
> > of the string ignoring word spacing, capitalisation, and dot.
> >
> >
> >
> > anagram=: 13 : '(/:~(B,a.) {~ (A,a.) i.~~ (-.&'' .'')y)-:
> > /:~(B=.((97+i.26){a.),a.) {~ (A=.((65+i.26){a.),a.) i.~~ (-.&''
> > .'')x'
> >
> >
> >
> >
> >
> > 'Dr. K. E. Iverson' anagram 'Knives Or Red'
> >
> > 1
> >
> >
> > Gian Medri
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
--
Devon McCormick, CFA
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm