• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The fizz buzz coding challenge

 
Bert Bates
author
Sheriff
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nice!
 
Joel Espinosa
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Threads! (Just because we can)

 
Bert Bates
author
Sheriff
Posts: 8898
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12083
29
Chrome Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
marc weber wrote:
  • FizzBuzz60 (coming fall 2012)


  • I'm guessing the release date has been pushed back?
     
    Matthew Brown
    Bartender
    Posts: 4565
    8
    • Likes 2
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 15205
    36
    Android IntelliJ IDE Java Scala Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 206
    1
    Eclipse IDE Java Opera
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    People at codeacademy.com Javascript trail should see this!
     
    Jose George Augustine
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 15205
    36
    Android IntelliJ IDE Java Scala Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 3028
    10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 2407
    32
    Linux Oracle Postgres Database Python Scala
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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...
     
    Dave Gustafson
    Greenhorn
    Posts: 1
    Clojure
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 687
    Hibernate jQuery Spring
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ruby:


     
    Ruud Smith
    Greenhorn
    Posts: 11
    Eclipse IDE Java Linux
    • Likes 3
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Commodore BASIC V2:

     
    Matthew Brown
    Bartender
    Posts: 4565
    8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 3751
    62
    Chrome Netbeans IDE Oracle
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 48378
    56
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Scott Shipp may not have been aware of the existence of this thread. See this.
     
    Matthew Brown
    Bartender
    Posts: 4565
    8
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    chris webster
    Bartender
    Posts: 2407
    32
    Linux Oracle Postgres Database Python Scala
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Here's a 2-line Scala version using a for-comprehension:
    Or as one (long) line:
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic