mersenneforum.org  

Go Back   mersenneforum.org > Fun Stuff > Puzzles

Reply
 
Thread Tools
Old 2006-04-11, 16:49   #1
mfgoode
Bronze Medalist
 
mfgoode's Avatar
 
Jan 2004
Mumbai,India

80416 Posts
Cool one to a billion

: ":smile
Once a bright young lady called Lillian,
Summed the numbers from one to a billion,
But it gave her the fidgets
To add up the digits;
If you can help her, she'll thank you a million."
Mally
mfgoode is offline   Reply With Quote
Old 2006-04-11, 17:25   #2
Greenbank
 
Greenbank's Avatar
 
Jul 2005

2·193 Posts
Default

5E17 or 5E23?
Greenbank is offline   Reply With Quote
Old 2006-04-11, 17:51   #3
Jamiaz
 
Jamiaz's Avatar
 
Sep 2005
Detroit, MI

23 Posts
Default

Easy one. Just have to use the formula for adding 1-n :)

500,000,000,500,000,000 or ~5^17

Last fiddled with by Jamiaz on 2006-04-11 at 17:51
Jamiaz is offline   Reply With Quote
Old 2006-04-11, 19:53   #4
axn
 
axn's Avatar
 
Jun 2003

123668 Posts
Default

Is the question about sum of 1..n OR sum of _digits_ of 1..n ?!
axn is online now   Reply With Quote
Old 2006-04-11, 19:57   #5
Xyzzy
 
Xyzzy's Avatar
 
Aug 2002

11·769 Posts
Default

$ cat a.pl

#!/usr/bin/perl -w
use strict;
my $sum;
for my $x ( 1 .. 1_000_000_000 ) {
$sum += $x;
}
print "$sum\n";

$ ./a.pl

500000000500000000
Xyzzy is offline   Reply With Quote
Old 2006-04-11, 20:03   #6
xilman
Bamboozled!
 
xilman's Avatar
 
"๐’‰บ๐’ŒŒ๐’‡ท๐’†ท๐’€ญ"
May 2003
Down not across

23×5×283 Posts
Default

Quote:
Originally Posted by Xyzzy
$ cat a.pl

#!/usr/bin/perl -w
use strict;
my $sum;
for my $x ( 1 .. 1_000_000_000 ) {
$sum += $x;
}
print "$sum\n";

$ ./a.pl

500000000500000000
That is a truly disgusting piece of code!



Paul
xilman is online now   Reply With Quote
Old 2006-04-11, 23:03   #7
Greenbank
 
Greenbank's Avatar
 
Jul 2005

2·193 Posts
Default

Indeed, in any reasonable language[1] that would produce possibly random/incorrect answers.

bash# cat a.c
#include <stdio.h>
#include <stdint.h>

int main(void) {
uint64_t sum; /* you think this is equal to 0? */
printf( "%llu\n", sum );
return(0);
}
bash# gcc a.c -o a
bash# ./a
18807377184
bash# gcc -O2 a.c -o a
bash# ./a
6994688905387704324

Anyway, my original answers were wrong (yeah, yeah) but why did I give two (wrong) answers to this question?

[1] I'm joking. I love perl, but I've programmed in C for too long to let uninitialised variables pass me by (and it even had 'use strict' in there!).

P.S. axn1, you raise a good point.

Last fiddled with by Greenbank on 2006-04-11 at 23:09
Greenbank is offline   Reply With Quote
Old 2006-04-11, 23:55   #8
sdbardwick
 
sdbardwick's Avatar
 
Aug 2002
North San Diego County

23×7×13 Posts
Default

Quote:
Originally Posted by Greenbank
Anyway, my original answers were wrong (yeah, yeah) but why did I give two (wrong) answers to this question?
Because the term billion is ambiguous; 10^12 or 10^9?
sdbardwick is offline   Reply With Quote
Old 2006-04-12, 08:45   #9
mfgoode
Bronze Medalist
 
mfgoode's Avatar
 
Jan 2004
Mumbai,India

40048 Posts
Smile Sum of digits

Quote:
Originally Posted by axn1
Is the question about sum of 1..n OR sum of _digits_ of 1..n ?!

You are on the right track axn1.

The poem is ,as it is, self explanatory. It is the sum of all the digits thats required.

Take a billion as having 9 zeros

None of the answers given so far are correct.
Mally
mfgoode is offline   Reply With Quote
Old 2006-04-12, 09:26   #10
Kees
 
Kees's Avatar
 
Dec 2005

19610 Posts
Default do not forget the last one

Leaving alone 1.000.000.000 which adds 1 to the final sum (see subject title) we
are summing all 9 digit numbers, not beginning with 0. Fixing a position (say the last one) we can have 0,1,2,3,4,5,6,7,8 or 9 on it and for every number in this choice we have 9*10^7 possible 9-digit numbers.
Summing over the last 8 positions gives 8*9*10^7*45.
If we fix the first digit, we have 10^8 possible 9-digit numbers, giving 10^8*45.
Adding these two numbers and adding 1 should give the required result:

36900000001
Kees is offline   Reply With Quote
Old 2006-04-12, 12:33   #11
axn
 
axn's Avatar
 
Jun 2003

2·2,683 Posts
Default


000 000 000
000 000 001
...........
999 999 998
999 999 999

1 billion numbers * 9 digits per number = 9 billion digits.

Number of occurrences of any one digit = 9 billion / 10 = 900 million

Sum = 900 million * Sum(0..9) = 45 * 900 million = 40.5 billion

And adding 1 (for 1 billion), we get "40.5 billion and 1"

Last fiddled with by axn on 2006-04-12 at 12:34
axn is online now   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ten Billion Digits Mersenne Numbers aketilander Operation Billion Digits 14 2021-02-27 07:14
Operation: Billion Digits clowns789 Operation Billion Digits 574 2017-09-12 01:34
question range 1 billion to 2 billion? Unregistered Information & Answers 7 2010-08-12 06:25
Billion digit prime? lfm Operation Billion Digits 6 2009-01-07 01:17
Lucas test for billion bit prime MESCALINE1968 Lone Mersenne Hunters 2 2005-06-06 22:06

All times are UTC. The time now is 12:45.


Fri May 27 12:45:52 UTC 2022 up 43 days, 10:47, 1 user, load averages: 2.05, 1.81, 1.77

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.

โ‰  ยฑ โˆ“ รท ร— ยท โˆ’ โˆš โ€ฐ โŠ— โŠ• โŠ– โŠ˜ โŠ™ โ‰ค โ‰ฅ โ‰ฆ โ‰ง โ‰จ โ‰ฉ โ‰บ โ‰ป โ‰ผ โ‰ฝ โŠ โŠ โŠ‘ โŠ’ ยฒ ยณ ยฐ
โˆ  โˆŸ ยฐ โ‰… ~ โ€– โŸ‚ โซ›
โ‰ก โ‰œ โ‰ˆ โˆ โˆž โ‰ช โ‰ซ โŒŠโŒ‹ โŒˆโŒ‰ โˆ˜ โˆ โˆ โˆ‘ โˆง โˆจ โˆฉ โˆช โจ€ โŠ• โŠ— ๐–• ๐–– ๐–— โŠฒ โŠณ
โˆ… โˆ– โˆ โ†ฆ โ†ฃ โˆฉ โˆช โŠ† โŠ‚ โŠ„ โŠŠ โŠ‡ โŠƒ โŠ… โŠ‹ โŠ– โˆˆ โˆ‰ โˆ‹ โˆŒ โ„• โ„ค โ„š โ„ โ„‚ โ„ต โ„ถ โ„ท โ„ธ ๐“Ÿ
ยฌ โˆจ โˆง โŠ• โ†’ โ† โ‡’ โ‡ โ‡” โˆ€ โˆƒ โˆ„ โˆด โˆต โŠค โŠฅ โŠข โŠจ โซค โŠฃ โ€ฆ โ‹ฏ โ‹ฎ โ‹ฐ โ‹ฑ
โˆซ โˆฌ โˆญ โˆฎ โˆฏ โˆฐ โˆ‡ โˆ† ฮด โˆ‚ โ„ฑ โ„’ โ„“
๐›ข๐›ผ ๐›ฃ๐›ฝ ๐›ค๐›พ ๐›ฅ๐›ฟ ๐›ฆ๐œ€๐œ– ๐›ง๐œ ๐›จ๐œ‚ ๐›ฉ๐œƒ๐œ— ๐›ช๐œ„ ๐›ซ๐œ… ๐›ฌ๐œ† ๐›ญ๐œ‡ ๐›ฎ๐œˆ ๐›ฏ๐œ‰ ๐›ฐ๐œŠ ๐›ฑ๐œ‹ ๐›ฒ๐œŒ ๐›ด๐œŽ๐œ ๐›ต๐œ ๐›ถ๐œ ๐›ท๐œ™๐œ‘ ๐›ธ๐œ’ ๐›น๐œ“ ๐›บ๐œ”