Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #34954

Re: So I did "FizzBuzz", in Java!

Path csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Eric Sosman <esosman@comcast-dot-net.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: So I did "FizzBuzz", in Java!
Date Mon, 18 Jul 2016 14:09:45 -0400
Organization A noiseless patient Spider
Lines 40
Message-ID <nmj61j$95o$1@dont-email.me> (permalink)
References <FizzBuzz-20160717163715@ram.dialup.fu-berlin.de> <nmj00i$jae$1@dont-email.me> <1933e39b-6363-4174-8392-602415a61799@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Mon, 18 Jul 2016 18:09:55 -0000 (UTC)
Injection-Info mx02.eternal-september.org; posting-host="2d081e2f7155c28005d4472f67c2f43d"; logging-data="9400"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+i0mgZfo9/PgIKJNYtF0bi"
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0
In-Reply-To <1933e39b-6363-4174-8392-602415a61799@googlegroups.com>
Cancel-Lock sha1:DyfcTrulPa0AG9GGGEQ2WILpX64=
Xref csiph.com comp.lang.java.programmer:34954

Show key headers only | View raw


On 7/18/2016 1:10 PM, Eric Douglas wrote:
> On Monday, July 18, 2016 at 12:27:08 PM UTC-4, Daniel Pitts wrote:
>> Here's one of my solutions:
>> [... using streams ...]
>
> That sounds real fancy.  Is it really more efficient than a basic loop?
> public final class FizzBuzz {
>      public static void main(final java.lang.String[] args) {
>          for (int i = 1; i <= 100; i++) {
>                  final StringBuilder result = new StringBuilder();
>                  if (0 == i % 3) {
>                      result.append("Fizz");
>                  }
>                  if (0 == i % 5) {
>                      result.append("Buzz");
>                  }
>                  if (result.length() == 0) {
>                      result.append(i);
>                  }
>              }
>      }
> }

     1) The streams-based solution is gazillions of times slower
than your basic loop.

     2) Your basic loop is gazillions of times faster than ...
a correct solution.  (Ponder this a while.)

     3) This is not the first "efficiency" question you've asked, which
leads me to fear that you may be well on the way to becoming an addict.
Stop!  Stop now, while you still can!  "Efficiency" is a drug as habit-
forming and as destructive as anything you can find in a darkened back
alley.  If you get hooked, you'll never get clean.  Trust me, I know:
The monkey has ridden my back for half a century despite my strenuous
efforts to dislodge it.  Don't follow my pathway to ruin!

-- 
esosman@comcast-dot-net.invalid
"Don't be afraid of work. Make work afraid of you." -- TLM

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: So I did "FizzBuzz", in Java! Daniel Pitts <usenet@coloraura.com> - 2016-07-18 09:26 -0700
  Re: So I did "FizzBuzz", in Java! Eric Douglas <e.d.programmer@gmail.com> - 2016-07-18 10:10 -0700
    Re: So I did "FizzBuzz", in Java! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-18 14:09 -0400
      Re: So I did "FizzBuzz", in Java! Eric Douglas <e.d.programmer@gmail.com> - 2016-07-18 14:00 -0700
        Re: So I did "FizzBuzz", in Java! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-18 17:30 -0400
          Re: So I did "FizzBuzz", in Java! Eric Douglas <e.d.programmer@gmail.com> - 2016-07-19 05:06 -0700
            Re: So I did "FizzBuzz", in Java! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-19 08:13 -0400
              Re: So I did "FizzBuzz", in Java! Eric Douglas <e.d.programmer@gmail.com> - 2016-07-19 05:18 -0700
        Re: So I did "FizzBuzz", in Java! Martin Gregorie <martin@address-in-sig.invalid> - 2016-07-18 21:59 +0000
        Re: So I did "FizzBuzz", in Java! Arne Vajhøj <arne@vajhoej.dk> - 2016-07-18 19:51 -0400
  Re: So I did "FizzBuzz", in Java! Arne Vajhøj <arne@vajhoej.dk> - 2016-07-18 19:46 -0400

csiph-web