Advertise on Bikeforums.net



User Tag List

Page 1 of 3 123 LastLast
Results 1 to 25 of 60
  1. #1
    Senior Member
    Join Date
    Aug 2006
    Posts
    998
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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”.

  2. #2
    **** that mattm's Avatar
    Join Date
    Dec 2006
    Location
    CALI
    Posts
    11,638
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    i wish interview questions were that easy!
    cat 1.

    blog

  3. #3
    Footballus vita est iamlucky13's Avatar
    Join Date
    Jun 2002
    Location
    Portland, OR
    My Bikes
    Trek 4500, Kona Dawg
    Posts
    2,118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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

  4. #4
    Senior Member
    Join Date
    Jun 2008
    Posts
    428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Less than a couple while loops...

  5. #5
    Senior Member DannoXYZ's Avatar
    Join Date
    Jul 2005
    Location
    Saratoga, CA
    Posts
    11,507
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heck, I can do that with a single pass through one while-loop...

  6. #6
    riding once again jschen's Avatar
    Join Date
    Oct 2005
    Location
    San Diego, CA
    My Bikes
    '06 Cervelo R3, '05 Specialized Allez
    Posts
    7,360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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.

  7. #7
    Grizzled Curmudgeon keithm0's Avatar
    Join Date
    Mar 2006
    Location
    Woodinville, WA
    My Bikes
    Specialized Stumpjumper (hardtail), Co-Motion Nor'Wester
    Posts
    467
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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.

  8. #8
    **** that mattm's Avatar
    Join Date
    Dec 2006
    Location
    CALI
    Posts
    11,638
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by keithm0 View Post
    Sadly, I've seen interview candidates fail even simpler questions.
    like what?
    cat 1.

    blog

  9. #9
    Third World Layabout crtreedude's Avatar
    Join Date
    Dec 2005
    Location
    Costa Rica
    My Bikes
    Cannondale F900 and Tandem
    Posts
    3,073
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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.

  10. #10
    Senior Member MrCrassic's Avatar
    Join Date
    Jun 2007
    Location
    Brooklyn, NY
    My Bikes
    2008 Giant OCR1 (with panda bear on the back!)
    Posts
    3,651
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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...?
    Last edited by MrCrassic; 09-16-08 at 04:46 AM. Reason: Variable cleaning.
    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

  11. #11
    T-Shirt Guy ehidle's Avatar
    Join Date
    Jul 2008
    Location
    Lansdale, PA
    My Bikes
    2005 Fuji Team Issue, 2007 Fuji SL-1
    Posts
    464
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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

  12. #12
    Third World Layabout crtreedude's Avatar
    Join Date
    Dec 2005
    Location
    Costa Rica
    My Bikes
    Cannondale F900 and Tandem
    Posts
    3,073
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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.

  13. #13
    Senior Member MrCrassic's Avatar
    Join Date
    Jun 2007
    Location
    Brooklyn, NY
    My Bikes
    2008 Giant OCR1 (with panda bear on the back!)
    Posts
    3,651
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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

  14. #14
    Third World Layabout crtreedude's Avatar
    Join Date
    Dec 2005
    Location
    Costa Rica
    My Bikes
    Cannondale F900 and Tandem
    Posts
    3,073
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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.

  15. #15
    Third World Layabout crtreedude's Avatar
    Join Date
    Dec 2005
    Location
    Costa Rica
    My Bikes
    Cannondale F900 and Tandem
    Posts
    3,073
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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.

  16. #16
    Third World Layabout crtreedude's Avatar
    Join Date
    Dec 2005
    Location
    Costa Rica
    My Bikes
    Cannondale F900 and Tandem
    Posts
    3,073
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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...

  17. #17
    T-Shirt Guy ehidle's Avatar
    Join Date
    Jul 2008
    Location
    Lansdale, PA
    My Bikes
    2005 Fuji Team Issue, 2007 Fuji SL-1
    Posts
    464
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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

  18. #18
    J E R S E Y S B E S T Jerseysbest's Avatar
    Join Date
    Apr 2005
    Location
    DC
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I barely know how code and could do that.

    I guess CS grads do more theoretical work instead of practical?

  19. #19
    Banned Indy_Rider's Avatar
    Join Date
    Dec 2004
    Location
    On a boat
    My Bikes
    2000 Fisher Paragon, 2005 Giant OCR2, 2006 Bianchi SASS, numerous others
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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.

  20. #20
    Senior Member hos13's Avatar
    Join Date
    Mar 2007
    Location
    552 LATA
    My Bikes
    2007 Mercier Sperns (I'm a shill) and a 99 Diamondback Invert
    Posts
    778
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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)
    "Don't give up, don't ever give up" jimmyv

  21. #21
    Senior Member MrCrassic's Avatar
    Join Date
    Jun 2007
    Location
    Brooklyn, NY
    My Bikes
    2008 Giant OCR1 (with panda bear on the back!)
    Posts
    3,651
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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

  22. #22
    Senior Member MrCrassic's Avatar
    Join Date
    Jun 2007
    Location
    Brooklyn, NY
    My Bikes
    2008 Giant OCR1 (with panda bear on the back!)
    Posts
    3,651
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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

  23. #23
    Fax Transport Specialist black_box's Avatar
    Join Date
    May 2008
    Location
    chicago burbs
    My Bikes
    '07 fuji cross pro, '10 gary fisher x-caliber
    Posts
    850
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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.

  24. #24
    On my TARDIScycle! KingTermite's Avatar
    Join Date
    Jun 2005
    Location
    Eastside Seattlite Termite Mound
    My Bikes
    Trek 520, Trek Navigator 300, Peugeot Versailles PE10DE
    Posts
    3,928
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(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 *******.

  25. #25
    **** that mattm's Avatar
    Join Date
    Dec 2006
    Location
    CALI
    Posts
    11,638
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    now do it without using the mod operator..
    cat 1.

    blog

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •