• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

The fizz buzz coding challenge

 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nice!
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Threads! (Just because we can)

 
Bert Bates
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

marc weber wrote:

  • FizzBuzz60 (coming fall 2012)


  • I'm guessing the release date has been pushed back?
     
    Bartender
    Posts: 4568
    9
    • Likes 2
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    Greenhorn
    Posts: 4
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi All,

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

    Check this out.

    Thanks,
    Jose.
     
    Java Cowboy
    Posts: 16084
    88
    Android Scala IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    Ranch Hand
    Posts: 233
    1
    Eclipse IDE Opera Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    Posts: 16084
    88
    Android Scala IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    Master Rancher
    Posts: 4806
    72
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    Bartender
    Posts: 2407
    36
    Scala Python Oracle Postgres Database Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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...
     
    Greenhorn
    Posts: 1
    Clojure
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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

     
    Ranch Hand
    Posts: 687
    Hibernate jQuery Spring
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Ruby:


     
    Greenhorn
    Posts: 11
    Eclipse IDE Java Linux
    • Likes 4
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Commodore BASIC V2:

     
    Matthew Brown
    Bartender
    Posts: 4568
    9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.

     
    Sheriff
    Posts: 3837
    66
    Netbeans IDE Oracle Firefox Browser
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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!
     
    Marshal
    Posts: 79177
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Scott Shipp may not have been aware of the existence of this thread. See this.
     
    Matthew Brown
    Bartender
    Posts: 4568
    9
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
    36
    Scala Python Oracle Postgres Database Linux
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Here's a 2-line Scala version using a for-comprehension:
    Or as one (long) line:
     
    Jesper de Jong
    Java Cowboy
    Posts: 16084
    88
    Android Scala IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Last weekend I've been playing with Kotlin, a very nice new programming language that runs on the JVM by JetBrains.

    Here is my first Scala example (that I posted six years ago!) in Kotlin.
    Probably the syntax highlighting is a bit off, because the highlighter doesn't recognise Kotlin.
     
    Campbell Ritchie
    Marshal
    Posts: 79177
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    What does the -> operator do? Is it a mapsto operator, or a naked guard?
     
    Jesper de Jong
    Java Cowboy
    Posts: 16084
    88
    Android Scala IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Here's another one in Kotlin, with an extension function:
     
    Jesper de Jong
    Java Cowboy
    Posts: 16084
    88
    Android Scala IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Campbell Ritchie wrote:What does the -> operator do? Is it a mapsto operator, or a naked guard?


    It's not an operator, just syntax notation. Just like in a Java switch statement you have "case <value>:" you have this arrow -> here instead of the ":". Yes, you could pronounce it as "maps to".
     
    Campbell Ritchie
    Marshal
    Posts: 79177
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Aaaaaaaah. Thank you.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic