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

Home > Just Math
Simultaneous Base Baffle (Posted on 2014-09-17) Difficulty: 3 of 5
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.

See The Solution Submitted by K Sengupta    
Rating: 4.5000 (2 votes)

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


Private Sub Form_Load()
 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
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (16)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information