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?
DefDbl AZ
Dim crlf$
Private Sub Form_Load()
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 20150326 15:21:20 