Reversal

Author

Eric W. Weisstein
August 25, 2015

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

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

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

Code

Reversal[n_Integer,b_:10]:=FromDigits[Reverse[IntegerDigits[n,b]],b]
PalindromicQ[n_]:=Module[{l=IntegerDigits[n]},l===Reverse[l]]

Multiples of their Reversals

V10.2

Select[Range[10^6],!PalindromicQ[#]&&Mod[Reversal[#],#]==0&]//Timing

Select[Range[10^6],Mod[#,10]≠0&&!PalindromicQ[#]&&Mod[#,Reversal[#]]==0&]//Timing

V10.3

ReversalMultipleQ[n_]:=Block[{r=IntegerReverse[n]},r=!=n&&Mod[r,n]==0]

Select[Range[10^6],ReversalMultipleQ]//Timing

Select[Transpose[{Range[10^6],IntegerReverse/@Range[10^6]}],#[[1]]=!=#[[2]]&&Mod[#[[2]],#[[1]]]==0&][[All,1]]//Timing

Product Equals Reversal of (Product of Reversals)

{Times@@#,Reversal[Times@@(Reversal/@#)]}&[{312,221}]

{Times@@#,Reversal[Times@@(Reversal/@#)]}&[{213,122}]

n R(n) is Square

Select[Range[10^4],Mod[#,10]≠0&&!PalindromicQ[#]&&IntegerQ[Sqrt[# Reversal[#]]]&]

n R(n) is a non-square power

Non10s[n_]:=Flatten[Outer[10#1+#2&,Range[0,10^(n-1)-1],Range[9]]]

(10^5)

Select[Range[10^5],Mod[#,10]≠0&&!PalindromicQ[#]&&GCD@@Last/@FactorInteger[# Reversal[#]]>2&]//Timing

Select[Range[10^5],Mod[#,10]≠0&&GCD@@Last/@FactorInteger[# Reversal[#]]>2&&!PalindromicQ[#]&]//Timing

Select[Non10s[5],GCD@@Last/@FactorInteger[# Reversal[#]]>2&&!PalindromicQ[#]&]//Timing

(10^6)

Select[Range[10^6],Mod[#,10]≠0&&!PalindromicQ[#]&&GCD@@Last/@FactorInteger[# Reversal[#]]>2&]//Timing

(10^7)

Select[Non10s[7],GCD@@Last/@FactorInteger[# Reversal[#]]>2&&!PalindromicQ[#]&]//Timing

Product of Digit Sum and its Reversal