Easier Than Fizz Buzz - Why Can't Programmers Print 100 to 1? (article)
-
Guy makes a chart showing correlation between interview candidates whining about their ex employer and having problems solving a very simple programming challenge.
The challenge:
Print 100 to 1.
That's it.
That was the question.
The Catch?
You need to start with "for(int i=0;" and continue from there - you cannot write anything before "for(int i=0;" and you can't use two loops.
Results?
About 14% just couldn't solve the problem in less then 10 minutes - which is when we moved on to the next question.
About 40% took more than 5 minutes to solve the problem and / or had to be corrected more than once.
Only about 14% could solve this problem in 2 minutes or less.
About 82% had to be corrected at-least once before they solved the problem. (which means they actually got it wrong the first time around!)
Unbelievable.
As for myself, I solved it in like 15 seconds and I don't feel I'd spend much time whining about my current employer. So I'd fit right into his chart.
(The guy's site is being being hugged to death right about now, so be patient if it won't load immediately. If needed, I can mirror it here).
-
Luckily someone archived it: https://archive.today/hSiHV
-
for (var i = 0; i < 100; i += 1) { console.log(100-i); }
time spent solving..... about a minute=, most of which was formatting it for discourse.
-
-
Not knowing - is inexcusable.
-
-
Guys, you're not solving the correct problem.
for(int i=0; i < strlen("100 to 1\n"); i++) { putc("100 to 1\n"[i]); }
-
@thegoryone said:
Only 14% of people could...uhh...seriously?
@multiple TDWTF members said:
If you're on TDWTF you're among 10% of best programmers in the world.
I don't know which scares me more: Nagesh being here, or me.
-
I got to the subtraction solution after a short bit of thinking myself, although @accalia does point out that the challenge is a bit silly in its syntax specificity:
for x in range(0, 100): print(100-x)
is a valid solution, but doesn't fit the criteria because Python's for is a foreach ;)
-
And it's supposed to be
range(0, 100)
(silly me for making that fencepost error) but now I can't edit the post! @discoursebot
-
challenge is a bit silly in its syntax specificity:
depends on the language... in C or C++ then int is the correct type.
-
Paging @offbyone ...Or are ranges non-inclusive in python?I guess they are non-inclusive! That's odd. And different from VB.NET:
For i As integer = 0 To 99 Console.Writeline(100 - i) Next
-
depends on the language... in C or C++ then int is the correct type.
Yeah, but it's being presented without that context
-
The context can be inferred to be "a language where
for (int i=0;
is valid"
-
Guys, you're not solving the correct problem.
for(int i=0; i == 0; i++) { puts("100 to 1"); }
-
But seriously, it's an interesting choice of a problem. You're given a task you probably CAN solve, no matter how incompetent you are. But then, you're given an arbitrary constriction:
"You can't just write the thing however you want. You HAVE to use this silly pattern and follow these stupid rules."
Almost like the sort of rules you have to navigate around in a corporate environment. Some people whine and complain. Others whine and complain, and then get shit done.
The more I think about it, the more I like this interview technique.
-
You mean like how the application I currently work on in Java couldn't use JPA or things like Spring MVC and instead uses raw JDBC code and raw JSP/Servlets?
Then again, I don't think it was corporate that decided that, but rather the developer who started this project.
-
More worrying IMO is the whining part. One of the first things I learnt was to never, ever, complain about my previous workplaces. Some remarks are good to show criticism (eg. bad communication between teams) but to go on and on about your boss being an ass to your possibly new boss is a really stupid way of handling yourself.
Also, be aware of what you say about technology stacks. Always take the positive side of projects and don't say things like "Spring is crap" to later get "we use Spring in all our projects -because me, the one doing the interview- decided to". Good way of digging your own ditch.
-
for(i=0;i>=0;i--) { if(i==0) i=99; cout << i+1<< endl; }
Solved it the WRONG way in less than a minute. (Not tested so if I stupid'd something oh well)
Filed Under: Yeah, yeah, evil ideas thread is yada yada bla
-
Endless loop, yada yada bla
-
IMO, they are expecting you to know the difference between i++ and ++i that's why they put i = 0 as the start.
-
Eh, I'm sure I could fix that but my low food light is on.
And just so everyone knows I'm not insane...
for(int i=0;i<100;i++) cout << 100-i << endl;
-
IMO, they are expecting you to know the difference between i++ and ++i that's why they put i = 0 as the start.
Bad test case then, because there's none here, assuming a sane solution of course.
Filed under: INB4 embedded hardware
-
I don't think so, since that's in the loop declaration.
Actually I can make this a one-liner...
for(int i=0;i<100;cout << 101-(++i) << endl);
-
IMO, they are expecting you to know the difference between i++ and ++i that's why they put i = 0 as the start.
I think IHBT, but...
They're looking to see if you can figure out that you can subtract it from 100 instead of counting down from 100.
-
At nearly 2am, solutions start to get kinda weird:
for(var i = 0; i > -100; i--) { console.log(i+100); }
-
belgium it. I just nerdsniped myself. I WILL SOLVE IT THAT WAY DAMMIT!
-
can we use bots here? you know, there's a bot that can run that codes for us :P|
-
for(int i = 0; printf("%d\n", 100 - i) && i < 99; ++i);
I wanted to use
printf
to be an actual useful condition, but couldn't think of anything right now.
-
And again, instead of people talking about the really important issue of crappy IT interview candidates polluting job pools everywhere, people just start posting code samples. I guess to "prove" they aren't the crappy candidates themselves? We can just trust you on that, ok?
-
Also, be aware of what you say about technology stacks. Always take the positive side of projects and don't say things like "Spring is crap" to later get "we use Spring in all our projects -because me, the one doing the interview- decided to". Good way of digging your own ditch.
That happened to me, but not about a specific technology-- about the concept of having a QA department manually testing code!
WTF.
Kind of glad I bombed that interview.
-
More worrying IMO is the whining part. One of the first things I learnt was to never, ever, complain about my previous workplaces. Some remarks are good to show criticism (eg. bad communication between teams) but to go on and on about your boss being an ass to your possibly new boss is a really stupid way of handling yourself.
Also, be aware of what you say about technology stacks. Always take the positive side of projects and don't say things like "Spring is crap" to later get "we use Spring in all our projects -because me, the one doing the interview- decided to". Good way of digging your own ditch.
I disagree to a point. If you've come from a shitty environment it can be a good way to gauge the competency of your prospective employer. If your old company was batshit insane and did insane things, any sane person is going to listen to that and think "Holy shit that place was stupid". The place that's like "You complained a lot about your old job" is likely just as bad because they don't see anything wrong.
I'd often use something similar, not outright bitching but more like pointing out flaws with things such as a mandate to not use a framework that could have helped or being forbidden from improving code. The reason is it's a smell test: If the person interviewing me doesn't pick up on why that would cause a lot of issues, they're probably just as clueless and ignorant.
In short: You bitch about your current/ex job in the hopes the person interviewing will think "We'd never treat anyone so bad that they felt the need to bitch about it". If they think anything else, and especially anything against you for bitching, they have the same problems.
Sometimes it's just random bitching for stupid reasons e.g. They didn't give me dual monitors, etc. But usually the bitching is because the old company had major problems and the interviewee wants to make sure the new company doesn't.
-
i guess it depends on how much you need/want the job.
but yeah, sometimes is better to fail at the interview
-
i guess it depends on how much you need/want the job.
Not enough to work at a place that sees no value in QAing their product.
-
so, you won't be working for discourse soon?
-
I'm not a qualified programmer but I solved it in the time it took to type the subtraction version. It's possibly a case of peoples brains turning to toffee in an interview situation. I know I have constant flashes of panic when asked [i]anything[/i], even my own name.
-
They're looking to see if you can figure out that you can subtract it from 100 instead of counting down from 100.
I suck, and even I had that as my first thought. Look at what you have control of, and then think of how you can use it.
The other guys were probably too busy whining about how arbitrary the exercise was and how easy it would be if they could just decrement from 100.
Filed under: Seriously Chrome, you don't have "decrement" in your spell check dictionary?
-
I'm not a qualified programmer but I solved it in the time it took to type the subtraction version. It's possibly a case of peoples brains turning to toffee in an interview situation. I know I have constant flashes of panic when asked [i]anything[/i], even my own name.
I think it's more that at first it sounds like a trick question, because the idea of hard-coding 100 and subtracting i isn't immediately evident as a solution you'd ever do so you kind of push it out of your mind.
-
It's possibly a case of peoples brains turning to toffee in an interview situation.
I disagree. There really are candidates this brain dead. I understand being nervous and underperforming, but thanks to SO and schools that care more about milking students for as much money as possible, it is possible to get a CIS degree without knowing how to program at all.
-
it is possible to get a CIS degree without knowing how to program at all.
It is possible to get a CIS degree these days apparently without even knowing that all mathematical operations a computer does are addition.
I shit you not.
-
As I said, you can be critic and you can whine. There's a difference. I mean, you can say your ex-boss was stupid, but use a educated tone. You can say the technology stack was a mess or you can say it had a lot of technical debt.
At the end a job interview has a big sales/marketing component and you have to know how to sell yourself, specially when talking with HR and executives.
Think about the person doing the interview. They don't want to listen to your bitching, the want to know if you're a fitted candidate and usually it's better to have a positive position.
Also, the question "Why you want to switch jobs?" is tricky and a way of getting your guard down and to open up.
-
It's possibly a case of peoples brains turning to toffee in an interview situation.
So this is a perfect example of doing a problem-solving test in a high-stress situation. Therefore, it's a really really good interview question IMO. It's a "can you actually think your way out of a cardboard box even if you're on the spot" type question
-
for(i=0;i>=1;i--) { if(i==0) i=100; cout << i<< endl; }
that should do it. ;-)
-
And ladies and gentlemen, this is why you don't program on an empty stomach without an IDE.
-
well it's untested. i just saw an offbyone error and i knew how to fix it. :-P
uhh..... i did not expect that to trigger user card...
if discourse actually generated notification then that would be hilarious because i was trying to avoid the mention!.
-
well accalia, does it?
-
-
dunno. reply trumps mention notifications
-
That won't print anything.
-