Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi all, we have some important news to share. Please follow the link here to find out more!

https://www.boards.ie/discussion/2058419143/important-news/p1?new=1

Developer Applicant Suitability

2

Comments

  • Registered Users, Registered Users 2 Posts: 12,012 ✭✭✭✭Giblet


    Well if you want efficiency, you might as well hardcode the output as it's a constant B)


  • Registered Users, Registered Users 2 Posts: 221 ✭✭Elfman


    For cnt = 0 To 100
    printme = ""
    printme &= IIf(i Mod 3 = 0, "FIZZ", "")
    printme &= IIf(i Mod 5 = 0, "BUZZ", "")
    Console.WriteLine(printme & " - " & cnt)
    Next


  • Registered Users, Registered Users 2 Posts: 9,153 ✭✭✭everdead.ie


    Elfman wrote: »
    For cnt = 0 To 100
    printme = ""
    printme &= IIf(i Mod 3 = 0, "FIZZ", "")
    printme &= IIf(i Mod 5 = 0, "BUZZ", "")
    Console.WriteLine(printme & " - " & cnt)
    Next
    I like this implementation but if people can't create a single for loop with 2/3 if else statements surely that's a problem.


  • Registered Users, Registered Users 2 Posts: 2,088 ✭✭✭henryporter


    Funny how the thrown gauntlet has been accepted by most of the posters (including me) per the follow up article on Coding Horror: http://www.codinghorror.com/blog/2007/02/fizzbuzz-the-programmers-stairway-to-heaven.html :D


  • Registered Users, Registered Users 2 Posts: 1,657 ✭✭✭komodosp


    Elfman wrote: »
    For cnt = 0 To 100
    printme = ""
    printme &= IIf(i Mod 3 = 0, "FIZZ", "")
    printme &= IIf(i Mod 5 = 0, "BUZZ", "")
    Console.WriteLine(printme & " - " & cnt)
    Next

    You're not supposed to print the number if "Fizz" or "buzz" or "fizzbuzz" is being printed...


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭oeb


    Just to be annoying, PHP.

    [PHP]for($i=1;$i<=100;$i++){$o='';$o.=!($i%3)?'Fizz':'';$o.=!($i%5)?'Buzz':'';$o=!$o?$i:$o;echo $o.'<br />';}[/PHP]


  • Registered Users, Registered Users 2 Posts: 1,477 ✭✭✭azzeretti


    And in Perl (I like these tests - any more!?)
    my @numbers = (1..100);
            foreach my $i (@numbers)
              {
                my $res3 = $i/3;
                my $res5 = $i/5;
                    if($res3 =~ /^\d+$/ && $res5 =~ /^\d+$/) {print "FizzBuzz for $i\n"}
                        elsif($res3 =~ /^\d+$/)
                         {print "Fizz for $i\n";}
                        elsif($res5 =~/^\d+$/)
                        {print "Buzz for $i\n"}
                        else {print "$i\n"}
    }
    
    
    


  • Registered Users, Registered Users 2 Posts: 40,038 ✭✭✭✭Sparks


    Just to be really annoying, can I give y'all the second part of the FizzBuzz test (the one that really counts at any company that does any sort of real product)?

    Here it is : Document your solution.

    You'd be horrified at how many grads can't do this, but honestly, every time someone on here asks "what programming language should I study to boost my career", the very first one that always jumps to mind is English. Because if you don't document it, you'll probably come across it in a Coding Horrors thread or WTF post someday...


  • Registered Users, Registered Users 2 Posts: 1,311 ✭✭✭Procasinator


    Sparks wrote: »
    Just to be really annoying, can I give y'all the second part of the FizzBuzz test (the one that really counts at any company that does any sort of real product)?

    Here it is : Document your solution.

    You'd be horrified at how many grads can't do this, but honestly, every time someone on here asks "what programming language should I study to boost my career", the very first one that always jumps to mind is English. Because if you don't document it, you'll probably come across it in a Coding Horrors thread or WTF post someday...

    Out of curiosity, how would you document the solution? It's such as simple task, the most I would document is the why not the how. And for FizzBuzz, there is no why except for because you were asked too.

    Why would you want to document the modulus operator, when the language reference already does?


  • Registered Users, Registered Users 2 Posts: 40,038 ✭✭✭✭Sparks


    Out of curiosity, how would you document the solution?
    Mod note: This developed into a good but divergent thread of it's own, so I've split it out to here...


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭oeb


    On a similar line to the FizzBuzz test, but also showing a bit of an ability to think outside the box, I saw an interview question online yesterday that went something along the lines of.
    Write a short function in the language of your choice. When given one integer, it must return the square of that number. You may NOT use the multiplication operator or any math functions that your language may provide.

    There are a couple of ways to do this.


  • Registered Users, Registered Users 2 Posts: 1,922 ✭✭✭fergalr


    oeb wrote: »
    On a similar line to the FizzBuzz test, but also showing a bit of an ability to think outside the box, I saw an interview question online yesterday that went something along the lines of.
    Write a short function in the language of your choice. When given one integer, it must return the square of that number. You may NOT use the multiplication operator or any math functions that your language may provide.

    There are a couple of ways to do this.


    return input^2


  • Registered Users, Registered Users 2 Posts: 1,922 ✭✭✭fergalr


    My point is that, in addition to its vagueness, I don't really like the question.


    The point of FizzBizz is to be the most casual filter possible: ask something that anyone who can code *has* to be able to do.


    This question is going to be off the beaten track for a lot of general developers. Like, when would they ever not have a multiply operator?


    Do they want the candidate to make a binary multiplier using bitwise operations in C? That's kind of error prone, and a PITA thing to do in an interview. It demonstrates a detailed knowledge of bitwise operations, if that's a particularly desirable quality; great question for someone working with embedded systems, but I'm not sure you need that in a general developer these days.


    I can think of a load of other stupid ways to solve the problem, too, using the division operator; building lookup tables; defining a language so trivial the only numbers in it are 0 and 1; etc.

    Maybe there's some solution I've overlooked that they are looking for; if so, my point stands; I'm not a fan of 'ah-ha' questions.


  • Closed Accounts Posts: 2,256 ✭✭✭Molly


    I think you're over complicating it a bit. I wasn't sure was this supposed to work for negative numbers so I made it work with them anyway. I actually think it's a decent enough test for problem solving. I also believe that a lot of software development is asking the correct questions before you dive headfirst into things so a developer being interviewed and asked about the negative numbers would to me show some sign of 'looking before they leaped'
    	public int square(int number){
    		int copyOfNumber = 0;
    		
    		if(number >  -1){
    			copyOfNumber = number;  
    		} else {
    			copyOfNumber = 0 - number;
    			number = copyOfNumber;
    		}
    
    		for(int i=1;i<copyOfNumber;i++){
    			number += copyOfNumber;
    		}
    		return number;
           }
    


  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭oeb


    The quick and dirty approach that I would have taken to the question myself would have been:

    [PHP]
    function squareMe($x) {
    return $x / (1/$x);
    }
    [/PHP]


  • Closed Accounts Posts: 2,256 ✭✭✭Molly


    I like that. It's really simple


  • Registered Users, Registered Users 2 Posts: 7,157 ✭✭✭srsly78


    It's a stupid gimmick question. You can't use multiplication but you can use everything else? Division is just multiplication by the inverse so it's stupid. Compiler would turn divide into inverse multiply anyway -.-

    Most likely they expect the candidate to use bitwise operations or something.

    I interviewed for a position in London last summer, HR drone placed a sheet fully of the usual stupid questions in front of me and told me I had an hour to complete the test. Questions were stuff like "write heapsort" and so on. I last studied that stuff in the 90s.... No I cannot remember heapsort!! Yeah you gotta make a "heapify" function lalala. Anyway, I just got up and said "Thank you for your time", and left. This is not how you interview a developer with 10+ years of experience -.-

    Contrast to next interview (for financial consultancy). Phone interview first, guys described the specific problem they wanted to hire someone to solve. I flew over for face-to-face interview, brought laptop with demo of a rough solution to what they wanted. Wallop -> instantly employed. No HR drones in sight.


  • Registered Users, Registered Users 2 Posts: 1,477 ✭✭✭azzeretti


    oeb wrote: »
    The quick and dirty approach that I would have taken to the question myself would have been:

    [PHP]
    function squareMe($x) {
    return $x / (1/$x);
    }
    [/PHP]

    Didn't it say you can use any mathmatical functions?


  • Registered Users, Registered Users 2 Posts: 7,157 ✭✭✭srsly78


    Yeah but it's very vague. They mean functions like pow(x, 2) I suppose. + - etc are operators not functions.


  • Registered Users, Registered Users 2 Posts: 1,922 ✭✭✭fergalr


    azzeretti wrote: »
    Didn't it say you can use any mathmatical functions?

    Well, this depends on the semantics you wish to attach to 'function' vs 'operator'.
    So you can answer trivially by choosing a language with an exponentiation operator and saying 'well this isn't multiplication', or a function.

    Which I think is a silly answer to a silly question.

    Molly wrote: »
    I think you're over complicating it a bit. I wasn't sure was this supposed to work for negative numbers so I made it work with them anyway. I actually think it's a decent enough test for problem solving. I also believe that a lot of software development is asking the correct questions before you dive headfirst into things so a developer being interviewed and asked about the negative numbers would to me show some sign of 'looking before they leaped'
        public int square(int number){
            int copyOfNumber = 0;
            
            if(number >  -1){
                copyOfNumber = number;  
            } else {
                copyOfNumber = 0 - number;
                number = copyOfNumber;
            }
    
            for(int i=1;i<copyOfNumber;i++){
                number += copyOfNumber;
            }
            return number;
           }
    
    This produces the correct result, but is linear in input size.
    Getting the square of a billion will take a while; implementing a bitwise binary multiplier is a better solution, although a PITA.

    srsly78 wrote: »
    It's a stupid gimmick question. You can't use multiplication but you can use everything else? Division is just multiplication by the inverse so it's stupid. Compiler would turn divide into inverse multiply anyway -.-


    I agree its a stupid gimmick question.
    oeb wrote: »
    The quick and dirty approach that I would have taken to the question myself would have been:

    [PHP]
    function squareMe($x) {
    return $x / (1/$x);
    }
    [/PHP]


    I'm not sure about the turning divide into inverse multiply - it said you had to take an integer - it didn't say whether it was integer multiplication, but if it was, there's a difference.


    Probably the best solution (fastest, non-trivial) to the problem would be to use float inverse division (assuming thats allowed), and then search near the solution for what the correct integer value would have been.

    There was a question in the facebook hacker cup that had to be solved in that sort of way.

    If thats not allowed, binary multiplier - but meh.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 16,415 ✭✭✭✭Trojan


    srsly78 wrote: »
    Contrast to next interview (for financial consultancy). Phone interview first, guys described the specific problem they wanted to hire someone to solve. I flew over for face-to-face interview, brought laptop with demo of a rough solution to what they wanted. Wallop -> instantly employed. No HR drones in sight.

    Super. Something I always recommend to people after reading this book years ago: do the job in the interview. Won't work for everyone, but if you've enough experience and confidence to steer the interview to that, it will pay off hugely.


  • Registered Users, Registered Users 2 Posts: 1,311 ✭✭✭Procasinator


    A shift and add implementation (JavaScript):
    function square(x)
    {
    	var r = 0;
    	if (x < 0) x = -x;
    	var y = x;
    	for(;y!=0;x=x<<1,y=y>>1)
    		if (y&1) r += x;
    	return r;
    }
    

    But I agree, it would be a silly question for most interviews.


  • Closed Accounts Posts: 4,564 ✭✭✭Naikon


    I would do the following in an interview. I am aware you can't use the multiplication operator, mind you. I am aware recursion is not very stack friendly.
    #include <stdio.h>
    #include <stdlib.h>
    int raise(unsigned int, int);
    
    int main(int argc, char *argv[])
    {
        if(argc != 3)
        {
            printf("Enter 3 args exactly, dummy!\n");
            return -1;
        }
        printf("%5d\n", raise(atoi(argv[1]), atoi(argv[2])));
        return 0;
    }
    
    int raise(unsigned int base, int exp)
    {
        if(exp >= 1)
        {
            return base * (raise(base, exp -1));
        }
        else return 1;
    }
    


  • Closed Accounts Posts: 4,564 ✭✭✭Naikon


    Right, onto more questions. How would you reverse an integer array in an interview? As simple as possible.

    I will start...
    #include <stdio.h>
    #define LENGTH 6
    int reverse(int *ptr, int length);
    
    int main(int argc, char *argv[]) {
            int array[LENGTH] = { 5,4,3,2,1,0 };
            reverse(array, LENGTH-1);
            return 0;
    }
    
    int reverse(int *ptr, int length) {
            if (length == 0) {
                    printf("%d\n", ptr[length]);
                    return 0;
            }
            printf("%d\n", ptr[length]);
            reverse(ptr, length-1);
            return 1;
    }
    


  • Registered Users, Registered Users 2 Posts: 89 ✭✭tehjimmeh


    That doesn't reverse an array, it prints an array in reverse.

    C:
    int * rev(int * arr, int len)
    {
       int * res = malloc(sizeof(int)*len);
       int * temp = res;
       while(len--)
          *(temp++) = arr[len];
    
       return res;
    }
    

    Haskell:
    rev = foldl (flip (:)) []
    


  • Closed Accounts Posts: 4,564 ✭✭✭Naikon


    tehjimmeh wrote: »
    That doesn't reverse an array, it prints an array in reverse.

    C:
    int * rev(int * arr, int len)
    {
       int * res = malloc(sizeof(int)*len);
       int * temp = res;
       while(len--)
          *(temp++) = arr[len];
    
       return res;
    }
    

    Haskell:
    rev = foldl (flip (:)) []
    

    That is what I was meant to say:P

    These haskell higher order functions are pretty compact. How would you go about reversing the array without using a temporary portion of Heap mem? Standard malloc() isn't something you really want on an embedded system.


  • Registered Users, Registered Users 2 Posts: 89 ✭✭tehjimmeh


    Well, it's done easily enough in place:
    void rev2(int * arr, int len)
    {
       len--;
       int i;
       for(i = 0; len > i ; len--, i++)
       {
          swap(&arr[len], &arr[i]);
       }
    }
    

    swap() could be:
    void swap(int * x, int * y)
    {
       int temp = *x;
       *x = *y;
       *y = temp;
    }
    

    or maybe...
    void swap(int * x, int * y)
    {
       asm volatile ("xchgl %0, %1;\n"
                            :"=r"(*x), "=r"(*y)
                            :"0"(*x), "1"(*y));
    }
    
    etc.


  • Closed Accounts Posts: 4,564 ✭✭✭Naikon


    tehjimmeh wrote: »
    Well, it's done easily enough in place:
    void rev2(int * arr, int len)
    {
       len--;
       int i;
       for(i = 0; len > i ; len--, i++)
       {
          swap(&arr[len], &arr[i]);
       }
    }
    

    swap() could be:
    void swap(int * x, int * y)
    {
       int temp = *x;
       *x = *y;
       *y = temp;
    }
    

    or maybe...
    void swap(int * x, int * y)
    {
       asm volatile ("xchgl %0, %1;\n"
                            :"=r"(*x), "=r"(*y)
                            :"0"(*x), "1"(*y));
    }
    
    etc.

    I had the inclination you would not use the XOR swap:pac:

    Gotta come up with some better questions I think...


  • Registered Users, Registered Users 2 Posts: 1,657 ✭✭✭komodosp


    Yeah but it's very vague. They mean functions like pow(x, 2) I suppose. + - etc are operators not functions.
    Aha, but now you have a problem. Given that you are writing it out and handing it to the interviewer and not discussing it, you have to trust the interviewer to know the difference.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 7,157 ✭✭✭srsly78


    Nah not really. If I got presented questions like that I would say "fook this" and leave :)


Advertisement