All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Simultaneous Base Baffle (Posted on 2014-09-17)
Determine the smallest value of a positive integer N such that N is a palindrome in both base 3 and base 10. What is the next smallest value of N having this property?

*** N must have more than one digit in any base. So, trivial solutions like (4)base 10 or, (8)base 10 are not permissible.

 No Solution Yet Submitted by K Sengupta Rating: 4.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
 computer solution -- the good the bad and the ugly | Comment 3 of 6 |
DefDbl A-Z
Dim crlf\$

ChDir "C:Program Files (x86)DevStudioVBprojectsflooble"
Text1.Text = ""
crlf\$ = Chr(13) + Chr(10)
Form1.Visible = True
DoEvents

For i = 1 To 1000000
s\$ = LTrim(Str\$(i))
If isPalin(s\$) Then
s\$ = base\$(i, 3)
If isPalin(s\$) Then
Text1.Text = Text1.Text & i & "    " & s\$ & crlf
End If
End If
Next

Text1.Text = Text1.Text & crlf & " done"
End Sub

Function base\$(n, b)
v\$ = ""
n2 = n
Do
d = n2 Mod b
n2 = n2 b
v\$ = Mid("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", d + 1, 1) + v\$
Loop Until n2 = 0
base\$ = v\$
End Function

Function isPalin(s\$)
good = 1

For i = 1 To Len(s\$) / 2
If Mid\$(s\$, i, 1) <> Mid\$(s\$, Len(s\$) + 1 - i, 1) Then good = 0: Exit For
Next
isPalin = good
End Function

finds

first the completely trivial (the bad):

1    1
2    2

then the semi-trivial (the ugly):

4    11
8    22

and then the expected answer and beyond (the good):

dec      base-3
121    11111
151    12121
212    21212
242    22222
484    122221
656    220022
757    1001001
29092    1110220111
48884    2111001112
74647    10210101201
75457    10211111201
76267    10212121201
92929    11201110211
93739    11202120211
848848    1121010101211

 Posted by Charlie on 2014-09-17 15:42:06

 Search: Search body:
Forums (1)