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

Home > Numbers
Worm ate the numbers (Posted on 2019-01-18) Difficulty: 3 of 5
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.)
Solution 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
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 (22)
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