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

Home > Just Math
More ones (Posted on 2015-10-21) Difficulty: 3 of 5
Find the total count of numbers from 1 (base ten) to 20150 (base ten) which have at least one 0 and more 1s than 0s when written in base 4.

See The Solution Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution Comment 1 of 1
DefDbl A-Z
Dim crlf$


Private Sub Form_Load()
 Form1.Visible = True
 
 Text1.Text = ""
 crlf = Chr$(13) + Chr$(10)

 For n = 1 To 20150
   b4$ = base$(n, 4)
   ct1 = 0: ct0 = 0
   For i = 1 To Len(b4)
     Select Case Mid(b4, i, 1)
       Case 1: ct1 = ct1 + 1
       Case 0: ct0 = ct0 + 1
     End Select
   Next
   If ct1 > ct0 And ct0 > 0 Then goodct = goodct + 1
   If ct1 > ct0 And ct0 = 0 Then suppct = suppct + 1
 Next n
 


 Text1.Text = Text1.Text & goodct & Str(suppct) & crlf & " done"
  
End Sub

Function base$(n, b)
  v$ = ""
  n2 = n
  Do
    d = n2 Mod b
    n2 = n2 \ b
    v$ = LTrim(Str(d)) + v$
  Loop Until n2 = 0
  base$ = v$
End Function

finds that 5997 numbers meet the criterion.

An additional 3025 would meet it if numbers with no zeros were allowed also.

  Posted by Charlie on 2015-10-21 15:27:42
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 (20)
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