Live data from Hacker News

A non-programmer’s solution to “Fizz Buzz”

nixonmcinnes.co.uk

31–40 of 58 posts

Re: A non-programmer’s solution to “Fizz Buzz”

#31

Earlier quoted context omitted.

Me: Really? Is that really a business requirement? Any other requirements you need done? I landed a graduate assistantship in 1992 as "the computer guy's assistant" at my school's physical plant. My first assignment was to generate a fixed format file with one phone number per line. The file was to range from 1-900-0000 to 1-900-999-9999 and was needed by the campus telephone system to block all premium rate calls. T…

I know people who spent at least 40 hours/month just updating dates in monthly/weekly excel reports. Edit: and had 6 figure salaries.

This should be the definition of a modern society.

Re: A non-programmer’s solution to “Fizz Buzz”

#32

Earlier quoted context omitted.

Marketing: That's great, but can we change it so that it says now with 25% more buzz? And also get anyone who reads FIZZBUZZ to sign up for our newsletter?

Sales: Yeah, our nerds just completed this new platform called FIZZBUZZ we want you to buy. What's that? Of course it's a fully-featured CMS/CRM/DataWarehouse/SocialMediaAggregator, the developers just have to make a few tweaks...they should be finished in a day or two at most.

Support: Your salesperson told you WHAT?! FIZZBUZZ isn't really capable of that, I'm sorry. No. No. I'm sorry, no. No, again, I apologize, I can't change that for you right now. If you'd like, I can put in a feature request for you. No, I can't give you an ETA...

Re: A non-programmer’s solution to “Fizz Buzz”

#33

Earlier quoted context omitted.

To be fair when doing front end work you sometimes need to make pretty patterns that do something like "print this table but apply this css class to every other row and one of these other classes to this row if a certain flag is set depending on what the previous class was".

And this is the problem I have with CSS selectors. What you just described is ridiculously fragile and will send shudders down the spine of any developer experienced with wrangling projects that have tangles of inappropriate coupling, but in many cases, there simply isn't a more elegant solution. Your options are: 1. Implement a sane (albeit less powerful) view hierarchy system, foregoing basically all of the CSS sel…

Or add classes during output generation.

Re: A non-programmer’s solution to “Fizz Buzz”

#34
post #33

Earlier quoted context omitted.

And this is the problem I have with CSS selectors. What you just described is ridiculously fragile and will send shudders down the spine of any developer experienced with wrangling projects that have tangles of inappropriate coupling, but in many cases, there simply isn't a more elegant solution. Your options are: 1. Implement a sane (albeit less powerful) view hierarchy system, foregoing basically all of the CSS sel…

Or add classes during output generation.

Well yes, but I would consider that only a variation of option 1.

Re: A non-programmer’s solution to “Fizz Buzz”

#35
Good for Clive for being a sport and coming up with a valid answer, of course, but this is what interested me about his response:

He tackled the problem on a "meta" level, but didn't grasp the math. He could have saved a lot of time by seeing if the number was divisible by 15.

Re: A non-programmer’s solution to “Fizz Buzz”

#36

Boss: I need you to write me a program to print the numbers from 1 to 100 Me: Really? Is that really a business requirement? Any other requirements you need done? Boss: Yes, it's your number 1 priority. No, just 1 to 100 Me: Done. Give it a review and I'll push it live. Boss: No! I said 1 to 100 and everything divisible by 3 should be replaced by "FIZZ". Why didn't you do that? Me: I'm pretty sure you didn't ask for…

Marketing: That's great, but can we change it so that it says now with 25% more buzz? And also get anyone who reads FIZZBUZZ to sign up for our newsletter?

Technical Cofounder: Can we release it as a simple REST API that lets you calculate fizz buzz in the cloud?

Re: A non-programmer’s solution to “Fizz Buzz”

#37
post #17

I don't wish to complain but does that look like an infinite loop to you? Programs are just algorithms, a flow diagram is just a different programming language

Programs are more than just algorithms, they are also documentation of that algorithm. Sometimes they also describe checked invariants of the execution of that algorithm (types).

There's probably a lot more to say about programs that doesn't fit within the "just algorithm" view.

Re: A non-programmer’s solution to “Fizz Buzz”

#38
post #29

What's very interesting here is the SICP-style recursive looping, combined with the fact that the non-programmer doesn't expect to be able to pass variables but rather expects to make stateful queries. That is, the infrastructure expected (here written in JS) is: var query = {}; function print(x) { console.log(x); if (typeof x === "number") { query = {last_num: x, time_since: 1}; } else { query.time_since += 1; } } A…

Inspired by this, I translated the whole solution into JS. I renamed your "query" object to "output_state," which seems like a more accurate name.

    var output_state = {};
    function print(x) {
        console.log(x);
        if (typeof x === "number") {
            output_state = {last_num: x, time_since: 1};
        } else {
            output_state.time_since += 1;
        }
    }

    function fizzbuzz() {
        switch(output_state.last_num) {
            case undefined:
                print(1);
                break;
            default:
                var a = output_state.last_num;
                var b = output_state.time_since;
                var number = a + b;

                if (number % 5 !== 0) {
                    if (number % 3 === 0) {
                        print("Fizz");
                    } else {
                        print(number);
                    }
                } else {
                    if (number % 3 === 0) {
                        print("FizzBuzz");
                    } else {
                        print("Buzz");
                    }
                }
        }

        fizzbuzz();
        // Or, correctly: if (number 

Re: A non-programmer’s solution to “Fizz Buzz”

#39
post #30
post #13

I like how instead of giving a procedure to produce the whole answer he created an induction-style algorithm that, given part of an answer, produces the next output. Looks like "The mathematician's solution to Fizz Buzz"

Is this really an "induction-style" algorithm? (I haven't actually heard that term before.) I usually associate induction with taking some large input and shrinking it at each step until you hit some base case. This is really the opposite of induction--it starts with a base case (1) and grows the output, which makes this sound a bit more like co-induction. Another way to think about it would be that he defined a litt…

You're right, it looks like co-induction the term for what I was thinking.

Is it a common FP technique to do local-state-less looping like that? I would expect a tail-recursion solution to pass the next or previous value rather than re-deriving it from reading the output.

Re: A non-programmer’s solution to “Fizz Buzz”

#40

Boss: I need you to write me a program to print the numbers from 1 to 100 Me: Really? Is that really a business requirement? Any other requirements you need done? Boss: Yes, it's your number 1 priority. No, just 1 to 100 Me: Done. Give it a review and I'll push it live. Boss: No! I said 1 to 100 and everything divisible by 3 should be replaced by "FIZZ". Why didn't you do that? Me: I'm pretty sure you didn't ask for…

Marketing: That's great, but can we change it so that it says now with 25% more buzz? And also get anyone who reads FIZZBUZZ to sign up for our newsletter?

Researcher: What is the meaning of FIZZ and BUZZ? What's the definition of the operation by which FIZZ and BUZZ combine into FIZZBUZZ?
Post reply on HN