Comment On F'd Factorial

When we look to hire a recent college graduate, there’s not a whole lot we can expect. Source Control, Defect Tracking, Best Practices –all concepts not a part of any computer science curriculum I’ve ever seen, but essential in any business environment. All we can hope for is a good personality match, a strong potential for learning, and at a very minimum, some retention of the concepts taught in computer science courses. [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5 | Page 6Next »

Re: F'd Factorial

2007-06-27 09:09 • by Welbog
More functions should disregard input values and just return 12. It would make life easier.

Re: F'd Factorial

2007-06-27 09:10 • by Kardi (unregistered)
No way is this even possible; but then again I guess anything is possible at WTF University.

I just can't fathom how someone can't know the terminoligy; if you don't have the skills ... make sure you can BS with the best of them. Oh, what as that 'n' doing??

http://www.FireJayPa.com

Re: F'd Factorial

2007-06-27 09:13 • by Justin (unregistered)
No No, it's not twelve. 'i' gets modified in the loop. So, we have a function that returns the answer to life, the universe, and everything.

Re: F'd Factorial

2007-06-27 09:18 • by Foobar (unregistered)
142818 in reply to 142816
Justin:
No No, it's not twelve. 'i' gets modified in the loop. So, we have a function that returns the answer to life, the universe, and everything.
Perfect. That's all everybody needs. I would hire him!

Re: F'd Factorial

2007-06-27 09:18 • by Cyrus
142819 in reply to 142816
Justin:
No No, it's not twelve. 'i' gets modified in the loop. So, we have a function that returns the answer to life, the universe, and everything.



Likely the submission was altered slightly to make it do just that, but it's pretty awesome nonetheless.

Sadly, when I got out of college no one really expected much from me even though the college I went to stressed things like team work and not breaking the build. :P

Re: F'd Factorial

2007-06-27 09:19 • by pitchingchris
Doesn't use the input parameter and doesn't reuse the variable a, except to hold the number. Course, we all were dumb at one point, but at least we know what recursion was when we graduated.

Re: F'd Factorial

2007-06-27 09:20 • by KattMan
142821 in reply to 142816
Justin:
No No, it's not twelve. 'i' gets modified in the loop. So, we have a function that returns the answer to life, the universe, and everything.



Yes we know it is modified in the loop. That's why it is twelve and not 10.

Re: F'd Factorial

2007-06-27 09:21 • by Anon (unregistered)
142822 in reply to 142816
Justin:
No No, it's not twelve. 'i' gets modified in the loop. So, we have a function that returns the answer to life, the universe, and everything.



Yes it is twelve.
First loop i = 1. i = 1 * 2 = 2, then the i is incremented to 3.
Next loop i = 2. i = 3 * 4 = 12, 12 is > 10 so the loop ends.
QED

Re: F'd Factorial

2007-06-27 09:21 • by Anon (unregistered)
142823 in reply to 142822
Anon:
Justin:
No No, it's not twelve. 'i' gets modified in the loop. So, we have a function that returns the answer to life, the universe, and everything.



Yes it is twelve.
First loop i = 1. i = 1 * 2 = 2, then the i is incremented to 3.
Next loop i = 2. i = 3 * 4 = 12, 12 is > 10 so the loop ends.
QED


Whoops, that should be i = 3 on the second line

Re: F'd Factorial

2007-06-27 09:26 • by Welbog
Graduates who don't know what recursion is are less common than forum users who don't know how C-style for loops work, I guess.

Re: F'd Factorial

2007-06-27 09:26 • by KevB
This is shocking. I just recently graduated, and I am shocked at that code, I especially love his manipulation of 'i' in the loop and not using the all important 'n' what so ever ..amazing!

Re: F'd Factorial

2007-06-27 09:27 • by bstorer
142826 in reply to 142813
Welbog:
More functions should disregard input values and just return 12. It would make life easier.


Are you saying that n! != 12 for all n?

Re: F'd Factorial

2007-06-27 09:28 • by Joseph (unregistered)
142827 in reply to 142825
I just find it amazing that people who code like that can actually graduate!

Re: F'd Factorial

2007-06-27 09:29 • by Welbog
142828 in reply to 142826
bstorer:
Welbog:
More functions should disregard input values and just return 12. It would make life easier.
Are you saying that n! != 12 for all n?
In fact I'm saying n! != 12 for any n! (That last ! is for emphasis.)

Re: F'd Factorial

2007-06-27 09:31 • by OhNoesTheyBeStealingOurFactorials (unregistered)
I used to interview candidates at my previous job. Often asked this question. Have to say this candidate is in the top 50 percent... :)

Re: F'd Factorial

2007-06-27 09:32 • by Protiuz (unregistered)
My former boss asked a person he was interviewing what the definition of a 'class' was in reference to c++... They responded with "A class is what I attended at school to learn about c++". The didn't get hired...

Re: F'd Factorial

2007-06-27 09:32 • by Welbog
142831 in reply to 142829
OhNoesTheyBeStealingOurFactorials:
I used to interview candidates at my previous job. Often asked this question. Have to say this candidate is in the top 50 percent... :)
I think I speak for all of us when I ask you to provide examples of bad factorial implementations from interviews.

Re: F'd Factorial

2007-06-27 09:35 • by KattMan
142832 in reply to 142820
pitchingchris:
Doesn't use the input parameter and doesn't reuse the variable a, except to hold the number. Course, we all were dumb at one point, but at least we know what recursion was when we graduated.


I never regurgitated from college, hell I never went, and even I know what recursion is.

Re: F'd Factorial

2007-06-27 09:36 • by bstorer
142833 in reply to 142827
Joseph:
I just find it amazing that people who code like that can actually graduate!

Don't be. In my senior level software engineering class, we worked on a program that had been developed by, I believe, the two previous semesters. I rewrote so much of the code it was mind-boggling. There were 3 separate functions to convert a MFC CString into a char*: one worked properly, but was still slower than the built-in methods, one had an off-by-one error, and one didn't always allocate enough space, so you could do buffer overruns with it.
I was blown away at the time, because these people had all presumably graduated and found jobs. This site will never run out of content.

Re: F'd Factorial

2007-06-27 09:43 • by bstorer
142835 in reply to 142828
Welbog:
bstorer:
Welbog:
More functions should disregard input values and just return 12. It would make life easier.
Are you saying that n! != 12 for all n?
In fact I'm saying n! != 12 for any n! (That last ! is for emphasis.)


Ha! Shows what you know:
3! = 12 (base 4)
4! = 12 (base 22)
5! = 12 (base 118)

On a related note, does anyone want to solve for z in G(z) = 12 where G is the Gamma function? Because that's like a factorial.

Re: F'd Factorial

2007-06-27 09:44 • by mkb
142836 in reply to 142833
bstorer:
Joseph:
I just find it amazing that people who code like that can actually graduate!

Don't be. In my senior level software engineering class, we worked on a program that had been developed by, I believe, the two previous semesters. I rewrote so much of the code it was mind-boggling. There were 3 separate functions to convert a MFC CString into a char*: one worked properly, but was still slower than the built-in methods, one had an off-by-one error, and one didn't always allocate enough space, so you could do buffer overruns with it.
I was blown away at the time, because these people had all presumably graduated and found jobs. This site will never run out of content.


Dear god, why do people insist on reinventing the wheel? We REJECT candidates who use their own sort algorithms in their homework assignment.

Re: F'd Factorial

2007-06-27 09:45 • by Welbog
142837 in reply to 142835
bstorer:
Welbog:
bstorer:
Welbog:
More functions should disregard input values and just return 12. It would make life easier.
Are you saying that n! != 12 for all n?
In fact I'm saying n! != 12 for any n! (That last ! is for emphasis.)
Ha! Shows what you know:
3! = 12 (base 4)
4! = 12 (base 22)
5! = 12 (base 118)

On a related note, does anyone want to solve for z in G(z) = 12 where G is the Gamma function? Because that's like a factorial.
Using other bases is cheating. I'm telling!

Re: F'd Factorial

2007-06-27 09:46 • by Krenn
142838 in reply to 142833
bstorer:
I was blown away at the time, because these people had all presumably graduated and found jobs. This site will never run out of content.


Oh, of course they found jobs. Jobs where you ask "Do you want fries with that?" and give the customer exactly 12 fries, no matter how big a serving they wanted.

Re: F'd Factorial

2007-06-27 09:50 • by bstorer
142839 in reply to 142837
Welbog:
bstorer:
Welbog:
bstorer:
Welbog:
More functions should disregard input values and just return 12. It would make life easier.
Are you saying that n! != 12 for all n?
In fact I'm saying n! != 12 for any n! (That last ! is for emphasis.)
Ha! Shows what you know:
3! = 12 (base 4)
4! = 12 (base 22)
5! = 12 (base 118)

On a related note, does anyone want to solve for z in G(z) = 12 where G is the Gamma function? Because that's like a factorial.
Using other bases is cheating. I'm telling!


And 2! = 12 (base... uh, 0?)

Re: F'd Factorial

2007-06-27 09:51 • by Noamsml (unregistered)
142840 in reply to 142832
KattMan:
pitchingchris:
Doesn't use the input parameter and doesn't reuse the variable a, except to hold the number. Course, we all were dumb at one point, but at least we know what recursion was when we graduated.


I never regurgitated from college, hell I never went, and even I know what recursion is.


Same here. I'm a f'ing high school student and even I know what recursion is.

Oh, and by the way:



int factorial(int n)
{
if (n=0) return 1;
else return n * factorial n;

//if the universe has gone insane, return 42 (cannot be a factorial)
return 42;
}

Re: F'd Factorial

2007-06-27 09:51 • by ElQuberto (unregistered)
He could have made it interesting by throwing in a "+i* (i % 2 == 0 ? -1 : 1)" or something.

Re: F'd Factorial

2007-06-27 09:52 • by ElQuberto (unregistered)
He could have made it interesting by throwing in a "+i* (i % 2 == 0 ? -1 : 1)" or something.

Re: F'd Factorial

2007-06-27 09:53 • by Cochrane (unregistered)
I pity the guy who wrote that. He spend possibly several years of his life, trying to learn something that would keep him fed throughout the rest of his life, but he didn't learn anything. He is completely useless now. That's a very depressing thought.

Re: F'd Factorial

2007-06-27 09:54 • by Not a computer science graduate (unregistered)
Written in a minute or two by myself, with no reference to anything:

function factorial( $a )

{
if ( $a <= 1 )
return( $a );

return ( $a * factorial( $a - 1 ) );
}


Recursion! Factorials! Rubbish, but actually works! Doesn't return twelve!

Unfortunately, I didn't study computer science at university - in fact, I have no computing qualifications whatsoever. Sorry.

Re: F'd Factorial

2007-06-27 09:55 • by bstorer
142845 in reply to 142843
Cochrane:
I pity the guy who wrote that. He spend possibly several years of his life, trying to learn something that would keep him fed throughout the rest of his life, but he didn't learn anything. He is completely useless now. That's a very depressing thought.

Not if you're competing against him for a job...

Re: F'd Factorial

2007-06-27 09:57 • by Kardi (unregistered)
142846 in reply to 142843
Cochrane:
I pity the guy who wrote that. He spend possibly several years of his life, trying to learn something that would keep him fed throughout the rest of his life, but he didn't learn anything. He is completely useless now. That's a very depressing thought.


I pitty the university and future people that apply for jobs out of said school. He is clearly a reflection of the program and how anyone can pass.

Colleges are allowing too many students to move forward these days and there are far too few courses that weed out the weak. Infact, a Comp Sci 101 course should have been enough to address this

Re: F'd Factorial

2007-06-27 10:02 • by Will (unregistered)
142848 in reply to 142844
Not a computer science graduate:
Written in a minute or two by myself, with no reference to anything:

function factorial( $a )

{
if ( $a <= 1 )
return( $a );

return ( $a * factorial( $a - 1 ) );
}


Recursion! Factorials! Rubbish, but actually works! Doesn't return twelve!

Unfortunately, I didn't study computer science at university - in fact, I have no computing qualifications whatsoever. Sorry.



Isn't factorial(0) defined as 1?

Captcha: muhahaha!

Re: F'd Factorial

2007-06-27 10:04 • by UncleMidriff
142849 in reply to 142846
I dunno if I agree that this guy is a reflection of how bad the school from which he graduated is.

I had plenty of difficult computer science classes in college, and I was just a computer science minor. Several people in several of my classes either failed or withdrew from the class half-way through because they just weren't getting it. Still, though those classes were good at weeding out the morons, a few exceptionally skilled slackers managed to make it through to their senior year. I got stuck with them on group projects. They were useless, lazy, and they didn't seem to know crap. How they managed to pass their previous classes was and still is beyond me.

Re: F'd Factorial

2007-06-27 10:05 • by tlf (unregistered)
142850 in reply to 142840
Noamsml:


Same here. I'm a f'ing high school student and even I know what recursion is.

Oh, and by the way:



int factorial(int n)
{
if (n=0) return 1;
else return n * factorial n;

//if the universe has gone insane, return 42 (cannot be a factorial)
return 42;
}



Nice code.
Will never return though...

Captcha: alarm - what this code raised internally (in me)

Re: F'd Factorial

2007-06-27 10:06 • by Andorbal (unregistered)
Some CS programs are really MIS programs in disguise. Don't be fooled!

Re: F'd Factorial

2007-06-27 10:07 • by gsmalleus
142852 in reply to 142840
Noamsml:
KattMan:
pitchingchris:
Doesn't use the input parameter and doesn't reuse the variable a, except to hold the number. Course, we all were dumb at one point, but at least we know what recursion was when we graduated.


I never regurgitated from college, hell I never went, and even I know what recursion is.


Same here. I'm a f'ing high school student and even I know what recursion is.

Oh, and by the way:



int factorial(int n)
{
if (n=0) return 1;
else return n * factorial n;

//if the universe has gone insane, return 42 (cannot be a factorial)
return 42;
}



But evidently you haven't gotten to the part about infinite loops yet.

else return n * factorial n-1;

Re: F'd Factorial

2007-06-27 10:08 • by Fj_ (unregistered)
142853 in reply to 142822
LOL WTF?

It actually returns 13, because 12 is incremented one last time before the comparison.

Re: F'd Factorial

2007-06-27 10:11 • by FalconNL (unregistered)
142854 in reply to 142840
Noamsml:

Same here. I'm a f'ing high school student and even I know what recursion is.

Oh, and by the way:



int factorial(int n)
{
if (n=0) return 1;
else return n * factorial n;

//if the universe has gone insane, return 42 (cannot be a factorial)
return 42;
}



At least the code in the story produces an answer when n > 1 ;)

Re: F'd Factorial

2007-06-27 10:11 • by DZ-Jay (unregistered)
142855 in reply to 142840

int factorial(int n)

{

if (n=0) return 1;

else return n * factorial n;



//if the universe has gone insane, return 42 (cannot be a factorial)

return 42;

}


Congratulations! You have just discovered Infinite Recursion (TM), or more commonly known as the stack overflow.

-dZ.

Re: F'd Factorial

2007-06-27 10:15 • by Welbog
142856 in reply to 142853
Fj_:
It actually returns 13, because 12 is incremented one last time before the comparison.
I suggest learning more about for loops.

Re: F'd Factorial

2007-06-27 10:15 • by Fj_ (unregistered)
142857 in reply to 142853
Ooops, but it isn't stored though =/

Re: F'd Factorial

2007-06-27 10:16 • by NiceWTF (unregistered)
Well, but at least he knew what a factorial is! (mostly...anyway)

Re: F'd Factorial

2007-06-27 10:19 • by Kthx Bai (unregistered)
142859 in reply to 142843
Cochrane:
didn't learn anything. He is completely useless now


In other words, perfect management material... from here its all up up up the ziggurat lickity split!

Re: F'd Factorial

2007-06-27 10:19 • by patrys
Here's the (obviously) corrected version in Python:


i = 1
a = 0
while i < 10:
i = i * (i + 1)
a = i
print a

Re: F'd Factorial

2007-06-27 10:21 • by sxeraverx (unregistered)
4.5224! = 12

Re: F'd Factorial

2007-06-27 10:22 • by Justin (unregistered)
142862 in reply to 142823
Quite right. Looks like I needed to sleep some more last night!

Re: F'd Factorial

2007-06-27 10:23 • by unklegwar
142863 in reply to 142827
Joseph:
I just find it amazing that people who code like that can actually graduate!


Garbage In - Garbage Out

I sat behind a girl in my Comp Sci classes who declared to the entire class that multiplying a positive number by a negative number yielded a positive number.

How can you expect to build a competent computer scientist on that kind of foundation? Imagine what she cranked out for recursive algorithms.


Re: F'd Factorial

2007-06-27 10:23 • by thisisnotmyname (unregistered)
142864 in reply to 142855
DZ-Jay:

int factorial(int n)

{

if (n=0) return 1;

else return n * factorial n;



//if the universe has gone insane, return 42 (cannot be a factorial)

return 42;

}


Congratulations! You have just discovered Infinite Recursion (TM), or more commonly known as the stack overflow.

-dZ.


Not sure what language this is, but I think you want
if (n == 0) return 1;

Re: F'd Factorial

2007-06-27 10:24 • by sxeraverx (unregistered)
142865 in reply to 142861
Sorry about that, gamma(4.5224) = 12, so:

3.5224! = 12

My bad.

Re: F'd Factorial

2007-06-27 10:27 • by Guru Buckaroo (unregistered)
142866 in reply to 142855
DZ-Jay:

int factorial(int n)

{

if (n=0) return 1;

else return n * factorial n;



//if the universe has gone insane, return 42 (cannot be a factorial)

return 42;

}


Congratulations! You have just discovered Infinite Recursion (TM), or more commonly known as the stack overflow.

-dZ.

What you have all failed to notice, is that this function WILL return, immediately, the value it is called with. After all, that first if is using an assignment operator, not a comparison operator.

'course, it won't compile.... but who's perfect...

Captcha: gygax (thief)
« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5 | Page 6Next »

Add Comment