Digit

Author

Eric W. Weisstein
April 2, 2006

This notebook downloaded from http://mathworld.wolfram.com/notebooks/Numbers/Digit.nb.

For more information, see Eric's MathWorld entry http://mathworld.wolfram.com/Digit.html.

©2006 Wolfram Research, Inc. except for portions noted otherwise

Distinct Digits

Select[Range[100],UnsameQ@@IntegerDigits[#]&]

Length[l=Select[Range[10^6],UnsameQ@@IntegerDigits[#]&]]//Timing

Length[l=Select[Range[10^7],UnsameQ@@IntegerDigits[#]&]]//Timing

Length[l=Select[Range[10^8],UnsameQ@@IntegerDigits[#]&]]//Timing

Table[Count[l,_?(#≤10^n&)],{n,8}]

Length[l=Select[Range[1,9],UnsameQ@@IntegerDigits[#]&]]//Timing

Length[l=Select[Range[10,99],UnsameQ@@IntegerDigits[#]&]]//Timing

Length[l=Select[Range[100,999],UnsameQ@@IntegerDigits[#]&]]//Timing

10 9 8-9 8

Length[l=Select[Range[1000,9999],UnsameQ@@IntegerDigits[#]&]]//Timing

10 9 8 7-9 8 7

Product[i,{i,n,9}]

Simplify[((9 9!)/((10-n)!))]

Table[((9 9!)/((10-n)!)),{n,10}]

Table[9 Product[k,{k,9,11-n,-1}],{n,10}]

9Table[Pochhammer[10-n,n],{n,0,9}]

Rest[FoldList[Plus,0,%]]

Sum[Pochhammer[10-n,n],{n,0,k}]

...wrong...

9Sum[Pochhammer[10-n,n],{n,0,9}]

Sum of Inverse

Total[1`20/l]

Grid Code

xservecluster = {"xserve1", "xserve2", "xserve3", "xserve4", "xserve5", "xserve6", "xserve7", "xserve8"};
Needs[ "Parallel`"];
$AvailableMachines=Join[#,#]&@xservecluster;
LaunchSlaves[];
t=AbsoluteTime[];
sum=With[{min=1, max=9876543210, chunksize = 10^7/2},
  ParallelSum[
     Total[1/Select[Range[k, Min[k + chunksize - 1, max]],
      UnsameQ @@ IntegerDigits[#]&]],
    {k, min, max, chunksize}
  ]
];
Print[(AbsoluteTime[]-t)Second];
Print[N[sum,100]];
Put[sum,"DistinctDigits.out"];
CloseSlaves[];

In[8]:= 26382.639822 Second
In[9]:= 8.929948174755443424171179403981525048667286767255408480936913993018768120557239657437064181411273952

StringLength[string=StringReplace[Import["DistinctDigits.out","String"],{"\n"->"","\\"->""}]]//Timing

StringLength/@(strings=StringSplit[string,"/"])//Timing

With[{dig=25},
((StringTake[strings[[1]],dig]<>"..."<>StringTake[strings[[1]],-dig])/(StringTake[strings[[2]],dig]<>"..."<>StringTake[strings[[2]],-dig]))
]

exprs=ToExpression/@strings;//Timing

Divide@@(N/@exprs)//Timing

Divide@@(N[#,100]&/@exprs)//Timing

r=Divide@@exprs;//Timing

N[r]//Timing

N[r,100]//Timing

DecimalLength[n_]:=Module[{i=IntegerExponent[n,#]&/@{2,5}},
If[n==Times@@Power@@@Transpose[{{2,5},i}],Max[i],0]
]

DecimalLength[Denominator[r]]//Timing

DecimalPeriod[r]//Timing

...ran overnight...

Count of Number of Digits

Digits[n_,b_:10]:=Floor[Log[b,n]]+1

Table[{n,Digits[n]},{n,20}]

Table[{n,Plus@@DigitCount[n]},{n,20}]

Digits Increasing/Decreasing

Counts

Table[Plus@@Length/@Table[DigitsIncreasing[n,b],{n,b}],{b,10}]

Table[Plus@@Length/@Table[DigitsDecreasing[n,b],{n,b}],{b,10}]

Base-2

Select[Range[1000],DigitsSortedQ[#,2,Order->Increasing]&]

Select[Range[1000],DigitsSortedQ[#,2,Order->Nondecreasing]&]

Select[Range[500],DigitsSortedQ[#,2,Order->Nonincreasing]&]

Select[Range[1000],DigitsSortedQ[#,2,Order->Decreasing]&]

Base-10

Select[Range[100],DigitsSortedQ[#,10,Order->Increasing]&]

Select[Range[100],DigitsSortedQ[#,10,Order->Nondecreasing]&]

Select[Range[500],DigitsSortedQ[#,10,Order->Nonincreasing]&]

Select[Range[500],DigitsSortedQ[#,10,Order->Decreasing]&]

Base-16

Select[Range[100],DigitsSortedQ[#,16,Order->Increasing]&]

Select[Range[100],DigitsSortedQ[#,16,Order->Nondecreasing]&]

Select[Range[500],DigitsSortedQ[#,16,Order->Nonincreasing]&]

Select[Range[500],DigitsSortedQ[#,16,Order->Decreasing]&]