Permutations, Anagrams, Rotations (was: More digital silliness)
zak seidov
zakseidov at yahoo.com
Fri Jan 11 03:37:05 CET 2008
Mathematica code for calculating
permutations, anagrams and rotations of 10-base
integer n:
id[n_]:=IntegerDigits[n]
ndd[n_]:=Length[id[n]]
permutations[n_]:=FromDigits/@Permutations[id[n]]
anagrams[n_]:=Select[perms[n],ndd[#]\[Equal]ndd[n]&]
rotations[n_]:=Select[FromDigits/@NestList[RotateRight[#]&,id[n],ndd[n]-1],ndd[#]\[Equal]ndd[n]&]
For David's number:
permutations[25600]
Out[48]=
{25600,25060,25006,26500,26050,26005,20560,20506,20650,20605,20056,20065,52600,52060,52006,56200,56020,56002,50260,50206,50620,50602,50026,50062,62500,62050,62005,65200,65020,65002,60250,60205,60520,60502,60025,60052,2560,2506,2650,2605,2056,2065,5260,5206,5620,5602,5026,5062,6250,6205,6520,6502,6025,6052,256,265,526,562,625,652}
In[49]:=
anagrams[25600]
Out[49]=
{25600,25060,25006,26500,26050,26005,20560,20506,20650,20605,20056,20065,52600,52060,52006,56200,56020,56002,50260,50206,50620,50602,50026,50062,62500,62050,62005,65200,65020,65002,60250,60205,60520,60502,60025,60052}
In[50]:=
rotations[25600]
Out[50]=
{25600,60025,56002}
Number of rotations <= number of anagrams <= number
of permutations.
Number of anagrams = number of permutations for
zero-less integers, e.g., 23513.
Number of rotations = number of anagrams for one
digit integers (0..9), and
for zero-less two-digit integers (13, 47 etc.).
zak
--- "David W. Wilson" <wilson.d at anseri.com> wrote:
> I like to distinguish between 'permutation' and
> 'anagram'.
>
> For a word w in language L, a string s is a
> permutation of w if s and w have
> the same number of each symbol they contain. A
> string s is an anagram of w
> if it additionally belongs to w.
>
> For example, if L is the English language, then the
> word 'stop' has
> permutations 'ospt', 'sopt', 'spot', 'post', 'spto',
> etc. Of these
> permutations, only 'spot' and 'post' are anagrams,
> since they are in L.
> Think about it. In the game of anagrams, you could
> not play 'ospt' as an
> anagram of 'spot', since 'ospt' is not a word.
>
> Similarly, let L be the language of standard base-10
> representations of
> positive integers. Then L consists of the strings of
> 1 or more decimal
> digits not starting in 0. In this language, 25600
> has the permutations
> 20605, 06502, and 60025, but of these 06502 is not
> an anagram, since it is
> not a standard base-10 integer representation,
> because it starts with 0.
>
>
>
>
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
More information about the SeqFan
mailing list