Skip to content
Liquid Egg Product

Liquid Egg Product

  • Home
  • Science/Technology
  • Interviews

Interviews

Posted on September 26, 2007 By Liquid Egg Product 7 Comments on Interviews
Science/Technology
Write a function that prints the numbers 1 through 100 in order, with the following exceptions:

If the number’s a multiple of 3, print “foo” instead of the number.
If the number’s a multiple of 5, print “bar” instead of the number.
If the number’s a multiple of 3 and 5, print “foobar” instead of the number.

Can use pseudocode or the language of your choice.

(Note for non-programmers: this is a very easy task.)
(Note 2: Pseudocode is not real code with formal syntax; it’s just jotting down how code’s going to work.)

Interview 1

So this guy interviews today, seems nice and possibly adequate. According to him, his strength is VB.NET, and although 95% of our stuff is C#, I don’t sweat someone learning a new language syntax.

Towards the end of the interview, my colleague gave him the programming question above. After stammering for a few seconds, the guy explained, “Well, you know, pseudocode was one of the first classes I took, and I can’t really remember back that far.” While I tried to prevent myself from bursting, my colleague suggested he write out the code in Visual Basic, since that was supposed to be his strength. The shirking candidate claimed he couldn’t write the function without looking in a reference book.

At that moment, I felt like saying “Interview over, time for our next contestant.” However, my co-worker went on to explain the solution, which would use a loop to print out all the numbers. “A loop. You know, a for loop?” he asked. The candidate muttered, “Oh, a for loop…”, obviously with no knowledge of what it was (who knows, he may have been thinking it was a “4 loop”.)

Interview 2

This guy seems pretty sharp, and I thought he’d easily write the function we asked for. He knew what he wanted to do, but couldn’t remember the math operator to do it. “Mod? Square root?”, he muttered.

After a few minutes he came up with this bloat, where he rolled out his own test for mod equalling 0. He almost got the function right. As a point of comparison, the function can be done in C# in 5 lines, 7 if you count the braces.

Roll your own mod

We reminded him of what the mod operator does, and had a chuckle over it. I told him that if we hired him, I’d frame his solution above his desk. Er, cubicle.

Post navigation

❮ Previous Post: Gender, please
Next Post: Get away from me, Rainmaker! ❯

7 thoughts on “Interviews”

  1. l3rucewayne says:
    September 27, 2007 at 2:33 am

    I am a definite amateur at programming, all I learned was from parts of a book on 2-d game programming, and since i haven’t done any coding in a while this will be pseudo code. (i have done some coding but not much, im most proud of my kitchen timer program, drawing programs[very very basic ones] and a very messed up text based rpg with some graphics and sound. i liked the last best the second second best.) this is my probably not so good attempt at answering the question. took a few minutes so probably did worse than all of you’r interviewers, but still seemed like a fun thing to try:

    number variable = 0

    begin loop here

    add 1 to “number”

    If number>100 then waitkey and end program

    If number divided by 3 = a whole number ;(not sure how to check for that, maybe could figure out a lengthy way to do it if i cared more.)
    then print “foo” and go to label#1 if not then go to label#2

    if number divided by 5 = a whole number then print “bar” and go to lable#1 if not then go to label#2

    if number divided by 3 = a whole number andif number divided by 5 = a whole number then print “foobar” and go to label#1 if not then go to label#2

    Label#2
    print number
    label#1

    end loop here ;i think “wend” is the term i recall.

    Reply
  2. Donnie says:
    September 27, 2007 at 5:52 am

    Wend! Sounds like old-school BASIC! You can check for divisibility using Mod, which returns the remainder after division (well, for positive numbers)

    10 Mod 4 = 2
    10 Mod 5 = 0

    You did a lot better than the first guy, who essentially handed in a blank sheet of paper. And it’s almost right.

    Interestingly, both you and Interview 2 made the same mistake of checking for the divide by 15 last. It actually should be checked first (I’ll let you figure out why that needs to be the case).

    Reply
  3. Allen says:
    September 27, 2007 at 9:39 am

    Wait. Why divide by 15 at all? If something is divisible by both 3 and 5, isn’t it divisible by 15 then? If so, then you don’t need to do a seperate calculation.

    for( int i = 1; i < 101; i++ ){ string Result = ""; if( i % 3 == 0 ) Result = "foo"; if( i % 5 == 0 ) Result += "bar"; Result = "" ? console.writeline(i) : console.writeline (Result); }

    Reply
  4. l3rucewayne says:
    September 27, 2007 at 7:02 pm

    ahh good point, if it is divisible by 3 or five then it will immediately print foo or bar when it could be divisible by both and should print foobar. it was a fun try anyway.
    so i guess to use mod to check it it would be like: if number mod 3 = 0 andif number mod 5 = 0 then etc.?

    The programming language i learned from was specifically made for making games, called blitz basic. mostly 2d games it seems so you are right it probably is pretty old. Doing this makes me want to learn more programming again, i once tried to find a free compiler that would work well with some free online programming lessons i found but i couldnt figure somethings out about the compiler for some reason. maybe someday ill just buy a book that comes with a compiler.

    p.s. do all numbers divisible by both 3 and 5 also divisible by 15? guess i have forgotten some algebra.

    Reply
  5. Donnie says:
    September 28, 2007 at 9:24 am

    If the language has a way to print characters without printing a new line, Allen was right about not having to check for 15 at all.

    The solution would be something like this:

    for i = 1 to 100
    printnumber = true

    if (i mod 3 = 0) then
    print “foo”
    printnumber = false
    end if
    if (i mod 5 = 0) then
    print “bar”
    printnumber = false
    end if

    if printnumber = true then
    print i
    end if

    print [newline character]
    end for loop

    (Or, it can be done in 5 lines as Allen did, but Basic doesn’t have all the stuff that C# does.)

    On the other hand, if the print command always attaches a newline character at the end, you have to check for 15 separately (I don’t know if this was the case for Blitz Basic.)

    PS: Yes. All numbers divisible by two numbers is divisible by the product of those numbers.

    Reply
  6. Derek Slater says:
    September 28, 2007 at 11:11 pm

    Donnie – I lack any knowledge of programming so I never have anything substantive to note on these interview posts, but the whole thing is utterly fascinating so I hope you’ll keep going.

    Reply
  7. l3rucewayne says:
    September 28, 2007 at 11:43 pm

    thx, can’t believe i forgot about end if. would have used it incorrectly anyway probably.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • 2020 was so bad, we didn’t make a single post
  • Monday Fighter!
  • King Safety
  • So, no rematch?
  • Estimate how much this cost

Recent Comments

  • annie on 2020 was so bad, we didn’t make a single post
  • annie on One could argue he’d make a poor preacher
  • annie on Monday Fighter!
  • Q on Monday Fighter!
  • annie on Monday Fighter!

Archives

  • January 2021
  • February 2019
  • November 2018
  • September 2018
  • June 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • August 2016
  • July 2016
  • June 2016
  • March 2016
  • September 2015
  • August 2015
  • May 2015
  • April 2015
  • August 2014
  • July 2014
  • April 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • October 2013
  • September 2013
  • August 2013
  • July 2013
  • June 2013
  • April 2013
  • March 2013
  • January 2013
  • December 2012
  • November 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • July 2011
  • June 2011
  • May 2011
  • April 2011
  • March 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007

Categories

  • Babes & Alleged Babes
  • Bad Ads
  • Bad Movie Night
  • Blog News
  • Burning Agony
  • CG
  • Chess
  • Computer-fu
  • Corridors & Creatures
  • Eggony
  • Eggs Vs Humans
  • Entertainment
  • Gaming
  • Grilled Cheese
  • History
  • In the News
  • Mascot for President
  • Mathematics
  • Monday Fighter!
  • North Korea
  • Patently Ineffective
  • Random
  • Religion
  • Science/Technology
  • Snake Oil
  • Sports
  • Tournament of Lepers
  • Uncategorized
  • Uncomfortability
  • Weaksauce Losers

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Copyright © 2021 Liquid Egg Product.

Theme: Oceanly by ScriptsTown