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

 Neighboring tickets (Posted on 2015-03-26)
A continuous bus tickets' tape consists of one million tickets numbered from 000000 to 999999.
All tickets are white, except those in which the sum of digits in the even positions equals the sum of digits in the odd positions: those are blue.

What is the largest distance (in numbers) between 2 consecutive blue tickets?

 No Solution Yet Submitted by Ady TZIDON No Rating

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

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

prev = 0
For n = 0 To 999999
n1 = n: odd = 0: even = 0
While n1 > 0
d = n1 Mod 10
p = (p + 1) Mod 2
n1 = n1 \ 10
If p Then odd = odd + d Else even = even + d
Wend
If odd = even Then
dist = n - prev
If dist >= maxd Then
maxd = dist: max1 = prev: max2 = n
Text1.Text = Text1.Text & maxd & Str(max1) & Str(max2) & crlf
End If
prev = n
End If
Next

Text1.Text = Text1.Text & crlf & crlf

End Sub

finds two instances of the maximum, which is 990:

990 90090 91080
990 908919 909909

where the span in each case is followed by the two ticket numbers in question.

 Posted by Charlie on 2015-03-26 15:21:20

 Search: Search body:
Forums (0)