| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Page 6 | Next » |
|
More functions should disregard input values and just return 12. It would make life easier.
|
|
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 |
|
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! |
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 |
|
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.
|
Yes we know it is modified in the loop. That's why it is twelve and not 10. |
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 |
|
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.
|
|
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!
|
Are you saying that n! != 12 for all n? |
|
I just find it amazing that people who code like that can actually graduate!
|
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... :)
|
|
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...
|
I think I speak for all of us when I ask you to provide examples of bad factorial implementations from interviews. |
I never regurgitated from college, hell I never went, and even I know what recursion is. |
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. |
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. |
Dear god, why do people insist on reinventing the wheel? We REJECT candidates who use their own sort algorithms in their homework assignment. |
Using other bases is cheating. I'm telling! |
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. |
And 2! = 12 (base... uh, 0?) |
Re: F'd Factorial
2007-06-27 09:51
•
by
Noamsml
(unregistered)
|
Same here. I'm a f'ing high school student and even I know what recursion is. Oh, and by the way:
|
|
He could have made it interesting by throwing in a "+i* (i % 2 == 0 ? -1 : 1)" or something.
|
|
He could have made it interesting by throwing in a "+i* (i % 2 == 0 ? -1 : 1)" or something.
|
|
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 ) 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. |
Not if you're competing against him for a job... |
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 |
Isn't factorial(0) defined as 1? Captcha: muhahaha! |
|
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. |
Nice code. Will never return though... Captcha: alarm - what this code raised internally (in me) |
|
Some CS programs are really MIS programs in disguise. Don't be fooled!
|
But evidently you haven't gotten to the part about infinite loops yet. else return n * factorial n-1; |
|
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)
|
At least the code in the story produces an answer when n > 1 ;) |
Congratulations! You have just discovered Infinite Recursion (TM), or more commonly known as the stack overflow. -dZ. |
I suggest learning more about for loops. |
|
Ooops, but it isn't stored though =/
|
|
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)
|
In other words, perfect management material... from here its all up up up the ziggurat lickity split! |
|
Here's the (obviously) corrected version in Python:
|
|
Quite right. Looks like I needed to sleep some more last night!
|
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)
|
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)
|
|
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)
|
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) |
| « Prev | Page 1 | Page 2 | Page 3 | Page 4 | Page 5 | Page 6 | Next » |