• Belcat (unregistered)

    The fool! All he had to do was rollback.. too late now! (Ok, so some tools may not do that automatically, but the ones we use here automatically start a transaction, so if we need to rollback, no problem!)

  • Anonaa (unregistered)

    TRWTF is that links is directly pasted from outlook webmail

    ED: I think TRWTF is that OWA has to redirect every link... Fixed!

  • moz (unregistered)

    All I can say is that I do not think subtext means what you think it means.

  • delete (unregistered)

    A few weeks ago happened to me, that my boss "accidentally" forgot the delete clause in a DELETE.

    And after asked me the same silly question, while pointing up that in DB2/400 is effectively possible to recover data from a table (but they usually call them "files"), after a delete, if you don't repack the table.

  • nick (unregistered)

    That's sad :/ I feel kinda sorry for that guy.

  • Erik (unregistered)

    I'm all for coding tests for potential hires, but why would your coding test try to ascertain whether or not the interviewee was capable of producing code in a way that you yourselves admit they would never do in real life?

    That particular problem is sort of like asking someone to pattern match in Perl without using regular expressions. Just seems a little pointless to me.

  • thetunaman (unregistered)

    I think it is a valid interview question, makes someone show they can iterate though some simple work.

    Would also need maybe a follow up question on recursion, but definately a valid question to ask.

  • (cs) in reply to Erik
    Erik:
    I'm all for coding tests for potential hires, but why would your coding test try to ascertain whether or not the interviewee was capable of producing code in a way that you yourselves admit they would never do in real life?

    That particular problem is sort of like asking someone to pattern match in Perl without using regular expressions. Just seems a little pointless to me.

    I think the point is to weed out the complete muppets, the ones that don't have a clue, similar to that Fiz Buz problem that had its 15 nanoseconds of Internet fame a while ago. (The problem was something along the lines of: for every number from 1 to 100 print Fiz if it's divisible by 3, Buz if it's divisible by 5 and FizBuz if it's divisble by both 3 and 5. It appeared that surprisingly low percentage of potential hires managed to solve this highly sophisticated problem)

  • (cs) in reply to Erik
    Erik:
    I'm all for coding tests for potential hires, but why would your coding test try to ascertain whether or not the interviewee was capable of producing code in a way that you yourselves admit they would never do in real life?

    That particular problem is sort of like asking someone to pattern match in Perl without using regular expressions. Just seems a little pointless to me.

    Usually the point is to analyze the interviewee's problem solving ability, but you're right, it's pretty silly here because the candidates complete it on their own time. For whatever reason I guess it still weeds out the completely useless candidates.

    I hope these comments don't degenerate into (some) self-taught programmers bashing anything that isn't 100% practical just because they don't understand the difference between a LinkedList and an ArrayList.

  • (cs)

    I would have posted teh codez if I wasn't afraid that the peer review here would be too severe.

    I want to see someone come up with a one line solution

    Btw that is a task for home?

    And what better name for a table than table_columns

  • (cs) in reply to Stilgar
    Stilgar:
    And what better name for a table than table_columns
    If you think about it that is one table you do NOT want to lose. Especially if your col_id has gone up to 1223
  • kr (unregistered) in reply to Sad Bug Killer
    Sad Bug Killer:
    I think the point is to weed out the complete muppets, the ones that don't have a clue, similar to that Fiz Buz problem that had its 15 nanoseconds of Internet fame a while ago. (The problem was something along the lines of: for every number from 1 to 100 print Fiz if it's divisible by 3, Buz if it's divisible by 5 and FizBuz if it's divisble by both 3 and 5. It appeared that surprisingly low percentage of potential hires managed to solve this highly sophisticated problem)

    I got asked that exact question at my last interview (over a year ago). I hadn't heard it before and didn't know until know it was a common question. I did think it was a little silly; if my 9-year-old self had known what "modulo" was, he could have done it in GW-BASIC. But the interviewer said the same thing, "apparently a lot of people have trouble with that one".

  • kr (unregistered) in reply to kr
    kr:
    and didn't know until know it was a common question.

    "didn't know until now", I mean.

  • Thomas Winwood (unregistered)

    I decided to write some code because I was bored and it was something to spend five minutes on. I've not tested it in "production", though I probably would if I was actually applying for the job.

    I'm using the Substring() and ToLower() methods, which doesn't seem to be against the rules (which only state that you're not allowed to use built-in methods which do the checking for you). If there's no matches then I return an empty list.

    List<int> StringIndex(string text, string subtext)
    {
        List<int> positionsFound = new List<int>();
    
        for (int pos = 0; pos < input.Length - 1; pos++)
        {
            if (text.ToLower().Substring(pos, subtext.Length) == subtext.ToLower())
            {
                positionsFound.Add(pos);
            }
        }
    
        return positionsFound;
    }
  • (cs)

    The real WTF is (I've always wanted to post that) that the indices in the example are 1 based

  • Muppet (unregistered) in reply to Outlaw Programmer
    Outlaw Programmer:
    Usually the point is to analyze the interviewee's problem solving ability, but you're right, it's pretty silly here because the candidates complete it on their own time. For whatever reason I guess it still weeds out the completely useless candidates.

    The filter works the other way too, as I'd be tempted to get up and leave when presented with that kind of busy-work.

    (But then, I code in perl, where "there's more than one way to do it" is both the official motto, and its biggest curse. The last thing I need is people with a penchant for "clever" solutions to things that shouldn't be problems in the first place.)

  • Sam (unregistered)

    I think the fact that the requirement was to not use any string manipulation function makes this problem a bit silly and excessive.

    While barring the use of any Substring function or Contains function could have left the door open to:

    string[] splitString = input.Split(' ');
    foreach string word in splitString
        // etc
    

    And is significantly easier to do, barring any string manipulation function would require you to traverse individual characters, looking for spaces, keeping track of indicies, etc. Even C contains an strtok function, and C barely has any string manipulation functions. Why ask someone to dramatically re-invent the wheel? Could someone implementing the code above not be able to demonstrate an understanding of a number of functions in C#?

    Programming tests are fine; I think when they get too ridiculously abstract and pointless is when they just get silly.

    • Sam
  • (cs) in reply to Thomas Winwood
    Thomas Winwood:
    I decided to write some code because I was bored and it was something to spend five minutes on. I've not tested it in "production", though I probably would if I was actually applying for the job.

    I'm using the Substring() and ToLower() methods, which doesn't seem to be against the rules (which only state that you're not allowed to use built-in methods which do the checking for you). If there's no matches then I return an empty list.

    List<int> StringIndex(string text, string subtext)
    {
        List<int> positionsFound = new List<int>();
    
        for (int pos = 0; pos < input.Length - 1; pos++)
        {
            if (text.ToLower().Substring(pos, subtext.Length) == subtext.ToLower())
            {
                positionsFound.Add(pos);
            }
        }
    
        return positionsFound;
    }

    Where does input.Length come from? And you should only check till text.Length - subtext.Length or you will get an IndexOutOfRangeException from Substring IIRC.

    And don't forget to cache the text.ToLower() and subtext.ToLower() ;)

  • Sam (unregistered) in reply to Sam
    Sam:
    ... barring any string manipulation function ...

    PS - My interpretation of "string manipulation function" is really any method of the String class, including Split, ToLower, Substring, Contains, etc.

    If I'm incorrect in this assumption, then what I said above doesn't apply xD

    • Sam

    Captcha - haero ... are these actually words?

  • Fanguad (unregistered)

    I once got asked "given two points, how would you find the distance between them?"

    My brain went into overdrive trying to find the hidden meaning behind the question. Were they talking three-dimensional points? Are the points moving? Are they some sort of weird hyper-points?

    I hesitantly responded, "The square root of delta x squared plus delta y squared?" The interviewer nodded and told me, "You'd be amazed at how many people have trouble with that."

  • me (unregistered) in reply to Thomas Winwood
    Thomas Winwood:
    List<int> StringIndex(string text, string subtext)
    {
        List<int> positionsFound = new List<int>();
    
    for (int pos = 0; pos < input.Length - 1; pos++)
    {
        if (text.ToLower().Substring(pos, subtext.Length) == subtext.ToLower())
        {
            positionsFound.Add(pos);
        }
    }
    
    return positionsFound;
    

    }

    Instant no hire. This is so bad I don't even know where to start... O(n^2) complexity. Doing the same O(n) thing over and over again instead of remembering the result. Doing an awful lot of entirely unnecessary allocations.

    Of course, that the problem is ill-defined (Does subtext="" have no matches or tons of matches? Can matches overlap or not?) doesn't make things any better. But then, it may be intentional to test if the programmer realizes it.

  • Paolo/Pixline (unregistered)

    Was this post helpful? I hope you marked it 'Yes', but I'm not sure about the point of view.

  • MyFACE (unregistered) in reply to Thomas Winwood
    Thomas Winwood:
    I decided to write some code because I was bored and it was something to spend five minutes on. I've not tested it in "production", though I probably would if I was actually applying for the job.

    I'm using the Substring() and ToLower() methods, which doesn't seem to be against the rules (which only state that you're not allowed to use built-in methods which do the checking for you). If there's no matches then I return an empty list.

    List<int> StringIndex(string text, string subtext)
    {
        List<int> positionsFound = new List<int>();
    
        for (int pos = 0; pos < input.Length - 1; pos++)
        {
            if (text.ToLower().Substring(pos, subtext.Length) == subtext.ToLower())
            {
                positionsFound.Add(pos);
            }
        }
    
        return positionsFound;
    }

    I was under the impression that no calls to "substring" would be allowed? If it is allowed, that makes this significantly easier (not that implementing substring is that much more difficult). I wrote it assuming I couldn't, although I wrote it in C...

    void get_index_of( char* text, char* subtext, int* result )
    {
        // assumes result is big enough.
        textLen = strlen( text );
        subtextLen = strlen( subtext );
        bool found = false;
        int i = 0, j = 0, foundidx = 0;
    
        if( subtextLen > textLen )
            return; // do nothing.
    
        for( i = 0; i < textLen; i++ )
        {
            for( j = 0; j < subtextLen; j++ )
            {
                found = true;
                if( i + j >= textLen )
                {
                    found = false;
                    break;
                }
    
                if( tolower( subtext[ j ] ) != tolower( text[ i + j ] ) )
                {
                    found = false;
                    break;
                }
            }
    
            if( found )
                result[ foundidx++ ] = i;
        }
    }
    

    Note, I'm not sure if it even compiles as I'm sure I have typos and gross syntax errors but this ought to work.

    I have now proven that I am either incapable of implementing a simple function, or that I fit the stereotype of every other nerd on the internet that MUST solve any programming problem, no matter how trivial.

  • MyFACE (unregistered) in reply to MyFACE

    Oops, found=true should be BEFORE the for( j = 0... ) loop.

  • anonymous (unregistered) in reply to MyFACE
    MyFACE:
        textLen = strlen( text );
        subtextLen = strlen( subtext );
    

    Shouldn't that be

    int textLen = strlen( text );
    int subtextLen = strlen( subtext );
    
  • Canthros (unregistered)

    I got asked during one interview how I would count the number of rows in a table using SQL (or something to that effect: find the largest value in a column in a table or something similar). Same general idea: apparently, many people interviewing for SQL-related jobs don't understand aggregate functions. Huh.

    (I didn't get the job, actually, but that had as much to do with me as the interview with their VP that started with "You're just a young guy!" and continued with "I used to do your job and I know all about it", before, IIRC, insisting that I should use the time for a practice interview.)

  • Otto (unregistered) in reply to me

    Writing an O(n) algorithm for this problem is decidedly non-trivial. (Look up Boyer-Moore, it's pretty fancy.) I would not expect anyone to come up with it for an interview question without cheating, at least.

  • CodeMonkey (unregistered)

    From the same dude, even more scary IMHO: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2356627&SiteID=1

    Hi Guys,

    How would change the position of a column within a datatable. For example, in my datatable there are 5 columns:

    ID | NAME | AGE | ADDRESS | SAVINGS

    How would I change it so that column ADDRESS appears where column AGE is currently at, I would end up with this:

    ID | NAME | ADDRESS | AGE | SAVINGS

    I know I could change the select statement to change it, but I'd like to know how this could be done through ADO.NET

    Many thanks

    Everything looks like a nail, when you have a new hammer...

  • ping floyd (unregistered) in reply to MyFACE
    MyFACE:
    I was under the impression that no calls to "substring" would be allowed? If it is allowed, that makes this significantly easier (not that implementing substring is that much more difficult). I wrote it assuming I couldn't, although I wrote it in C...
    void get_index_of( char* text, char* subtext, int* result )
    {
        // assumes result is big enough.
        textLen = strlen( text );
        subtextLen = strlen( subtext );
        bool found = false;
        int i = 0, j = 0, foundidx = 0;
    
    if( subtextLen > textLen )
        return; // do nothing.
    
    for( i = 0; i < textLen; i++ )
    {
        for( j = 0; j < subtextLen; j++ )
        {
            found = true;
            if( i + j >= textLen )
            {
                found = false;
                break;
            }
    
            if( tolower( subtext[ j ] ) != tolower( text[ i + j ] ) )
            {
                found = false;
                break;
            }
        }
    
        if( found )
            result[ foundidx++ ] = i;
    }
    

    }

    Note, I'm not sure if it even compiles as I'm sure I have typos and gross syntax errors but this ought to work.

    I have now proven that I am either incapable of implementing a simple function, or that I fit the stereotype of every other nerd on the internet that MUST solve any programming problem, no matter how trivial.

    YOU'RE HIRED!

  • Anon (unregistered)

    Another WTF is that lousy table of inputs and expected results. Put the input in one column and the expected results in the other.

  • Anon (unregistered) in reply to me

    [quote user="me"][quote user="Thomas Winwood"] Of course, that the problem is ill-defined (Does subtext="" have no matches or tons of matches? Can matches overlap or not?) doesn't make things any better. But then, it may be intentional to test if the programmer realizes it.[/quote]

    I think an ill-defined interview question probably tells you more about the candidate that a well defined one. Will they get frustrated because they don't have all the information or will they, I don't know, have the sense to ask for clarification? I set a take home programming problem for a position I had open and I hired the guy who had the sense to ask questions about the ambiguous parts of the problem.

  • JustSomeone (unregistered)

    Must...not...implement...it.......

  • Alex (unregistered)

    So, I don't understand the limits of the request.. I just cannot use LastIndexOf?, would I get the job with this?:

    private void FindSubStringPos(string str, string substr) { int i = 0; int maxIndex = str.Length - substr.Length;

    while (i < maxIndex) { if (str.Substring(i, substr.Length).Equals(substr, StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("Position: "+i); i += substr.Length; } else i++; } }

  • Anonymous user who feels like a smug Scheme weenie today. (unregistered) in reply to me
    me:
    Instant no hire. This is so bad I don't even know where to start... O(n^2) complexity. Doing the same O(n) thing over and over again instead of remembering the result. Doing an awful lot of entirely unnecessary allocations.

    Of course, that the problem is ill-defined (Does subtext="" have no matches or tons of matches? Can matches overlap or not?) doesn't make things any better. But then, it may be intentional to test if the programmer realizes it.

    When the problem is ill-defined, programmers should tend to choose the path that is easiest to implement. The posting doesn't say that the program has to be in C#, either. This implementation contains only one or two optimizations and is O(m*n - n^2) in the worst case (where the worst case is, e.g. finding "aaa" in "aaaaaaaaaaaaaaaa"). It is also, hopefully, completely useless to the plz-send-codez luser.

    (define (match-string str substr n)
     (if (= n (string-length substr))
       #t
      (if (char-ci=? (string-ref str n) (string-ref substr n))
        (match-string str substr (+ n 1)
        #f)))
    
    (define (substring-indexes str substr)
      (let* ((laststrindex (- (string-length str) 
                              (string-length substr))
             (recursive-substring-indexes 
              (lambda (str substr n) 
                (cond ((>= n laststrindex) '())
                      ((match-string str substr 0)
                          (cons n (recursive-substring-indexes
                                   str substr (+ n 1)))
                      (#t (recursive-substring-indexes 
                            str substr (+ n 1)))))))   
          (recursive-substring-indexes str substr 0)))
    
  • (cs) in reply to Erik

    toLower is a String method...

    private char myToLower(char c) { if(c > 63 && c < 91) return (char) (c + 32);

    return c; }

  • (cs) in reply to CodeMonkey
    CodeMonkey:
    From the same dude, even more scary IMHO: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2356627&SiteID=1

    Everything looks like a nail, when you have a new hammer...

    For my money, his most frightening post is at http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1577009&SiteID=1 in which he confesses his confusion:

    Im trying to check if a date in a database is less than todays date, this is the code im using:

    if (dr["CSS_FIRST_DATE"].ToString() < DateTime.Now)

    {

    do something();

    }

    however this isnt working, Im getting an error about cannot use '<' operator with string and datetime......where am I going wrong??

    At least his question about changing positions of columns can be explained by simple ignorance. In this one, however, the error message is RIGHT THERE IN FRONT OF HIM; he is criminally guilty of being unable to develop code and should be moved over to Marketing immediately.

  • (cs) in reply to Anonymous user who feels like a smug Scheme weenie today.
    Anonymous user who feels like a smug Scheme weenie today.:
    me:
    Instant no hire. This is so bad I don't even know where to start... O(n^2) complexity. Doing the same O(n) thing over and over again instead of remembering the result. Doing an awful lot of entirely unnecessary allocations.

    Of course, that the problem is ill-defined (Does subtext="" have no matches or tons of matches? Can matches overlap or not?) doesn't make things any better. But then, it may be intentional to test if the programmer realizes it.

    When the problem is ill-defined, programmers should tend to choose the path that is easiest to implement. The posting doesn't say that the program has to be in C#, either. This implementation contains only one or two optimizations and is O(m*n - n^2) in the worst case (where the worst case is, e.g. finding "aaa" in "aaaaaaaaaaaaaaaa"). It is also, hopefully, completely useless to the plz-send-codez luser.

    (define (match-string str substr n)
     (if (= n (string-length substr))
       #t
      (if (char-ci=? (string-ref str n) (string-ref substr n))
        (match-string str substr (+ n 1)
        #f)))
    
    (define (substring-indexes str substr)
      (let* ((laststrindex (- (string-length str) 
                              (string-length substr))
             (recursive-substring-indexes 
              (lambda (str substr n) 
                (cond ((>= n laststrindex) '())
                      ((match-string str substr 0)
                          (cons n (recursive-substring-indexes
                                   str substr (+ n 1)))
                      (#t (recursive-substring-indexes 
                            str substr (+ n 1)))))))   
          (recursive-substring-indexes str substr 0)))
    
    Needs to be blue-lighted -- if only because it's probably the first example of a Scheme code-snippet on TDWTF.

    It's also a great answer to a stupid interview question.

    Unfortunately, because the interview question is stupid, we may assume that it would fail to get a highly-qualified candidate the job.

    Still, that's Scheme for you.

  • Robert S. Robbins (unregistered) in reply to Fanguad

    [quote user="Fanguad"]I once got asked "given two points, how would you find the distance between them?" [quote]

    I'd just use a ruler and measure the distance. This question does not imply that we are not talking about physical points.

  • (cs)

    For what it's worth, here's my solution to FizBuz, in C++

    #include <stdio>
    #include <iostream>
    
    using namespace std;
    
    int main (int nargs, const char* pszargs[]) {
      for (int i=1; i <= 100; i++) {
        cout << i << ": ";
        //don't ask why I made this next line the way I did
        //it's Monday
        cout << (i%3 ? "" : "Fiz") << (i%5 ? "" : "Buz");
        cout << '\n';
      }
      return 0;
    }

    EDIT: Err, semicolon on the return 0 might be helpful.

  • ydrol (unregistered)

    I always get nervous typing sql 'delete' statements, and when I remember I usually type 'select count(*)' instead and then replace it with 'delete' when I'm happy.

  • (cs) in reply to Fanguad
    Fanguad:
    I once got asked "given two points, how would you find the distance between them?"

    My brain went into overdrive trying to find the hidden meaning behind the question. Were they talking three-dimensional points? Are the points moving? Are they some sort of weird hyper-points?

    I hesitantly responded, "The square root of delta x squared plus delta y squared?" The interviewer nodded and told me, "You'd be amazed at how many people have trouble with that."

    Lovely story; same sad-sack interview technique.

    It's a shame this ended on a happy note, really. I was rather expecting "You missed out delta z squared! Mwahahaha! Luser!"

  • (cs) in reply to The Enterpriser
    The Enterpriser:
    toLower is a String method...

    private char myToLower(char c) { if(c > 63 && c < 91) return (char) (c + 32);

    return c; }

    but that is ToLower for char which is not String method

  • Movie Poop Shoot dot Com (unregistered) in reply to nick
    nick:
    That's sad :/ I feel kinda sorry for that guy.
    You'd feel differently if he were the one programming your pacemaker.

    Or maybe the logic that controls anti-lock braking in your car?

    Or maybe the logic that controls the velocity of commuter trains?

    Fuck that guy. Fuck him up his stupid ass.

  • fhic (unregistered) in reply to Erik

    I agree completely. Depending on how the rest of the interview went, I'd code up something as horribly complex as possible and tell the interviewer that, since they obviously wanted to create a purely intellectual challenge, I thought I'd return the favor and would s/he mind explaining exactly what s/he thought my working code did.

    On my last interview I spent a couple of hours solving those silly "how would you get the cannibals across the river" type of problems. Funny, that's not a problem I've run into yet in all my years of coding. Yet they didn't ask a single question about a real-world problem. You want to know what I know? Ask me how I'd put together a bulletproof component for handling user input while four junior programmers are sitting around waiting for it and the release date is two weeks away. That I've done, and it's presumably why you're hiring me.

  • (cs) in reply to curtmack

    That FizBuz solution is a good answer that runs in (n) operations, but what they really wanted you to do was something a little more optimized: Have a Fiz and Buz counter that increment by 3 and 5 respectively. Each iteration of the loop increments the lower counter and prints the corresponding string. When the two are equal, increment both and print "FizBuz". Runs in: ((n/3) + (n/5) - (n / (3+5))) operations. Maybe.

    Addendum (2008-05-05 12:48): Code that might work:

    #include <iostream>
    int main(int argc,char** argv)
    {
    int fiz=0,buz=0;
    while(fiz<=100&&buz<=100) std::cout << fiz<buz?(fiz++?"fiz":""):(buz<fiz?(buz++?"buz":""):((fiz++ +buz++?"fizbuz":""))) << endl;
    return 0;
    }</pre>
    

    Addendum (2008-05-05 12:50): Er, the big line should be pre-increment

    while(fiz<=100&&buz<=100) std::cout << fiz<buz?(++fiz?"fiz":""):(buz<fiz?(++buz?"buz":""):((++fiz + ++buz?"fizbuz":""))) << endl;</pre>
    

    Addendum (2008-05-05 12:52): And by pre-increment, I meant add 3 or 5. LOL!

    while(fiz<=100&&buz<=100) std::cout << fiz<buz?((fiz+3)?"fiz":""):(buz<fiz?((buz+5)?"buz":""):(((fiz+3) + (buz+5)?"fizbuz":""))) << endl;</pre>
    
  • Sven (unregistered) in reply to curtmack
    curtmack:
    For what it's worth, here's my solution to FizBuz, in C++
    #include <stdio>
    #include <iostream>
    
    using namespace std;
    
    int main (int nargs, const char* pszargs[]) {
      for (int i=1; i <= 100; i++) {
        cout << i << ": ";
        //don't ask why I made this next line the way I did
        //it's Monday
        cout << (i%3 ? "" : "Fiz") << (i%5 ? "" : "Buz");
        cout << '\n';
      }
      return 0;
    }

    EDIT: Err, semicolon on the return 0 might be helpful.

    Fail!

    • Use of hungarian notation
    • No header named <stdio> exists (you either want <cstdio> or <stdio.h>, not that this program even needs that header).
    • Use of \n instead of endl.

    :P

  • blindio (unregistered)

    Why not just skip the middle man, post the interview question directly on various internet help boards, then approach those who answer it with job offers. Should give about the same success rate.

  • RandomWTF (unregistered) in reply to dpm
    dpm:
    At least his question about changing positions of columns can be explained by simple ignorance. In this one, however, the error message is RIGHT THERE IN FRONT OF HIM; he is criminally guilty of being unable to develop code and should be moved over to Marketing immediately.

    Maybe he realizes that the '<' operator won't work, but has no idea how to compare dates in the language he is using. But he leaves that part in the code so that it is still clear what he is trying to do.

    I know that date/time functions can be horribly inconsistent between languages or platforms, and often takes a bit of time and research to figure it out.

  • captcha: suscipit (unregistered) in reply to curtmack
    curtmack:
    For what it's worth, here's my solution to FizBuz, in C++
    #include <stdio>
    #include <iostream>
    
    using namespace std;
    
    int main (int nargs, const char* pszargs[]) {
      for (int i=1; i <= 100; i++) {
        cout << i << ": ";
        //don't ask why I made this next line the way I did
        //it's Monday
        cout << (i%3 ? "" : "Fiz") << (i%5 ? "" : "Buz");
        cout << '\n';
      }
      return 0;
    }

    EDIT: Err, semicolon on the return 0 might be helpful.

    The original question asks that you print numbers, but print Fiz instead of the number if it's a multiple of 3, and Buz instead of the number if it's a multiple of 5, and FizBuz instead of the number if it's a multiple of both. It also doesn't specify that the numbers should be on separate lines.

    Doesn't make it less trivial, but it does allow for ever so slightly more clever solutions.

  • (cs) in reply to RandomWTF
    RandomWTF:
    dpm:
    At least his question about changing positions of columns can be explained by simple ignorance. In this one, however, the error message is RIGHT THERE IN FRONT OF HIM; he is criminally guilty of being unable to develop code and should be moved over to Marketing immediately.

    Maybe he realizes that the '<' operator won't work, but has no idea how to compare dates in the language he is using. But he leaves that part in the code so that it is still clear what he is trying to do.

    I know that date/time functions can be horribly inconsistent between languages or platforms, and often takes a bit of time and research to figure it out.

    The funny part is that in C# the comparison operators are overloaded for DateTime. He could easily compare DateTimes with > but for some reason he decided to compare string and DateTime. Now that is not WTF yet. It would become WTF when he calls .ToString() to the second DateTime argument which will compile and will probably return the right result in enough cases to make it look like it works.

Leave a comment on “Code examples and interviews”

Log In or post as a guest

Replying to comment #192906:

« Return to Article