at least he tried
-
as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :
if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
{
return true;
}
else
{
return false;
}when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?
me, myself and my blog - loadx.org ericos g.
-
as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :
if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
{
return true;
}
else
{
return false;
}when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?
me, myself and my blog - loadx.org ericos g.
-
as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :
if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
{
return true;
}
else
{
return false;
}when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?
me, myself and my blog - loadx.org ericos g.
And, in addition to being very limited in the range of input values, the result isn't correct, either. <SmartassMode> 1 is not a prime number, by definition. </SmartassMode> ;P
Regards, mav -- Black holes are the places where God divided by 0...
-
wikipedia stops at 113 too :) http://en.wikipedia.org/wiki/Prime_number[^]
well then. and i felt sorry for him having to find them on his own. well observed!
me, myself and my blog - loadx.org ericos g.
-
And, in addition to being very limited in the range of input values, the result isn't correct, either. <SmartassMode> 1 is not a prime number, by definition. </SmartassMode> ;P
Regards, mav -- Black holes are the places where God divided by 0...
True, but that did not worry me. ;P
me, myself and my blog - loadx.org ericos g.
-
as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :
if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
{
return true;
}
else
{
return false;
}when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?
me, myself and my blog - loadx.org ericos g.
-
as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :
if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
{
return true;
}
else
{
return false;
}when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?
me, myself and my blog - loadx.org ericos g.
Ask him to write a function that returns weather or not a given number is even :D
-
as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :
if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
{
return true;
}
else
{
return false;
}when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?
me, myself and my blog - loadx.org ericos g.
How about a function that returns whether a number is an integer?
Chris Meech I am Canadian. [heard in a local bar]
-
Ask him to write a function that returns weather or not a given number is even :D
Well funny you should mention that, since it was asked previously. Amazingly enough, most knew the *hidden* patterns of even numbers. Or they heard me say modulus, between all the words that sent them to sleep. :-)
me, myself and my blog - loadx.org ericos g.
-
How about a function that returns whether a number is an integer?
Chris Meech I am Canadian. [heard in a local bar]
I guess if we follow the "Law of Wikipedia"[^], that would simply be -3,-2,-1,0,1,2,3.
me, myself and my blog - loadx.org ericos g.
-
as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :
if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
{
return true;
}
else
{
return false;
}when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?
me, myself and my blog - loadx.org ericos g.
-
as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :
if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
{
return true;
}
else
{
return false;
}when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?
me, myself and my blog - loadx.org ericos g.
Waaaay back in college, in my first Pascal class, we were assigned the task of writing a program to perform the "Sieve of Eratosthenes"... but the assignment quoted a formula to use... which was faulty (of course). I don't know what the other students did, but I headed to the library. If I ever teach (and I'd like to) I would assign the problem with extra credit to whomever builds the largest sieve. Wouldn't this be a good Friday programming quiz?
-
Waaaay back in college, in my first Pascal class, we were assigned the task of writing a program to perform the "Sieve of Eratosthenes"... but the assignment quoted a formula to use... which was faulty (of course). I don't know what the other students did, but I headed to the library. If I ever teach (and I'd like to) I would assign the problem with extra credit to whomever builds the largest sieve. Wouldn't this be a good Friday programming quiz?
PIEBALDconsult wrote:
Wouldn't this be a good Friday programming quiz?
I miss those. :sigh: I leave my office a bit early on Friday evenings and don't get to see the Friday quizzes because they're posted later in the day. (I don't have a computer at home.)
Cheers, Vıkram.
After all is said and done, much is said and little is done.
-
Nah, since for most of their test data it returned good results.
me, myself and my blog - loadx.org ericos g.
-
as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :
if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
{
return true;
}
else
{
return false;
}when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?
me, myself and my blog - loadx.org ericos g.
He does not need any computer to find prime numbers :-D
Regards, Sylvester G sylvester_g_m@yahoo.com
-
as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :
if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
{
return true;
}
else
{
return false;
}when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?
me, myself and my blog - loadx.org ericos g.
You are right, this is awful. Better is:
int Primes[]={2,3,5,7,...,113};
int size=sizeof(Primes[])/sizeof(Primes[0]);
int i=0;
while (i<size)
{
if (num==Primes[i]) return true;
}
return false;Last modified: 21hrs 3mins after originally posted --
Constantly "Saving the day" should be taken as a sign of organizational dysfunction rather than individual skill - Ryan Roberts[^]
-
as an assignment, i asked for a program that we've all been through, a function that returns weather or not a given number is prime. in one case, i was given the following :
if(num== 1 || num== 2 || num== 3 || num== 5 || num== 7 || num== 11 || num== 13 || num== 17 || num== 19 || num== 23 || num== 29 || num== 31 || num== 37 || num== 41 || num== 43 || num== 47 || num== 53 || num== 59 || num== 61 || num== 67 || num== 71 || num== 73 || num== 79 || num== 83 || num== 89 || num== 97 || num== 101 || num== 103 || num== 107 || num== 109 || num== 113)
{
return true;
}
else
{
return false;
}when i asked him why he stopped at 113 (since it was the only thing i thought of asking) he said, in a tired voice, "I couldn't think of any more numbers" do you, or do you not feel sorry for him?
me, myself and my blog - loadx.org ericos g.
Beh, any real programmer would write it like this:
int primes[] = {2,3,5,...133};
const int* end = primes + sizeof(primes)/sizeof(int);
return (std::find(primes, end, num) != end);
-
You are right, this is awful. Better is:
int Primes[]={2,3,5,7,...,113};
int size=sizeof(Primes[])/sizeof(Primes[0]);
int i=0;
while (i<size)
{
if (num==Primes[i]) return true;
}
return false;Last modified: 21hrs 3mins after originally posted --
Constantly "Saving the day" should be taken as a sign of organizational dysfunction rather than individual skill - Ryan Roberts[^]
I dunno, maybe a
switch
statement. -
You are right, this is awful. Better is:
int Primes[]={2,3,5,7,...,113};
int size=sizeof(Primes[])/sizeof(Primes[0]);
int i=0;
while (i<size)
{
if (num==Primes[i]) return true;
}
return false;Last modified: 21hrs 3mins after originally posted --
Constantly "Saving the day" should be taken as a sign of organizational dysfunction rather than individual skill - Ryan Roberts[^]
Don't you just love infinate loops?:)
-
Beh, any real programmer would write it like this:
int primes[] = {2,3,5,...133};
const int* end = primes + sizeof(primes)/sizeof(int);
return (std::find(primes, end, num) != end);
And any real engineer would build something like this: :D
bool IsPrime(int i)
{
if (i<2)
return false;
if (i == 2)
return true;
if (i%2 == 1)
// All odd numbers are prime:
// 3 ... prime
// 5 ... prime
// 7 ... prime
// 9 ... measuring fault
// 11... prime
// 13... prime
// and so on...
return true;
else
return false;
}Regards, mav -- Black holes are the places where God divided by 0...