Stefan Ram <ram@zedat.fu-berlin.de> wrote:
+---------------
| Recently a question was posed in TV about the number of "5"
| characters occuring within all integral decimal numerals
| between 0 and 100.
|
| Frank Buss suggested the following source code to
| calculate the result in Lisp:
...
| I wrote this in Perl:
+---------------
Actually, I don't like *any* of the (many) solutions presented! ;-}
This is a problem you should be doing in your head! QUICK! What's
the answer for 0-9? One, of course. And the answer for 0-99? One
for each decade, plus 10 for the 50's, or 20 [as many responded].
What about 0-999? 300. 0-9999? 4000. And 0-99999? 50000, duh!
Got the pattern yet...? ;-}
There's some ancient aphorism about this, something about *thinking*
first, before haring off to write code. But, hey, Gauss got in a lot
of trouble for thinking [Google for "Gauss sum class"], so I suppose
nobody does that any more.
This one is only slightly harder: Among the printed representations
of integers from 0 to (expt 10 n), how many contain *at least one* "5"?
Hint: ((1 . 1) (2 . 19) (3 . 271) ... )
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607