Steffi Problem

Author

Eric W. Weisstein
February 17, 2003

This notebook downloaded from http://mathworld.wolfram.com/notebooks/IntegerSequences/SteffiProblem.nb.

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

Code

Steffi[b_:10,k_]:=Module[
{
perms=FromDigits[#,b]&/@Permutations[Range[k]],
matches,
p,
solns,
max=Floor[Divide@@(FromDigits[#,b]&/@{Reverse[#],#}&[Range[k]])]
},
matches=Function[n,Select[n/Range[2,max],IntegerQ[#]&&Sort[IntegerDigits[#,b]]==Range[k]&]]/@perms;
p=Flatten[Position[matches,_?(#≠{}&)]];
solns=Transpose[{perms[[#]]&/@p,matches[[p]]}];
Join@@Flatten[Outer[List,{#1},#2]&@@@solns,1]
]/;k<b

SteffiCounts[b_:10,k_]:=Module[
{
perms=FromDigits[#,b]&/@Permutations[Range[k]],
matches,
p,
solns,
max=Floor[Divide@@(FromDigits[#,b]&/@{Reverse[#],#}&[Range[k]])]
},
matches=Function[n,Select[n/Range[2,max],IntegerQ[#]&&Sort[IntegerDigits[#,b]]==Range[k]&]]/@perms;
Plus@@(Length/@matches[[Flatten[Position[matches,_?(#≠{}&)]]]])
]/;k<b

FancySteffi[b_,k_]:=Map[BaseForm[#,b]&,Steffi[b,k],{2}]

Solutions[b_,k_]:=(Divide@@#==Divide@@First/@#)&/@FancySteffi[b,k]

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

Steffi's Original Problem

Maximum Ratio

N[7654321/1234567]

Not Divisible by 3, 9

Sum[k,{k,7}]

Mod[28,#]&/@{3,9}

Not Divisible by 5

((......5)/(......1))

(7643215/2345671)

(7643215/2345671)//N

Not Divisible by 2

Table[Mod[n,2],{n,7}]

(((Subscript[e, 2])....(Subscript[e, 1]))/(((Subscript[e, 2])/2).....((Subscript[e, 1])/2)))

Counts

Print[Timing[table=Table[SteffiCounts[b,k],{b,3,10},{k,2,b-1}];]];
table//TableForm

Print[Timing[table=Table[Length[Steffi[b,k]],{b,3,11},{k,2,b-1}];]];
table//TableForm

Print[Timing[table=Table[SteffiCounts[b,k],{b,3,12},{k,2,b-1}];]];
table//TableForm

Table[SteffiCounts[12,n],{n,2,9}]//Timing

Table[SteffiCounts[12,n],{n,2,10}]//Timing

SteffiCounts[12,11]//Timing

Solutions

Base 4

Solutions[4,3]

Base 5

Solutions[5,4]

Base 6

Solutions[6,4]

Solutions[6,5]

Base 7

Solutions[7,5]

Solutions[7,6]

Base 7

Solutions[8,6]