Jump to content
BrainDen.com - Brain Teasers
  • 0


Guest
 Share

Question

Here is this smart kid who wrote a computer program (in C) "to print all the even numbers till 500" in 10 minutes. How long will it take to have him write the program "to print all even numbers till 10,000"? B))

Pls answer in terms of minutes.

Link to comment
Share on other sites

20 answers to this question

Recommended Posts

  • 0

If it took 10 min. to write the first program, why would it be any different to write the other program in 10 min.? All you need to do is switch the 500 to 10,000....so 10 min.?

-or-

If it took 10 min for the program to compute the 250 even numbers within 500...then it would probably take 20 times as long for 10,000...so 200 min.

Link to comment
Share on other sites

  • 0
Here is this smart kid who wrote a computer program (in C) "to print all the even numbers till 500" in 10 minutes. How long will it take to have him write the program "to print all even numbers till 10,000"? B))

Pls answer in terms of minutes.

By the way, if the kid takes 10 minutes to write a program to "to print all the even numbers till 500", he's not a smart kid, as you claimed.

Link to comment
Share on other sites

  • 0
By the way, if the kid takes 10 minutes to write a program to "to print all the even numbers till 500", he's not a smart kid, as you claimed.

Well.. you have to forgive him bushindo, since he is a "kid", not a pro! :P

Link to comment
Share on other sites

  • 0
By the way, if the kid takes 10 minutes to write a program to "to print all the even numbers till 500", he's not a smart kid, as you claimed.

Depends on the definition of kid...if it is a five year old, yeah, I would be impressed that he could write a program in C that printed out every even number (even if it were 250 printf statements); and I would probably call that kid smart....

As an aside, the "smart" answer is zero time when expressed in minutes...either a constant should be changed or the stopping point should be an input.

B))

Link to comment
Share on other sites

  • 0

It will take him 0 minutes because the program is already written. He obtains the number to output even numbers "till" from the user using a printf and scanf. So the first user input 500, but if I input 10,000 then the program will output the even number to 10,000.

Also the question is ambiguous, does the program output the string "to print all the even numbers till 500" as the quotes imply and it took him ten minutes to write it, or does it output the string in 10 minutes from now, i.e. at 12:01 MST if I started the program right now. Or in ten minutes from when I run the program does the program output the even numbers 0 - 498 as we expect.

Or perhaps 5:00 is in ten minutes and the program will stop running then, if this is the case, not sure what 10,000 would represent.

Anyone who deals with a computer programmer should know that the slightest hint of ambiguity is unacceptable and invalidates the process. And in any event the intelligence level of the child is subjective and therefore irrelevant. You may as well ask if a programmer writes a program to compute X in Y minutes how long to compute Z. The answer is the same.

Link to comment
Share on other sites

  • 0
Depends on the definition of kid...if it is a five year old, yeah, I would be impressed that he could write a program in C that printed out every even number (even if it were 250 printf statements); and I would probably call that kid smart....

As an aside, the "smart" answer is zero time when expressed in minutes...either a constant should be changed or the stopping point should be an input.

B))

I'd be even more impressed if his definition of Kid pertained to goats.

Link to comment
Share on other sites

  • 0

Hahahaha, I can't believe I was so stupid... Damn!! :(

If it took 10 minutes to write that program, it will take the same amount of time to write the other program, cause the difference is only in those few numbers...

I can't believe how stupid I was. I even started counting!...

Link to comment
Share on other sites

  • 0

Yeah, it shouldn't take much longer to add 2 extra 0's, so maybe 10 minutes, .5 seconds.

If we took it that the program took 10 minutes to print out the numbers 2-500, then to print out the numbers 2-10000 would be an increasing number.

For the numbers 2-500, there are 697 individual characters. If it took this kid's dot matrix printer 10 minutes to print out 697 numbers, then each number took approximately 1.1616 seconds each number.

Between 2-10000, there are 19,449 characters. At 1.1616 seconds per character average, this would take approximately 376 minutes, or 6 hours and 16 minutes.

Link to comment
Share on other sites

  • 0

0.25 mins. If he is smart and he has a program to print the numbers from 0 500. All he'll have to do is alter the program to go from 0 10000, which is really easy.

Link to comment
Share on other sites

  • 0
By the way, if the kid takes 10 minutes to write a program to "to print all the even numbers till 500", he's not a smart kid, as you claimed.

I've actually used C, and if you just typed in"to print all even numbers till 500" it would not do so. you would have to tell it how to do so, which for me, would take a lot longer than ten minutes.

Link to comment
Share on other sites

  • 0
0.25 mins. If he is smart and he has a program to print the numbers from 0 500. All he'll have to do is alter the program to go from 0 10000, which is really easy.

If you ever used C, you'd know that you can't just say print numbers 1-500, you'd have to say print numbers 1,2,3,4,5,6,7,8,9,10,ect.

Link to comment
Share on other sites

  • 0
Here is this smart kid who wrote a computer program (in C) "to print all the even numbers till 500" in 10 minutes. How long will it take to have him write the program "to print all even numbers till 10,000"? B))

Pls answer in terms of minutes.

did you mean it would print it out in ten minutes or that he wrote it in ten minutes?

it would take 200 minutes if that's how long he wrote it rather than how long it prints out.

Link to comment
Share on other sites

  • 0
did you mean it would print it out in ten minutes or that he wrote it in ten minutes?

it would take 200 minutes if that's how long he wrote it rather than how long it prints out.

Well! 2 Clarifications to benefit all --

1. The word "print" in the question meant "output" or "display". It didnt mean that output has to be send to a printer and print it.

2. The program was built using the algorithm, not plain "printf" statements.

Peace!

Edited by Terminator
Link to comment
Share on other sites

  • 0
I've actually used C, and if you just typed in"to print all even numbers till 500" it would not do so. you would have to tell it how to do so, which for me, would take a lot longer than ten minutes.

Hi txmom2,

The cool kids these days write these kinda programs in like 2-3 minutes :D

Link to comment
Share on other sites

  • 0

ok, well I agree with all of the posts that say it should be trivial to print out the even numbers to any number...and I also agree that 10 minutes is a LONG time to write that program...here it is in Java (took about 20 seconds to write, literally...this assumes you will pass in the value upon execution...):


for (int i = 0; i <= Integer.parseInt(args[0]); i++) {
if (i % 2 == 0) {
System.out.println(i);
}
}
}
public static void main(final String[] args) {

So, I believe it would be something like this in C (been while since I've done C...):


for (int i = 0; i <= atoi(argv[0]); i++) {
if (i % 2 == 0) {
printf("%d\n", i);
}
}
return 0;
}
int main(int argc, char *argv[]) {

You could also replace the Integer.parseInt(args[0]) and atoi(argv[0]) with a constant value (500 or 10000 in this case), and in order to change the upper bound, simply change that value...that's it...So, I say that it will take him 0 minutes to write the second program, since if he did the first one correctly, he will not have to do any more writing for the second.

I will also note that this doesn't do any error handling or checking to make sure the user isn't stupid...adding those checks in adds about 1 more minute of programming (to wrap stuff in try-catch blocks and gracefully exit...so, that's about it)...

Edited by Pickett
Link to comment
Share on other sites

  • 0
If you ever used C, you'd know that you can't just say print numbers 1-500, you'd have to say print numbers 1,2,3,4,5,6,7,8,9,10,ect.

The following prints all even numbers between 0 and 500 inclusive. Took me about 30 seconds to write, mainly because it took me about 10 seconds to correct from using C++ for loop variant.

#include <stdio.h>

const int stop = 500;

int main()

{

   int i;

   for (i = 0; i <= stop; i += 2)

		printf("%d\n", i);

   return 0;

}
The following prints all even numbers between 0 and 10000 inclusive. It took me 5 seconds to cut and paste and replace the 500 with 10000.
#include <stdio.h>

const int stop = 10000;

int main()

{

   int i;

   for (i = 0; i <= stop; i += 2)

		printf("%d\n", i);

   return 0;

}

Now, granted, I'm not a kid...and also do this for a living...and that code is not suitable for "real life" (i'd have an input method for getting and validating the stop point and use that as a parameter to a function)..... but we have no basis for what is meant by "smart kid". Did the "smart kid" do that above (i.e. figure out loops and branches...)? how old is said kid? (I was doing this stuff in about 8-9 grade...and i am what they called a "smart kid"...for basis of my own comparison...)

If the smart kid did the above, my answer is, it should have taken less than ten seconds to modify the code to print out even numbers from 0 to 100000 from 0 through 500. If the "smart kid" is smart enough to use branch statements and conditionals, s/he should know about constants ....

Link to comment
Share on other sites

  • 0
Hi txmom2,

The cool kids these days write these kinda programs in like 2-3 minutes :D

I would like to disagree. The kids at SAGE never figured out how to make the robot go through the obstacle course. We had 4 hours, and we only got to the third cup before the robot decided that it was a girl that needed to go to the bathroom(funny story actually). Well then again, we're not concidered cool kids, but the kids who are don't know what C is.

Edited by txmom2
Link to comment
Share on other sites

  • 0

The following prints all even numbers between 0 and 500 inclusive. Took me about 30 seconds to write, mainly because it took me about 10 seconds to correct from using C++ for loop variant.

#include <stdio.h>

const int stop = 500;

int main()

{

   int i;

   for (i = 0; i <= stop; i += 2)

		printf("%d\n", i);

   return 0;

}
The following prints all even numbers between 0 and 10000 inclusive. It took me 5 seconds to cut and paste and replace the 500 with 10000.
#include <stdio.h>

const int stop = 10000;

int main()

{

   int i;

   for (i = 0; i <= stop; i += 2)

		printf("%d\n", i);

   return 0;

}

Now, granted, I'm not a kid...and also do this for a living...and that code is not suitable for "real life" (i'd have an input method for getting and validating the stop point and use that as a parameter to a function)..... but we have no basis for what is meant by "smart kid". Did the "smart kid" do that above (i.e. figure out loops and branches...)? how old is said kid? (I was doing this stuff in about 8-9 grade...and i am what they called a "smart kid"...for basis of my own comparison...)

If the smart kid did the above, my answer is, it should have taken less than ten seconds to modify the code to print out even numbers from 0 to 100000 from 0 through 500. If the "smart kid" is smart enough to use branch statements and conditionals, s/he should know about constants ....

Well I actually never used C to do that, I used it to guide robots, and I asumed the C for computers might be the same.

I had the same question. In SAGE 5-7 grade was learning C, but if it took that long then, how long would a younger kid take???

Link to comment
Share on other sites

  • 0

The solution will be -- 10 or 11 minutes, since the kid already hv the algorithm and program ready, and what he needs is just change the parameters or variables to display the desired output.

Congrats to all the winners!!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...