• (disco)

    The cornify was really easy to find. But I find myself incapable of understanding WTF the "source code" is supposed to mean.

  • (disco)

    I think the candidate was trying to find a repeating sequence in the FizzBuzz output, somehow. But your guess is as good as mine…

  • (disco) in reply to aliceif
    aliceif:
    The cornify was really easy to find. But I find myself incapable of understanding WTF the "source code" is supposed to mean.
    Same here - what he is trying to achieve with `(1 - 100) / 3` is a complete mystery to me.

    But one thing is sure: he hasn't yet come across the modulo operator.

    As for the interface / abstract thing: I'm not sure if all languages know the concept of "abstract" so mybe he can be excused there.

  • (disco) in reply to faoileag

    You don't even need modulo in C++.

    int modulo(int n, int m){
       return n - (m * (n / m));
    }
    
  • Frist Bruzz (unregistered)

    http://blog.codinghorror.com/why-cant-programmers-program/

    Failing a FizzBuzz isn't rare. Failing a FizzBuzz this hard, is.

  • (disco) in reply to aliceif
    aliceif:

    You don't even need modulo in C++.

    int modulo(int n, int m){
       return n - (m * (n / m));
    }
    

    I need to get back into programming C++...

    Hm. Perhaps that function was what he was trying to build in his code snippet?

    Edit: fixed broken quoting.

  • (disco)

    Likes thread makes more sense now.

  • (disco)

    I can't read any of the writing. But I probably wouldn't understand it anyway.

  • (disco) in reply to aliceif

    Instead of dividing and remultiplying, C has a standard reference function called "div". It's perfect for people who are annoyed at the idea of needlessly doing an expensive division twice :

    #include<stdlib.h>
    int modulo(int n, int d) {
        div_t result = div(n, d) ;
        return result.rem ;
    }
    

    Of course, if he doesn't know % he won't know about standard C functions. In fact, I'm wondering what this guy actually does know.

  • (disco) in reply to aliceif
    aliceif:
    You don't even need modulo in C++.
    You don't need modulo in any language. You don't even need stinking multiplication, division and subtraction in any language. Just good old ++ and a comparison or two will set you straight.
  • (disco) in reply to TGV
    TGV:
    You don't need modulo in any language. You don't even need stinking multiplication, division and subtraction in any language. Just good old ++ and a comparison or two will set you straight.
    You don't even need ++.

    This also is a valid approach at FizzBuzz:

    if (i == 0) { cout << 'FizzBuzz\n'; }
    else if (i == 1) { cout << i; }
    else if (i == 2) { cout << i; }
    else if (i == 3) { cout << 'Fizz'; }
    else if (i == 4) { cout << i; }
    else if (i == 5) { cout << 'Buzz'; }
    ...
    

    You get my meaning. But would you hire somebody that presented that solution?

  • Nagesh the nitpicker. (unregistered)

    The programmer moved to India and became a project manager.

  • (disco) in reply to faoileag

    If they wrote a script to output that program, then maybe. Just for curiosity's sake.

  • (disco) in reply to cartman82

    Even better: A program that creates that program, compiles it, and runs it.

  • (disco) in reply to faoileag

    I was just joking. Why stop at replacing modulo? Perhaps even better: write an enterprise framework, with separate servers for fizz and buzz, which of course have to be synchronized in some devious way. Ah, the possibilities.

  • (disco) in reply to TGV
    FizzBuzzFactoryBeanFactoryBeanManagerBeanFactoryBeanBeanFactory
    

    ?

  • (disco) in reply to aliceif
    aliceif:
    ```java FizzBuzzFactoryBeanFactoryBeanManagerBeanFactoryBeanBeanFactory ``` ?
    Eggs, bacons, bean and ... factory?
  • (disco)

    https://github.com/EnterpriseQualityCoding/FizzBuzzEnterpriseEdition

  • (disco) in reply to cartman82

    That's what I had in mind. I was too lazy to google it, though.

  • (disco) in reply to cartman82

    The article code looks a lot easier to figure out.

  • ¯\(°_o)/¯ I DUNNO LOL (unregistered)

    We don't need no steenking modulo operator.

    int i, f, b; for (i=1, f=1, b=1; i<=100; i++, f++, b++) { ; if (f==3) f=0; ; if (b==5) b=0; ; if (!(f+b)) printf("fizzbuzz\n"); ; else if (!f) printf("fizz\n"); ; else if (!b) printf("buzz\n"); ; else printf("%d\n", i); }

  • (disco)

    The RWTF is that his code would stop at 100

  • (disco) in reply to aliceif
    aliceif:
    That's what I had in mind. I was too lazy to google it, though.

    It was already posted in a different thread. But now I re-posted it in a timely manner and got all the likes for myself. Today likes, tomorrow the world! MWHAHAHAHA!

  • (disco) in reply to cartman82
    cartman82:
    I re-posted it in a timely manner and got all the likes for myself. Today likes, tomorrow the world!
    7 to go for "Mediocre Poster"!
  • (disco)

    I seriously fear this person has some kind of brain tumor or medical condition.

  • (disco) in reply to aliceif

    Allow me to translate for you:

    lol how doez I code?

  • (disco)

    Article source nit:

    <img src="https://thedailywtf.com/images/remy/fizzbuzz4.png" title="cout << 8.14"width="800"/>
    

    Note the lack of a space before the width attribute.

  • (disco) in reply to urkerab
    urkerab:
    Article source nit:
    &lt;img src="https://thedailywtf.com/images/remy/fizzbuzz4.png" title="cout &lt;&lt; 8.14"width="800"/&gt;
    

    Note the lack of a space before the width attribute.

    If I wanted to nitpick, I’d probably complain about the unescaped << in the title attribute first...

  • (disco) in reply to TGV

    And recursion. (or stinking goto).

  • (disco) in reply to aliceif
    aliceif:
    You don't even need modulo in C++.
    But you need integer division instead. Well, actually any sane IDIV implementation can generate the remainder at the same time for the same effort; it's just usually thrown away by language implementations.
  • (disco)

    Should this be categorized as Code SOD or Tales From the Interview? I struggle to call that "code" in the usual sense of the word.

  • (disco)

    The guy thought it was code on some level.

    This is special however, on so many levels.

  • (disco)

    This candidate should write code for feature films instead. It looks awesome and science-y on paper and makes no sense whatsoever; perfect for Hollywood.

  • (disco) in reply to mruhlin

    It sorta sits at the intersection of both.

  • (disco) in reply to dkf
    dkf:
    But you need integer division instead. Well, actually any sane IDIV implementation can generate the remainder at the same time for the same effort; it's just usually thrown away by language implementations.
    Nah, you can implement it all using nothing more than ++. It won't be pretty though.
  • (disco) in reply to faoileag

    No, but if they knew about loop unrolling and mentioned or implemented it as a solution to not require modulo, I'd consider them. Then I'd change the question so they no longer knew the numbers to fizz and buzz on (they would become parameters), requiring them to show modulo or equivalent-logic arithmetic.

  • (disco) in reply to TGV

    You need an equality test too.

  • (disco) in reply to aliceif
    aliceif:
    Even better: A program that creates that program, compiles it, and runs it.

    Extra points if the program can output a copy of itself in your choice of language.

  • (disco)

    How π came into it, I'll never know. But his last part about cout>>8.14 was just him adding Fizz and Buzz, which he appeared to have determined to equal 5 and 3.14 respectively, and printing them out as requested.

    Maybe I should have myself committed for managing to possibly understand the method behind that madness.

  • (disco) in reply to Adrian_Martin

    Hey, counting to 100 should be enough for anybody.

  • (disco) in reply to cartman82

    I prefer to go the other direction. FizzBuzz in BrainF*ck.

     >++++++++                                Place "fizzbuzz\n" starting at t(3)
     [>++++++++++++
     [>+>+>+>+>+>+>+>+<<<<<<<<-]<-]
     >>++++++>+++++++++>>>++<<<<<<+++
     [>+++++++
     [>>>+>+>>+>+>+<<<<<<<<-]<-]
     +++++[>>>>+>+>>>+>+><<<<<<<<<<-]
     >>>>>>>>>>++++++++++
     >>++++++++++[<++++++++++>-]             Sets t(11) to 100
     <                                    Move back to t(11)
     [                                    Start main loop
     ->+
     >[-]>+++                                Zero out helper, place 3 as the divisor
     >[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]        Clear the working memory for the modulo
     <<<<<<<<<<
     [->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]    Perform modulo
     >>>                                    Move to modulo result
     >[-]+>[-]<<[>-<[>>+<<-]]>>[<<+>>-]<    if(result == 0)
     [<<<<<<<<<<<<<<<<<+>>>.>.>.>.        Print fizz, increment t(0) to indicate we printed fizz
     >>>>>>>>>>>-]
     <<[-]>[-]+++++                        Zero out helper, place 5 as the divisor
     >[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]        Clear the working memory for the modulo
     >[-]>[-]<<<<<<<<<<<<
     [->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]    Perform modulo
     >>>                                    Move to modulo result
     >[-]+>[-]<<[>-<[>>+<<-]]>>[<<+>>-]<    if(result == 0)
     [<<<<<<<<<<<<<<<<<<+>>>>>>>.>.>.>.    Print buzz, increment t(0) to indicate we printed buzz
     >>>>>>>>-]
     <<<<<<<<<<<<<<<<<<                    Rewind tape to start                    
     >[-]+>[-]<<[>-<[>>+<<-]]>>[<<+>>-]<    if(t(0) == 0) print the number instead
     [>>>>>>>>>>>>>>                        Print the number
     >[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]
     <<<<<<
     ++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-
     <+>]>+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++++++
     <]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]
     <<<<<<<<<<<<<<<-]
     >>>>>>>>>>>>>>[-<<+>>]                Copy the number back to t(12)
     <<<<.                                Output a newline.
     <<<<<<<<<<<[-]                        Clear the register at t(0)
     >>>>>>>>>>>>                            Move back to the counter at t(11)
     ]                                    End main loop
    
  • (disco) in reply to dkf
    dkf:
    You need an equality test too.

    Surly you can build an equality test from an 'is zero' operator.

  • (disco)

    Wow, I was going to post my Scheme version, but that BrainF**k version beats that all hollow. Oh, well, I'll post it anyway:

    #!r6rs
    (import
     (rnrs base (6))
     (rnrs lists (6))
     (rnrs io simple (6))
     (rnrs r5rs (6)))
    
    (define (range a b)
       (let count ((x a))
         (if (>= x b)
             (list b)
             (append (list x) (count (+ 1 x))))))
    
    (define (fizzbuzz n)
      (let ((count-list (range 1 n)))
        (map 
         (lambda (fb count)
           (if (string=? fb "")
               count
               fb))
         (map
          (lambda (f b)
            (string-append f b))    
          (map
           (lambda (x)
             (if (= 0 (modulo x 3))
                 "Fizz"
                 ""))
           count-list)
          (map
           (lambda (x)
             (if (= 0 (modulo x 5))
                 "Buzz"
                 ""))
           count-list))
         count-list)))
    
    (display (fizzbuzz 100))
    

    EDIT: removed a little bit of redundancy. HTH. DOUBLE EDIT: I forgot the requirement to print the numbers which don't match the pattern. Fixed.

  • (disco) in reply to ScholRLEA

    I should dig out the one my buddy did which was in MSSQL.

  • (disco)

    Here's my fizzbuzz contribution:

    import re
    program = """
    if   1 % 15.0 == 0.0: print "fizzbuzz"
    elif 1 %  3.0 == 0.0: print "fizz"
    elif 1 %  5.0 == 0.0: print "buzz"
    else: print 1 
    
    if 1 != 100:
        program = re.sub(" 1 ", " {} ".format( 1 +1), program)
        exec program
    """
    exec program
    
  • (disco) in reply to EvanED

    wait... since when could you use the number 1 as a variable in python?

    i want to call shenanigans, but i'm half afraid that Guido would have implemented that.

  • (disco)

    Looks like Jeff was right about something!

    http://blog.codinghorror.com/fizzbuzz-the-programmers-stairway-to-heaven/

  • (disco) in reply to mott555
    mott555:
    Looks like Jeff was right about something!

    I like that he was right about this because it angers @blakeyrat.

  • (disco)

    Don't need modulo, just a couple of countdowns... here's an implementation in NetLogo.

    to fizzbuzz [ max-fizzbuzz ]
       let fizz 0
       let buzz 0
       let count 0
       repeat max-fizzbuzz
       [ set count count + 1
         set fizz fizz + 1
         set buzz buzz + 1
         ifelse fizz = 3   [ type "fizz" set fizz 0 ] [
         ifelse buzz = 5 [ type "buzz" set buzz 0 ] [
                                 type count
         ]]
         print ""
       ]
    end
    
  • (disco) in reply to accalia

    You can't. Not really. That's why I like that solution so much, because you get to say things like "if 1 != 100" and it will eventually be false. :-)

    A hint: """ delimits multi-line strings in Python.

Leave a comment on “The Fizz Buzz from Outer Space”

Log In or post as a guest

Replying to comment #:

« Return to Article