Cycling and bicycle discussion forums. 
   Click here to join our community Log in to access your Control Panel  


Go Back   > >

Foo Off-Topic chit chat with no general subject.

User Tag List

Reply
 
Thread Tools Search this Thread
Old 09-16-08, 12:28 AM   #1
mlts22 
Senior Member
Thread Starter
 
Join Date: Aug 2006
Bikes:
Posts: 998
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Less than 1% of CS grads can do this...

Supposedly, and the sources really can't be verified so take it for what it is worth, almost no CS grads can write a program to do the following:

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
mlts22 is offline   Reply With Quote
Old 09-16-08, 12:31 AM   #2
mattm
**** that
 
mattm's Avatar
 
Join Date: Dec 2006
Location: CALI
Bikes:
Posts: 13,739
Mentioned: 15 Post(s)
Tagged: 0 Thread(s)
Quoted: 111 Post(s)
i wish interview questions were that easy!
__________________
cat 1.

blog
mattm is offline   Reply With Quote
Old 09-16-08, 12:44 AM   #3
iamlucky13
Footballus vita est
 
iamlucky13's Avatar
 
Join Date: Jun 2002
Location: Portland, OR
Bikes: Trek 4500, Kona Dawg
Posts: 2,118
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Is there something more to it than a couple while statements?
__________________
"The internet is a place where absolutely nothing happens. You need to take advantage of that." ~ Strong Bad
iamlucky13 is offline   Reply With Quote
Old 09-16-08, 12:54 AM   #4
annc
Senior Member
 
Join Date: Jun 2008
Bikes:
Posts: 428
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Less than a couple while loops...
annc is offline   Reply With Quote
Old 09-16-08, 01:40 AM   #5
DannoXYZ 
Senior Member
 
DannoXYZ's Avatar
 
Join Date: Jul 2005
Location: Saratoga, CA
Bikes:
Posts: 11,600
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Heck, I can do that with a single pass through one while-loop...
DannoXYZ is offline   Reply With Quote
Old 09-16-08, 01:44 AM   #6
jschen
riding once again
 
jschen's Avatar
 
Join Date: Oct 2005
Location: San Diego, CA
Bikes: '06 Cervelo R3, '05 Specialized Allez
Posts: 7,359
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Heck... with no need to input a range, the program can just spit out a predefined string if the programmer wants a brute force solution!
__________________
If you notice this notice then you will notice that this notice is not worth noticing.
jschen is offline   Reply With Quote
Old 09-16-08, 01:55 AM   #7
keithm0
Grizzled Curmudgeon
 
keithm0's Avatar
 
Join Date: Mar 2006
Location: Woodinville, WA
Bikes: Specialized Stumpjumper (hardtail), Co-Motion Nor'Wester
Posts: 467
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Quote:
Originally Posted by mattm View Post
i wish interview questions were that easy!
Sadly, I've seen interview candidates fail even simpler questions.
__________________
keithmo.com
keithm0 is offline   Reply With Quote
Old 09-16-08, 02:36 AM   #8
mattm
**** that
 
mattm's Avatar
 
Join Date: Dec 2006
Location: CALI
Bikes:
Posts: 13,739
Mentioned: 15 Post(s)
Tagged: 0 Thread(s)
Quoted: 111 Post(s)
Quote:
Originally Posted by keithm0 View Post
Sadly, I've seen interview candidates fail even simpler questions.
like what?
__________________
cat 1.

blog
mattm is offline   Reply With Quote
Old 09-16-08, 03:05 AM   #9
crtreedude 
Third World Layabout
 
crtreedude's Avatar
 
Join Date: Dec 2005
Location: Costa Rica
Bikes: Cannondale F900 and Tandem
Posts: 3,075
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 57 Post(s)
Yeah, I know they are that bad... I used to interview them.

My test were worse. I would print out code and ask them.

"What does this code do?" after removing the obvious clues from function names.

You could see the beads of sweat appear...

Made sense to me. If I appear infront of a Latin American claiming I know Spanish, I better be ready for them to switch into Spanish.
crtreedude is offline   Reply With Quote
Old 09-16-08, 03:43 AM   #10
MrCrassic 
Senior Member
 
MrCrassic's Avatar
 
Join Date: Jun 2007
Location: Brooklyn, NY
Bikes: 2008 Giant OCR1 (with panda bear on the back!)
Posts: 3,650
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
C++: You only need a
Code:
for
statement to complete this, and a couple of checks to see whether the number modulo 3 or 5 is zero...

Code:
for (int i = 1; i <= 100; i++)
{
     if (i%3==0) 
           cout << "Bizz!";
     if (i%5==0)
           cout << "Buzz!";
     if (i%3==0&&i%5==0) //15 is multiple of both
           cout << "Bizz buzz!";
     else
           cout << "Number: " << i;
**
And I'm in Computer Engineering...?
__________________
Ride more.

Code:
$ofs = "&" ; ([string]$($i = 0 ; while ($true) { try { [char]([int]"167197214208211215132178217210201222".substring($i,3) - 100) ; $i =
 $i+3 > catch { break >>)).replace('&','') ; $ofs=" " # Replace right angles with right curly braces

Last edited by MrCrassic; 09-16-08 at 03:46 AM. Reason: Variable cleaning.
MrCrassic is offline   Reply With Quote
Old 09-16-08, 03:52 AM   #11
ehidle
T-Shirt Guy
 
ehidle's Avatar
 
Join Date: Jul 2008
Location: Lansdale, PA
Bikes: 2005 Fuji Team Issue, 2007 Fuji SL-1
Posts: 464
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Quote:
Originally Posted by MrCrassic View Post
C++: You only need a
Code:
for
statement to complete this, and a couple of checks to see whether the number modulo 3 or 5 is zero...

Code:
for (int i = 1; i <= 100; i++)
{
     if (i%3==0) 
           cout << "Bizz!";
     if (i%5==0)
           cout << "Buzz!";
     if (i%3==0&&i%5==0) //15 is multiple of both
           cout << "Bizz buzz!";
     else
           cout << "Number: " << i;
**
And I'm in Computer Engineering...?
So, your code here will output "Bizz!" for multiples of three, "Buzz!" for multiples of 5, and "Bizz!Buzz!Bizz buzz!" for numbers that are multiples of both 3 and 5...

You need to exclude multples of 5 from the first if statement and multiples of 3 from the second if statement and multples of both from both the first and second if statements.
__________________
Yellow + Blue Jerseys!

Get your Cranky T-Shirt!
Men's
and Women's designs available
ehidle is offline   Reply With Quote
Old 09-16-08, 04:02 AM   #12
crtreedude 
Third World Layabout
 
crtreedude's Avatar
 
Join Date: Dec 2005
Location: Costa Rica
Bikes: Cannondale F900 and Tandem
Posts: 3,075
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 57 Post(s)
Quote:
Originally Posted by ehidle View Post
So, your code here will output "Bizz!" for multiples of three, "Buzz!" for multiples of 5, and "Bizz!Buzz!Bizz buzz!" for numbers that are multiples of both 3 and 5...

You need to exclude multples of 5 from the first if statement and multiples of 3 from the second if statement and multples of both from both the first and second if statements.
Actually I would flunk you all, you missed the key component. The spec is vague - the output can be either with multiple outputs or not. This should be resolved first.

One of the most basic skills is know when a spec is not complete.

But, you are correct, MrCrassic would fail by either interpretation, because the number would be printed out unless the the number was multiples of 3 and 5. The instruction clearly states that the number should only be printed out in the case of no match on the conditions.
crtreedude is offline   Reply With Quote
Old 09-16-08, 04:12 AM   #13
MrCrassic 
Senior Member
 
MrCrassic's Avatar
 
Join Date: Jun 2007
Location: Brooklyn, NY
Bikes: 2008 Giant OCR1 (with panda bear on the back!)
Posts: 3,650
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Quote:
Originally Posted by ehidle View Post
So, your code here will output "Bizz!" for multiples of three, "Buzz!" for multiples of 5, and "Bizz!Buzz!Bizz buzz!" for numbers that are multiples of both 3 and 5...

You need to exclude multples of 5 from the first if statement and multiples of 3 from the second if statement and multples of both from both the first and second if statements.
So just remove the last IF statement?
__________________
Ride more.

Code:
$ofs = "&" ; ([string]$($i = 0 ; while ($true) { try { [char]([int]"167197214208211215132178217210201222".substring($i,3) - 100) ; $i =
 $i+3 > catch { break >>)).replace('&','') ; $ofs=" " # Replace right angles with right curly braces
MrCrassic is offline   Reply With Quote
Old 09-16-08, 04:12 AM   #14
crtreedude 
Third World Layabout
 
crtreedude's Avatar
 
Join Date: Dec 2005
Location: Costa Rica
Bikes: Cannondale F900 and Tandem
Posts: 3,075
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 57 Post(s)
for(int i = 1; i++ ; i <= 100)
{
if(i % 3 == 0) printf("fizz");
if(i % 5 == 0) printf("buzz");
if(i % 3 && i % 5) printf("%d",i);
printf("\n);
**

I am sure I could reduce this, but this is quick and dirty. No need to make a special case out of 5 and 3 together since you can just join them. Not tested, I have no compiler on this computer.

The benefits to test like this is they help you see how the person thinks since there are many, many ways to solve this.
crtreedude is offline   Reply With Quote
Old 09-16-08, 04:14 AM   #15
crtreedude 
Third World Layabout
 
crtreedude's Avatar
 
Join Date: Dec 2005
Location: Costa Rica
Bikes: Cannondale F900 and Tandem
Posts: 3,075
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 57 Post(s)
Quote:
Originally Posted by MrCrassic View Post
So just remove the last IF statement?
You need to have an else between each IF statement, not just the final one, if we are too assume that a single line of output is desired for each iterative.
crtreedude is offline   Reply With Quote
Old 09-16-08, 04:18 AM   #16
crtreedude 
Third World Layabout
 
crtreedude's Avatar
 
Join Date: Dec 2005
Location: Costa Rica
Bikes: Cannondale F900 and Tandem
Posts: 3,075
Mentioned: 1 Post(s)
Tagged: 0 Thread(s)
Quoted: 57 Post(s)
By the way, if I was coding for speed of execution, I would write it completely different. printfs are expensive to execute, so I would build the string before printing - the code would look much weirder and harder to follow.

I used to write DSP code where everything has to be super tight. When an eternity is 20 ms, you learn to be efficient...
crtreedude is offline   Reply With Quote
Old 09-16-08, 04:51 AM   #17
ehidle
T-Shirt Guy
 
ehidle's Avatar
 
Join Date: Jul 2008
Location: Lansdale, PA
Bikes: 2005 Fuji Team Issue, 2007 Fuji SL-1
Posts: 464
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Quote:
Originally Posted by crtreedude View Post
I used to write DSP code where everything has to be super tight. When an eternity is 20 ms, you learn to be efficient...
I used to write code to do numerical electromagnetic analysis. Think solving million x million matrices. A single simulation might take a couple of weeks to run, so every millisecond that could be shaved from a routine could save hours of time off of a simulation.

Now I work on embedded control systems with milliseconds control resolution. Everything has to be super tight - no wasted instructions.

And I'm a hardware guy... hah..
__________________
Yellow + Blue Jerseys!

Get your Cranky T-Shirt!
Men's
and Women's designs available
ehidle is offline   Reply With Quote
Old 09-16-08, 05:33 AM   #18
Jerseysbest
J E R S E Y S B E S T
 
Jerseysbest's Avatar
 
Join Date: Apr 2005
Location: DC
Bikes:
Posts: 1,849
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
I barely know how code and could do that.

I guess CS grads do more theoretical work instead of practical?
Jerseysbest is offline   Reply With Quote
Old 09-16-08, 05:45 AM   #19
Indy_Rider
Banned
 
Indy_Rider's Avatar
 
Join Date: Dec 2004
Location: On a boat
Bikes: 2000 Fisher Paragon, 2005 Giant OCR2, 2006 Bianchi SASS, numerous others
Posts: 56
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
That is probably because 99% of CS majors would ask why and tell them that is the dumbest question they have ever heard. People mistake not wanting to waste their time with a really freaking stupid question with not being able to do it.
Indy_Rider is offline   Reply With Quote
Old 09-16-08, 07:55 AM   #20
hos13
Senior Member
 
hos13's Avatar
 
Join Date: Mar 2007
Location: 552 LATA
Bikes: 2007 Mercier Sperns (I'm a shill) and a 99 Diamondback Invert
Posts: 781
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
This is so easy, I could do it with a Turing Machine. (Not really, But I did have to add 2 numbers together once with a Turing Machine)
hos13 is offline   Reply With Quote
Old 09-16-08, 08:07 AM   #21
MrCrassic 
Senior Member
 
MrCrassic's Avatar
 
Join Date: Jun 2007
Location: Brooklyn, NY
Bikes: 2008 Giant OCR1 (with panda bear on the back!)
Posts: 3,650
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Quote:
Originally Posted by crtreedude View Post
Actually I would flunk you all, you missed the key component. The spec is vague - the output can be either with multiple outputs or not. This should be resolved first.

One of the most basic skills is know when a spec is not complete.

But, you are correct, MrCrassic would fail by either interpretation, because the number would be printed out unless the the number was multiples of 3 and 5. The instruction clearly states that the number should only be printed out in the case of no match on the conditions.
Forgot the else statement...darn!

Code:
for (int i = 1; i <= 100; i++)
{
     if (i%3==0) 
           cout << "Bizz!";
     else if (i%5==0)
           cout << "Buzz!";
     else if (i%3==0&&i%5==0) //15 is multiple of both
           cout << "Bizz buzz!";
     else
           cout << "Number: " << i;
**
__________________
Ride more.

Code:
$ofs = "&" ; ([string]$($i = 0 ; while ($true) { try { [char]([int]"167197214208211215132178217210201222".substring($i,3) - 100) ; $i =
 $i+3 > catch { break >>)).replace('&','') ; $ofs=" " # Replace right angles with right curly braces
MrCrassic is offline   Reply With Quote
Old 09-16-08, 08:09 AM   #22
MrCrassic 
Senior Member
 
MrCrassic's Avatar
 
Join Date: Jun 2007
Location: Brooklyn, NY
Bikes: 2008 Giant OCR1 (with panda bear on the back!)
Posts: 3,650
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
My only corporate software development experience was with working in a software division of a hedge fund. I did some Java GUI code (HORRORS!!!), and towards the end, I finally worked on some C++ backend server processes.

I like coding, but hated the environment, hence the reason why I'm trying business analysis right now (though I wish I could do some coding!)
__________________
Ride more.

Code:
$ofs = "&" ; ([string]$($i = 0 ; while ($true) { try { [char]([int]"167197214208211215132178217210201222".substring($i,3) - 100) ; $i =
 $i+3 > catch { break >>)).replace('&','') ; $ofs=" " # Replace right angles with right curly braces
MrCrassic is offline   Reply With Quote
Old 09-16-08, 08:10 AM   #23
black_box
Fax Transport Specialist
 
black_box's Avatar
 
Join Date: May 2008
Location: chicago burbs
Bikes: '17 giant propel, '07 fuji cross pro, '10 gary fisher x-caliber
Posts: 902
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 7 Post(s)
i'm no efficiency expert, but couldnt you just use a string of some kind and concatenate or += the Buzz on modulo 5? you'd have to clear the variable at the end of each loop though.
black_box is online now   Reply With Quote
Old 09-16-08, 08:58 AM   #24
KingTermite 
On my TARDIScycle!
 
KingTermite's Avatar
 
Join Date: Jun 2005
Location: Eastside Seattlite Termite Mound
Bikes: Trek 520, Trek Navigator 300, Peugeot Versailles PE10DE
Posts: 3,924
Mentioned: 0 Post(s)
Tagged: 0 Thread(s)
Quoted: 0 Post(s)
Quote:
Originally Posted by mlts22 View Post
Supposedly, and the sources really can't be verified so take it for what it is worth, almost no CS grads can write a program to do the following:

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
That is so, so, so, so saaaad.

I remember a girl I was flirting with in college. I was Computer Engineering, she was Computer Science (close majors, CE = CS + a few extra classes). She got an intern job and she was telling me a story of how just to help her get started and understand the compiler they used, they asked her to write a "Hello World" program. She couldn't do it.

Besides all that, I just can't believe that less than 1% of CS majors could do this. That's like saying less than 1% of English majors couldn't identify the verb in a sentence.
__________________
Quote:
Originally Posted by coffeecake View Post
- it's pretty well established that Hitler was an *******.
KingTermite is offline   Reply With Quote
Old 09-16-08, 09:03 AM   #25
mattm
**** that
 
mattm's Avatar
 
Join Date: Dec 2006
Location: CALI
Bikes:
Posts: 13,739
Mentioned: 15 Post(s)
Tagged: 0 Thread(s)
Quoted: 111 Post(s)
now do it without using the mod operator..
__________________
cat 1.

blog
mattm is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT -6. The time now is 02:58 PM.