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

 Worm ate the numbers (Posted on 2019-01-18)
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?

 No Solution Yet Submitted by Danish Ahmed Khan No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
 computer solution Comment 2 of 2 |
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

 Search: Search body:
Forums (4)