The numbers 1 to 9999 (decimal base) were written on a paper. Then the paper was partially eaten by worms. It happened that just those parts of paper with digit "0" were eaten. Consequently the numbers 1200 and 3450 appear as 12 and 345 respectively, whilst the number 6078 appears as two separate numbers 6 and 78. What is the sum of the numbers appearing on the worm-eaten paper?
The answer is 37359000, compared with the 49995000 before the worm started to eat.
For i = 1 To 9999
n$ = LTrim(Str(i))
If Right(n, 1) = "0" Then n = Left(n, Len(n) - 1)
ix = InStr(n, "0")
tot2 = tot2 + i
If ix = 0 Then
tot = tot + Val(n)
Else
n1 = Val(Left(n, ix - 1))
n2 = Val(Mid(n, ix + 1))
tot = tot + n1 + n2
End If
DoEvents
Next
Text1.Text = Text1.Text & tot & Str(tot2)
|
Posted by Charlie
on 2019-01-19 13:36:45 |