Re: Ponder This: the wormeaten page
by hv (Prior) on Dec 17, 2004 at 13:58 UTC

This can also be solved by arithmetic quite readily.
The sum of the digits 1 .. 9 is 45.
Each digit appears 1000 times in each of the units, 10s, 100s and 1000s places.
The units always count as themselves: total 1000 * 45.
The tens are followed by a zero 1/10 of the time: total (100 + 900 * 10) * 45.
The hundreds are directly followed by a zero 1/10 of the time, and followed by a nonzero digit then a zero 1/10 of the remaining: total (100 + 90 * 10 + 810 * 100) * 45.
Similarly for the thousands: total (100 + 90 * 10 + 81 * 100 + 729 * 1000) * 45.
So the sum is (1300 + 1080 * 10 + 891 * 100 + 729 * 1000) * 45 = 830200 * 45 = 37,359,000
This approach can readily be adapted to base b, and beyond to the eat digits 0 .. x1 required for part 2 of the puzzle.
Hugo
 [reply] 
Re: Ponder This: the wormeaten page
by Anonymous Monk on Dec 17, 2004 at 10:59 UTC

perl le '$_ = "@{[1 .. 9999]}"; s/[ 0]+/+/g; print eval'

 [reply] [d/l] 

perl le 'print eval join'+',map{split/0+/}1..9999'
 [reply] [d/l] 

But I suppose this is cheating: perl le 'map$\+=$_,map/[^0]+/g,1..9999;print'
 [reply] [d/l] 

perl le '$_=join 0,1..9999;y/0/+/s;print eval'

 [reply] [d/l] 

 [reply] [d/l] 


 [reply] 
Re: Ponder This: the wormeaten page
by BrowserUk (Patriarch) on Dec 16, 2004 at 23:16 UTC

Cute. Though it would be a tad more efficient, (and w complient)if it were /0+/
"But you should never overestimate the ingenuity of the sceptics to come up with a counterargument." Myles Allen
"Think for yourself!"  Abigail
"Time is a poor substitute for thought"theorbtwo
"Efficiency is intelligent laziness." David Dunham
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side."  tachyon
 [reply] [d/l] 

 [reply] 
Re: Ponder This: the wormeaten page
by zentara (Cardinal) on Dec 17, 2004 at 12:17 UTC

perlverted :) I learned a new word today.
I'm not really a human, but I play one on earth.
flash japh
 [reply] 
Re: Ponder This: the wormeaten page
by Anonymous Monk on Jan 26, 2005 at 12:48 UTC

Of course you take a lateral approach and say that the "wormeaten paper" is the missing part and therefore the sumof the zeros would of course be zero?  [reply] 

But if you do that, you have to consider that the zeros on the page may form a pattern that looks like a number. Now you have to go over the many possible dimentions of the page and check them all! Thankfully, you have a head start, since you can use this OCR code; all you have to account for now is rotation.
 [reply] 