wood burning stoves 2.0*
The moose likes Meaningless Drivel and the fly likes The fizz buzz coding challenge Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Other » Meaningless Drivel
Bookmark "The fizz buzz coding challenge" Watch "The fizz buzz coding challenge" New topic
Author

The fizz buzz coding challenge

Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8803
    
    5
nice!


Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Joel Espinosa
Greenhorn

Joined: Sep 09, 2005
Posts: 2
Threads! (Just because we can)



JAEC
blogmetroblog
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8803
    
    5
I'm wondering whether these integers might want to "friend" each other at some point? If so, it might be interesting to develop a solution that uses a graph database?
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11161
    
  16

marc weber wrote:
  • FizzBuzz60 (coming fall 2012)


  • I'm guessing the release date has been pushed back?


    There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
    Matthew Brown
    Bartender

    Joined: Apr 06, 2010
    Posts: 4343
        
        8

    I've been taking the Coursera compilers class recently. In the spirit of that...here's a solution using the Lexical Analysis tool JFlex.

    The following input file will generate a finite-automata based lexical analyser that will parse an input stream of space/new line delimited numbers and produce the required output. So you just need to feed it a stream containing the range of numbers you want to use.
    Jose George Augustine
    Greenhorn

    Joined: Nov 08, 2012
    Posts: 4
    Hi All,

    http://fizzbuzzjava.blogspot.com/2012/11/fizz-buzz-java-program.html

    Check this out.

    Thanks,
    Jose.
    Jesper de Jong
    Java Cowboy
    Saloon Keeper

    Joined: Aug 16, 2005
    Posts: 14074
        
      16

    Jose George Augustine wrote:http://fizzbuzzjava.blogspot.com/2012/11/fizz-buzz-java-program.html

    Here's my bug report on that one.

    The program doesn't do what the specification says it should do. It prints different words instead of the words that the specification of the problem says it should print.
    Rajdeep Biswas
    Ranch Hand

    Joined: Mar 26, 2012
    Posts: 186

    People at codeacademy.com Javascript trail should see this!


    The biggest gamble will be to ask a question whose answer you know in that it will challenge your theory | www.TechAspire.blogspot.in
    Jose George Augustine
    Greenhorn

    Joined: Nov 08, 2012
    Posts: 4
    Hi Jesper de Jong,
    My intention was just to show the one line function which gives fizz buzz solution.
    But, I didnt see the specification of the problem anywhere in that page.

    Thanks,
    Jose
    Jesper de Jong
    Java Cowboy
    Saloon Keeper

    Joined: Aug 16, 2005
    Posts: 14074
        
      16

    Jose George Augustine wrote:My intention was just to show the one line function which gives fizz buzz solution.
    But, I didnt see the specification of the problem anywhere in that page.

    The Fizz Buzz problem is defined like this:
    Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

    Your program doesn't do this. Instead of "Fizz", "Buzz" or "FizzBuzz" it prints "THREE", "FIVE" or "THREE AND FIVE". Also, in your program the range goes from -50 to 50, not from 1 to 100. So it's not a correct solution for the Fizz Buzz problem.
    Mike Simmons
    Ranch Hand

    Joined: Mar 05, 2008
    Posts: 2994
        
        9
    External links aside, the FizzBuzz problem is also defined at the beginning of this thread. Note that this is page 2 of the thread, and you may have missed the link to page 1.
    chris webster
    Bartender

    Joined: Mar 01, 2009
    Posts: 1615
        
      13

    Late to the party, but had to try out my day-old Coursera-fresh knowledge of SML...

    Bert wrote:
    The JavaRanch addition is to write the program in such a way that it:

    - implements the above
    - is meaningfully different than all previous entries
    - can somehow be defended as a "good" way to go

    "Meaningfully different"? Hm...
    "Good way to go"? Not likely!
    I wish I'd written the Python one-liner though...


    No more Blub for me, thank you, Vicar.
    Dave Gustafson
    Greenhorn

    Joined: Apr 08, 2013
    Posts: 1

    Here's what I think is an interesting take on the challenge:
    - recusive solution
    - certainly not idiomatic Java
    - not at all efficient (might blow the stack if requirements were to change to print 100K elements)
    - but it is functional
    - and it is pure Java

    Devesh H Rao
    Ranch Hand

    Joined: Feb 09, 2002
    Posts: 687

    Ruby:


    Ruud Smith
    Greenhorn

    Joined: Feb 05, 2004
    Posts: 11

    Commodore BASIC V2:

    Matthew Brown
    Bartender

    Joined: Apr 06, 2010
    Posts: 4343
        
        8

    I thought I'd wake this up. Inspired by a MOOC I've been taking (https://www.edx.org/course/louvainx/louvainx-louv1-01x-paradigms-computer-1203), here is a version written using a Deterministic Dataflow approach: a concurrency paradigm that guarantees deterministic behaviour in multi-threaded applications. It's for the Mozart Programming System, using Oz, a multi-paradigm language.



    The model is that we have a Producer, which produces a stream of integers, a Transformer, which converts to fizz/buzz as appropriate, and a Consumer, which prints them out. These are chained together, but each runs in its own thread. Consumers will happily wait for input from producers as necessary.

    Martin Vajsar
    Sheriff

    Joined: Aug 22, 2010
    Posts: 3606
        
      60

    The syntax is a bit obscure to me, but I guess that working in a language where a function is declared as fun is guaranteed to be fun!
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 38016
        
      22
    Scott Shipp may not have been aware of the existence of this thread. See this.
    Matthew Brown
    Bartender

    Joined: Apr 06, 2010
    Posts: 4343
        
        8

    Campbell Ritchie wrote:Scott Shipp may not have been aware of the existence of this thread. See this.

    Yes, seeing that was what reminded me of this, and prompted me to do this version.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: The fizz buzz coding challenge
     
    Similar Threads
    Need help with Incompatible type error
    Divisibity Test Question
    prime number problem
    Calling static method from main
    Code Challenge