• tragomaskhalos (unregistered) in reply to hoodaticus
    hoodaticus:
    I once interviewed a "C++ programmer" who couldn't pass FizzBuzz. He didn't even know how to do logical negation (!).

    Less amusing, I had an assembly programmer who did pass it, but without using the mod operator or even attempting to roll his own. He had to use string conversion and tested for the decimal point.

    Oh yes the old string conversion bodge - once reviewed some ASP code that had to alternate the colours of rows in a list; the guy had accomplished this by converting the row number to a float, dividing by 2, stringising, then picking the colour based on the presence or absence of a decimal point. Happily he's a big management wheel now, so out of harm's way !

  • Fat (unregistered) in reply to QJo

    That's not a matter of belief. The magnitude of fibonacci numbers F(n) grows exponentially with n (it's almost ((sqrt(5)+1)/2)^2), therefore their length grows lineary with n. So, to add two numbers F(n) you need O(n) operations, and to multiply - about O(n*log(n)), as far as I know.

  • Yitscar (unregistered) in reply to Fat

    Thanks for bringing up the magnitude problem. I've been trying to explain that to the hash table guys on wikipedia (http://en.wikipedia.org/wiki/Talk:Hash_table#Look_up_is_not_O.281.29_at_all) : if your number of elements becomes large enough, you'll have to use a key of O(log(n)) bits, and its manipulation will take a time of O(log n), not O(1)

  • (cs) in reply to gnasher729
    gnasher729:
    boog:
    Calculating fibonacci numbers in O(log(n)) is what I'd call interesting.

    That would indeed by interesting, but since the result has a size of O(n), it is not possible.

    This.
  • Makky (unregistered)

    Reverse a string by swapping leftside with rightside.

    String s = "ReverseMePlease"; int left = 0; int right = s.length() - 1; char[] c = s.toCharArray();

    while(left < right) { char tmp = c[left]; c[left] = c[right]; c[right] = tmp; left++; right--; }

    return new String(c);

  • (cs) in reply to Yitscar
    Yitscar:
    Thanks for bringing up the magnitude problem. I've been trying to explain that to the hash table guys on wikipedia (http://en.wikipedia.org/wiki/Talk:Hash_table#Look_up_is_not_O.281.29_at_all) : if your number of elements becomes large enough, you'll have to use a key of O(log(n)) bits, and its manipulation will take a time of O(log n), not O(1)
    I think I agree with your opponents there.
  • (cs) in reply to resmoker10
    resmoker10:
    Sylver:
    Love it too, but how about:

    public bool learn(recursion) { if (!understand(recursion)) { learn(recursion); } return true; }

    that just causes a stack overflow

    NICE!

  • veggen (unregistered)

    I'm absolutely certain the last story had already appeared on this site before... I remember the "it's an idea floating around" comment.

  • (cs) in reply to Dave
    Dave:
    Hanoi 4 ever:
    dohpaz42:
    WC:
    No, it's the John Galt from Atlas Shrugged.

    I read that code snippet and thought, "Is that really a recursive function to reverse a string?" ... Yup, apparently it is. Wow.

    Reversing a string is a simple analogy for describing recursive functions. It's an easy concept to understand, and just as simple to implement, and it demonstrates recursion in an easy to understand way. Usually this sort of exercise is done in a beginner programming class (at least, it was for me back when I took beginning programming in college).

    Reversing a string is a poor example of recursion, as it's so obviously easier to do with a loop. Use something like quicksort or a tree-traversal.

    That would be horribly inefficient. I bet I could train a finite-context automaton to do that far more quickly than your tree-walk could do it.

    BEST BURN EVER! Tchshhhhhhhhh.

  • (cs) in reply to gnasher729
    gnasher729:
    boog:
    Calculating fibonacci numbers in O(log(n)) is what I'd call interesting.

    That would indeed by interesting, but since the result has a size of O(n), it is not possible.

    Sorry, calculating a number in the fibonacci sequence in O(log(n)) would be interesting.

    Sorry everybody.

  • you know who (unregistered) in reply to boog
    boog:
    gnasher729:
    boog:
    Calculating fibonacci numbers in O(log(n)) is what I'd call interesting.

    That would indeed by interesting, but since the result has a size of O(n), it is not possible.

    Sorry, calculating a number in the fibonacci sequence in O(log(n)) would be interesting.

    Sorry everybody.

    public int fib(int n){
        double sqrt5 = Math.sqrt(5);
        double termOne = Math.pow((1+sqrt5), n);
        double termTwo = Math.pow((1-sqrt5), n);
        return (int)((termOne + termTwo)/(2 * sqrt5));
    }
    
    public void fibSeq()
    {
        for (int n = 0; n < 100; ++n)
            System.out.println(fib(n));
    }
    
  • (cs) in reply to boog
    boog:
    gnasher729:
    boog:
    Calculating fibonacci numbers in O(log(n)) is what I'd call interesting.

    That would indeed by interesting, but since the result has a size of O(n), it is not possible.

    Sorry, calculating a number in the fibonacci sequence in O(log(n)) would be interesting.
    O(1) would be even more interesting.
  • you know who (unregistered) in reply to you know who
    you know who:
    boog:
    gnasher729:
    boog:
    Calculating fibonacci numbers in O(log(n)) is what I'd call interesting.

    That would indeed by interesting, but since the result has a size of O(n), it is not possible.

    Sorry, calculating a number in the fibonacci sequence in O(log(n)) would be interesting.

    Sorry everybody.

    public int fib(int n){
        double sqrt5 = Math.sqrt(5);
        double termOne = Math.pow((1+sqrt5), n);
        double termTwo = Math.pow((1-sqrt5), n);
        return (int)((termOne - termTwo)/(2 * sqrt5));
    }
    
    public void fibSeq()
    {
        for (int n = 0; n < 100; ++n)
            System.out.println(fib(n));
    }
    

    whoops

  • Fat (unregistered) in reply to you know who
    you know who:
    you know who:
    boog:
    gnasher729:
    boog:
    Calculating fibonacci numbers in O(log(n)) is what I'd call interesting.

    That would indeed by interesting, but since the result has a size of O(n), it is not possible.

    Sorry, calculating a number in the fibonacci sequence in O(log(n)) would be interesting.

    Sorry everybody.

    public int fib(int n){
        double sqrt5 = Math.sqrt(5);
        double termOne = Math.pow((1+sqrt5), n);
        double termTwo = Math.pow((1-sqrt5), n);
        return (int)((termOne - termTwo)/(2 * sqrt5));
    }
    
    public void fibSeq()
    {
        for (int n = 0; n < 100; ++n)
            System.out.println(fib(n));
    }
    

    whoops

    I think if you'd actually tried and execute this code, you'd understand it has at least one error.

  • Fat (unregistered) in reply to Fat

    And even if this code was right, this pinciple would give you O(n*log(n)) time for really large n (starting from 100 or so), at least if you wanted to calculate exact value of fibonacci number, not approximate.

  • (cs) in reply to you know who
    you know who:
    you know who:
    boog:
    gnasher729:
    boog:
    Calculating fibonacci numbers in O(log(n)) is what I'd call interesting.

    That would indeed by interesting, but since the result has a size of O(n), it is not possible.

    Sorry, calculating a number in the fibonacci sequence in O(log(n)) would be interesting.

    Sorry everybody.

    public int fib(int n){
        double sqrt5 = Math.sqrt(5);
        double termOne = Math.pow((1+sqrt5), n);
        double termTwo = Math.pow((1-sqrt5), n);
        return (int)((termOne - termTwo)/(2 * sqrt5));
    }
    
    public void fibSeq()
    {
        for (int n = 0; n < 100; ++n)
            System.out.println(fib(n));
    }
    

    whoops

    "Whoops" indeed - you failed to understand the amended comment and went and generated a list of numbers.

    As fake frits would say, "your[sic] not too bright, are you?"

  • you know who (unregistered) in reply to Fat
    Fat:
    you know who:
    you know who:
    boog:
    gnasher729:
    boog:
    Calculating fibonacci numbers in O(log(n)) is what I'd call interesting.

    That would indeed by interesting, but since the result has a size of O(n), it is not possible.

    Sorry, calculating a number in the fibonacci sequence in O(log(n)) would be interesting.

    Sorry everybody.

    public int fib(int n){
        double sqrt5 = Math.sqrt(5);
        double termOne = Math.pow((1+sqrt5), n);
        double termTwo = Math.pow((1-sqrt5), n);
        return (int)((termOne - termTwo)/(2 * sqrt5));
    }
    
    public void fibSeq()
    {
        for (int n = 0; n < 100; ++n)
            System.out.println(fib(n));
    }
    

    whoops

    I think if you'd actually tried and execute this code, you'd understand it has at least one error.

    0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 3524578 5702887 9227465 14930352 24157817 39088169 63245986 102334155 165580141 267914296 433494437 701408733 1134903170 1836311903 2147483647 2147483647 2147483647 2147483647 2147483647 2147483647 ...several more 2147483647's ...

  • (cs) in reply to hoodaticus
    hoodaticus:
    boog:
    Sorry, calculating a number in the fibonacci sequence in O(log(n)) would be interesting.
    O(1) would be even more interesting.
    Indeed. I once saw a C++ implementation of fibonacci numbers that used macros to unroll for-loops, so it could calculate fibonacci numbers at compile time. Sure, not O(1) when compiling, but O(1) at run-time.
  • you know who (unregistered) in reply to boog
    boog:
    you know who:
    you know who:
    boog:
    gnasher729:
    boog:
    Calculating fibonacci numbers in O(log(n)) is what I'd call interesting.

    That would indeed by interesting, but since the result has a size of O(n), it is not possible.

    Sorry, calculating a number in the fibonacci sequence in O(log(n)) would be interesting.

    Sorry everybody.

    public int fib(int n){
        double sqrt5 = Math.sqrt(5);
        double termOne = Math.pow((1+sqrt5), n);
        double termTwo = Math.pow((1-sqrt5), n);
        return (int)((termOne - termTwo)/(2 * sqrt5));
    }
    
    public void fibSeq()
    {
        for (int n = 0; n < 100; ++n)
            System.out.println(fib(n));
    }
    

    whoops

    "Whoops" indeed - you failed to understand the amended comment and went and generated a list of numbers.

    As fake frits would say, "your[sic] not too bright, are you?"

    What, would you say, is the complexity of the fib function?

  • (cs) in reply to EvanED
    EvanED:
    boog:
    Actually, no, your problem is not very neat at all. Asking for fibonacci numbers in O(n) using recursion is boring, because it's trivial to achieve O(n) with a simple loop, so the recursion is an unnecessary requirement.

    Calculating fibonacci numbers in O(log(n)) is what I'd call interesting.

    I have three objections to that statement.

    First, your proposed problem is interesting in a very different way -- much more of a "mathy" interesting, and not really a "programming" interesting. That's not bad by any means, but it is different and at least for me appeals to a very different part of my mind.

    Fair enough, but this challenge actually has a point: improved performance. In order to improve performance of any algorithm, a programmer will most likely need to use math.

    EvanED:
    Second, you say "a simple loop", but what if you're writing Fibonacci in a functional language? Then that "simple loop" suddenly becomes much more difficult, and the recursive expression is very natural.
    Also fair. I don't use a lot of functional languages (only one, and not very much). In that case, the problem is much more "functional-language" interesting, and not at all "imperative-language" interesting. Like my O(log(n)) problem, it's apparently being marketed to the wrong audience.
    EvanED:
    Third, so what if it's somewhat of an artificial requirement? That doesn't make it uninteresting. Most people add lots artificial requirements on a regular basis. I rock climb. That doesn't become uninteresting because the "go up the rock instead of walking up that trail" is unnecessary.
    Also fair. I often forget that some people like to have fun. I should get out more. Consider that part of my comment taken back.
  • (cs) in reply to you know who
    you know who:
    What, would you say, is the complexity of the fib function?
    What, would you say, is the point of the fibSeq() function? Or the comment "whoops"?
  • you know who (unregistered) in reply to boog
    boog:
    you know who:
    What, would you say, is the complexity of the fib function?
    What, would you say, is the point of the fibSeq() function? Or the comment "whoops"?
    And you have the audacity to imply I'm not too bright.
  • (cs) in reply to Hortical
    Hortical:
    Sutherlands:
    Psuedocode:

    foreach(letter in string) StringBuilder.AppendFront(letter)

    Consider the possibility that the StringBuilder uses a char[] internally.

    Consider the possibility that every time you insert a char at the beginning, all the other chars that have been added have to be moved over a space. Every time.

    Consider the possibility that this is pseudocode.

  • Fat (unregistered) in reply to you know who

    That is strange, since

    import java.util.*;
    import java.lang.*;
     
    class Main
    {
     
    public static int fib(int n){
        double sqrt5 = Math.sqrt(5);
        double termOne = Math.pow((1+sqrt5), n);
        double termTwo = Math.pow((1-sqrt5), n);
        return (int)((termOne - termTwo)/(2 * sqrt5));
    }
     
     
     
    public static void fibSeq()
    {
        for (int n = 0; n < 10; ++n)
            System.out.println(fib(n));
    }
     
            public static void main (String[] args) throws java.lang.Exception
            {
                    fibSeq();
            }
    }
    

    gave me

    0 1 2 8 24 80 256 832 2688 8704

    Doesn't look like fibonacci sequence at all.

  • (cs)

    Converting a string from (7-bit) ASCII to (invariant) EBCDIC and back shouldn't result in any loss of information, as long as it doesn't contain any characters outside of the set 1234567890-=@%&*()_+qwertyuiopQWERTYUIOP|asdfghjkl;'ASDFGHJKL:"zxcvbnm,.ZXCVBNM<>? and regular space.

  • (cs) in reply to resmoker10
    resmoker10:
    Sylver:
    Love it too, but how about:

    public bool learn(recursion) { if (!understand(recursion)) { learn(recursion); } return true; }

    that just causes a stack overflow

    Ok, how about: public bool learn(recursion) { if(understand(recursion)) return true; return learn(recursion) }

  • Jay (unregistered) in reply to dohpaz42
    dohpaz42:
    Recursion is usually a precursor to larger algorithms, such as sorting. If you can't understand recursion, you have no hope of quick sort or tree traversal.

    And if you can't understand recursion, you have no hope of understanding recursion.

    (Sorry, I couldn't help it.)

  • (cs) in reply to you know who
    you know who:
    boog:
    you know who:
    What, would you say, is the complexity of the fib function?
    What, would you say, is the point of the fibSeq() function? Or the comment "whoops"?
    And you have the audacity to imply I'm not too bright.
    That's unfair. In no way did I ever imply such a thing.

    However, I did say it quite explicitly.

  • Jay (unregistered) in reply to Nebler
    Nebler:
    Jeff:
    What about improvements to the recursive string reversal code?

    I'm thinking:

    1. First choice, use any built in library functions since they're already coded, tested, and optimized.

    2. Don't use recursion since that's a lot of overhead and you could get a possible stack overflow if the string was long. (Can you even get stack overflows in C#? I honestly haven't had one in many many years).

    3. As a coding exercise, off the top of my head I'd probably use a one character buffer and swap characters from the outside to the inside. Ala:

    strToRev="CodeTest";

    for(int i=0; i< strToRev.length() / 2; i++) { int farCharPosition = strToRev.length()-i-1; char buf = strToRev[farCharPosition]; strToRev[farCharPosition] = strToRev[i]; strToRev[i] = buf; }

    Thoughts?

    1. Is the only correct option. Always use unicode-aware methods, like string.reverse. All your surrogate pairs will die otherwise. The code in the interview gets this wrong as well.

    What language are we supposing here? A Java string is a collection of chars, i.e. code points, not of bytes. So you don't need to worry about breaking the Unicode sequences when doing char manipulation.

  • SCB (unregistered) in reply to you know who
    you know who:
    boog:
    gnasher729:
    boog:
    Calculating fibonacci numbers in O(log(n)) is what I'd call interesting.

    That would indeed by interesting, but since the result has a size of O(n), it is not possible.

    Sorry, calculating a number in the fibonacci sequence in O(log(n)) would be interesting.

    Sorry everybody.

    public int fib(int n){
        double sqrt5 = Math.sqrt(5);
        double termOne = Math.pow((1+sqrt5), n);
        double termTwo = Math.pow((1-sqrt5), n);
        return (int)((termOne + termTwo)/(2 * sqrt5));
    }
    
    public void fibSeq()
    {
        for (int n = 0; n < 100; ++n)
            System.out.println(fib(n));
    }
    

    But that calculates them in O(1). You need to add: sleep(log(n));

  • Jay (unregistered) in reply to SG_01
    SG_01:
    Fat:
    I don't really like this joke. It'n not a legitiamte use of recursion, it's just an infinite loop. Of course, it doesn't defeat its real purpose, make beginner programmers feel superior to anyone who didn't spend 2 hours studying algorithms.

    It's actually NOT an infinite loop. Back to school ^^

    That's what happens when you fail to spend at least 2 hours studying algorithms.

  • (cs) in reply to SCB
    SCB:
    But that calculates them in O(1). You need to add: sleep(log(n));
    Really? If n changed to 1000 or 10000, fibSeq would run in the same amount of time?

    Interesting...

  • (cs) in reply to Jay
    Jay:
    What language are we supposing here? A Java string is a collection of chars, i.e. code points, not of bytes. So you don't need to worry about breaking the Unicode sequences when doing char manipulation.
    Look up combining characters. There are single "logical characters" (that's probably not a real term) that are represented by multiple code points. Or see the second question here. (It uses "grapheme" for something that approximates my "logical character." I'm not sure if it's exactly the same as what I have in mind.)

    I don't know whether surrogate pairs enter the picture here or not.

  • Jay (unregistered)

    On a mildly serious note: To all those saying that the "right answer" is to use a built-in reverse function:

    If I was applying for a job and the interviewer asked me to write a function to reverse a string, or if I was taking a class and this was a project assignment, I'd think an assumption in the question is that I can't just call a function that someone else wrote. I suppose I might ask if that's a legal solution. But presumably the point of the question is to test the appplicant's ability to write code to solve the problem, not his ability to look things up in the reference docs.

    If you were given a school assignment to "write an e-mail program", do you think you could just hand in a copy of MS Outlook and get an A? (Well, probably a C, but that's another story.) That's not "writing an e-mail program", that's "making a copy of an e-mail program that someone else wrote".

    I suppose it's possible that the goal of the question is to find out if you're familiar with the library, or if you know to use library functions rather than re-writing everything yourself from scrath. But if I was interviewing someone, "Does the applicant remember that a relatively-infrequently-used function is in the library?" does not seem like a useful thing to know.

  • you know who (unregistered) in reply to boog
    boog:
    you know who:
    boog:
    you know who:
    What, would you say, is the complexity of the fib function?
    What, would you say, is the point of the fibSeq() function? Or the comment "whoops"?
    And you have the audacity to imply I'm not too bright.
    That's unfair. In no way did I ever imply such a thing.

    However, I did say it quite explicitly.

    You asked, implying it was the case, you didn't state it.

  • you know who (unregistered) in reply to boog
    boog:
    you know who:
    What, would you say, is the complexity of the fib function?
    What, would you say, is the point of the fibSeq() function? Or the comment "whoops"?

    I know what you said. I gave you an (incorrect translation) of an algorithm that will do it faster than O(n). It's not O(log n), but it's faster than O(n). I thought it would be interesting.

    The fibSeq() was part of the code used to frame the function.

    The "whoops" was cause I mistyped a minus sign the first time. It still doesn't work. This does, as I actually tested it this time:

    public static long fib(int n)
    {
    	double sqrt5 = Math.sqrt(5);
    	double termOne = Math.pow(1+sqrt5, n);
    	double termTwo = Math.pow(1-sqrt5, n);
    	
    	return (long)((termOne - termTwo)/(sqrt5 * 2));
    }
    
    public static void main(String[] args) throws IOException
    {
    	long[] fibNums = new long[50];
    	
    	for (int x = 0; x < 50; ++x)
    		System.out.println(fibNums[x] = fib(x));
    	
    	for (int x = 2; x < 50; ++x)
    		if (fibNums[x] != fibNums[x - 1] + fibNums[x - 2])
    			throw new Error();
    	
    	System.out.println("success");
    	System.exit(0);
    

    }

    0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 3524578 5702887 9227465 14930352 24157817 39088169 63245986 102334155 165580141 267914296 433494437 701408733 1134903170 1836311903 2971215073 4807526976 7778742049 success

  • (cs) in reply to boog
    boog:
    Fair enough, but this challenge actually has a point: improved performance. In order to improve performance of any algorithm, a programmer will most likely need to use math.
    + 1/0 for truth. If you ever need calculus, and you try to approximate it with procedure, your system's performance will suck xunesis's donkey balls.
  • you know who (unregistered) in reply to boog
    boog:
    SCB:
    But that calculates them in O(1). You need to add: sleep(log(n));
    Really? If n changed to 1000 or 10000, fibSeq would run in the same amount of time?

    Interesting...

    Don't be an ass. We already have plenty of those.

  • (cs) in reply to you know who
    you know who:
    Don't be an ass. We already have plenty of those.
    Clearly... ^^
  • Hortical (unregistered) in reply to Sutherlands
    Sutherlands:
    Hortical:
    Sutherlands:
    Psuedocode:

    foreach(letter in string) StringBuilder.AppendFront(letter)

    Consider the possibility that the StringBuilder uses a char[] internally.

    Consider the possibility that every time you insert a char at the beginning, all the other chars that have been added have to be moved over a space. Every time.

    Consider the possibility that this is pseudocode.

    pseudocode typically doesn't involve references to specific class libraries does it?

    You'll notices that I understood by "AppendFront(letter)", you meant "insert(0, letter)". I understand your pseudocode and that is it pseudo. But when we apply your approach it doesn't work out nearly as well as other approaches that have been posted, for the reason I gave.

    You were wrong, get over it.

  • (cs) in reply to Hortical
    Hortical:
    Sutherlands:
    Hortical:
    Sutherlands:
    Psuedocode:

    foreach(letter in string) StringBuilder.AppendFront(letter)

    Consider the possibility that the StringBuilder uses a char[] internally.

    Consider the possibility that every time you insert a char at the beginning, all the other chars that have been added have to be moved over a space. Every time.

    Consider the possibility that this is pseudocode.

    pseudocode typically doesn't involve references to specific class libraries does it?

    You'll notices that I understood by "AppendFront(letter)", you meant "insert(0, letter)". I understand your pseudocode and that is it pseudo. But when we apply your approach it doesn't work out nearly as well as other approaches that have been posted, for the reason I gave.

    You were wrong, get over it.

    Really? Please tell me what language I was using.

    The best approach is to simply use a library function that exists to do the task at hand, and that is what I would do.

  • (cs) in reply to resmoker10
    resmoker10:
    Actually that's something that bugs me about C# that it doesn't have a string reverse function. For some reason Microsoft didn't see fit to add a string.Reverse() method and I have had to roll my own.

    Password reversal is a useful when storing passwords in a database to obscure them from potential attackers. More recently what with all the hacking stories in the news I have increased my precautions by reversing the strings two times before inserting them into the password table so they are double encrypted.

    That's a REALLY backwards approach!

  • Hortical (unregistered) in reply to Sutherlands
    Sutherlands:
    Really? Please tell me what language I was using.

    The best approach is to simply use a library function that exists to do the task at hand, and that is what I would do.

    I saw "StringBuilder" and assumed java class libraries, but that's obviously not the case after a second glance. Then again, C#'s interface has the same method - underlying implementation, I don't know.

    I agree about using library functions, but that's not what you did, then again, it's not what you're supposed to do on this test and the approach you took in doing what you were supposed to do wasn't ideal either, despite the fact that it's just pseudocode.

  • Fat (unregistered) in reply to you know who

    I still don't believe you've executed your code. All I get is 0 1 2 8 24 80 256 832 2688 8704 28160 91136 294912 954368 3088384 9994240 32342016 104660992 338690048 1096024064 3546808320 11477712896 37142659072 120196169728 388962975744 1258710630400 4073273163776 13181388849152 42655870353408 138037296103424 446698073620480 1445545331654657 4677882957791237 15137947242201104 48987426315567160 158526641599938752 513002988462146176 1660112543324047360 5372237040496678912 9223372036854775807 9223372036854775807 9223372036854775807 (repeatedly)

    and then an exception.

    Besides, I clearly see the error that leads to this error. But I don't understand, why would you lie you tested it?

  • you know who (unregistered) in reply to C-Octothorpe
    C-Octothorpe:
    you know who:
    Don't be an ass. We already have plenty of those.
    Clearly... ^^

    Speak of the devil. Of course, you're a different kind of ass. boog is the kind that misunderstands things and then tries to make someone else look ridiculous so no one notices. You're the kind that takes jabs at others for being nerds despite the fact that you spend a good portion of your day here.

  • (cs) in reply to you know who
    you know who:
    boog:
    you know who:
    boog:
    you know who:
    What, would you say, is the complexity of the fib function?
    What, would you say, is the point of the fibSeq() function? Or the comment "whoops"?
    And you have the audacity to imply I'm not too bright.
    That's unfair. In no way did I ever imply such a thing.

    However, I did say it quite explicitly.

    You asked, implying it was the case, you didn't state it.

    Actually, I stated it, and asked for confirmation. :)

  • you know who (unregistered) in reply to Fat
    Fat:
    I still don't believe you've executed your code. All I get is 0 1 2 8 24 80 256 832 2688 8704 28160 91136 294912 954368 3088384 9994240 32342016 104660992 338690048 1096024064 3546808320 11477712896 37142659072 120196169728 388962975744 1258710630400 4073273163776 13181388849152 42655870353408 138037296103424 446698073620480 1445545331654657 4677882957791237 15137947242201104 48987426315567160 158526641599938752 513002988462146176 1660112543324047360 5372237040496678912 9223372036854775807 9223372036854775807 9223372036854775807 (repeatedly)

    and then an exception.

    Besides, I clearly see the error that leads to this error. But I don't understand, why would you lie you tested it?

    So you're under the impression that I got out a calculator and figured the output by hand?

  • you know who (unregistered) in reply to boog
    boog:
    you know who:
    boog:
    you know who:
    boog:
    you know who:
    What, would you say, is the complexity of the fib function?
    What, would you say, is the point of the fibSeq() function? Or the comment "whoops"?
    And you have the audacity to imply I'm not too bright.
    That's unfair. In no way did I ever imply such a thing.

    However, I did say it quite explicitly.

    You asked, implying it was the case, you didn't state it.

    Actually, I stated it, and asked for confirmation. :)

    Cool! We already forgot about how you (apparently) don't understand the complexity of algorithms. Nice work, boog!

  • Fat (unregistered) in reply to you know who

    I believe that either you post here not the code you execute, or you get the right output from some place else (maybe calculator, maybe almighty google). But again, your motives for this are unclear.

  • (cs) in reply to Hortical
    Hortical:
    Sutherlands:
    Really? Please tell me what language I was using.

    The best approach is to simply use a library function that exists to do the task at hand, and that is what I would do.

    I saw "StringBuilder" and assumed java class libraries, but that's obviously not the case after a second glance. Then again, C#'s interface has the same method - underlying implementation, I don't know.

    I agree about using library functions, but that's not what you did, then again, it's not what you're supposed to do on this test and the approach you took in doing what you were supposed to do wasn't ideal either, despite the fact that it's just pseudocode.

    C# uses a string and memcpy under the hood for Insert. Despite that, I wasn't answering the question in the OP, I was answering someone's question who didn't understand how you would do it without recursion.

    Re: answering the question in the article with a statement to use the library function: That's the first thing I would do, depending on how the question was worded. "How would you do this?" vs "Write this function". In the second case, I'd probably ask if we can insert a call to the function, which is something I've had to do at my job to "improve" a function that didn't exist in previous versions of the framework. Answering in this way shows that you actually know the framework and have used it. It's amazing when you interview people how many simply don't know how to use what they're working with.

Leave a comment on “Three for Three, Recursion Threads, and Wrong Answer”

Log In or post as a guest

Replying to comment #:

« Return to Article