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


Groups > comp.lang.forth > #47221

Re: fizzbuzz problem in forth

From Paul Rubin <no.email@nospam.invalid>
Newsgroups comp.lang.forth
Subject Re: fizzbuzz problem in forth
Date 2016-05-16 15:09 -0700
Organization A noiseless patient Spider
Message-ID <8760udodtl.fsf@jester.gateway.pace.com> (permalink)
References <2210aa04-1df4-4328-bf8c-66fbf845609c@googlegroups.com> <f2c2561c-5208-452d-97b7-3aff17789c02@googlegroups.com> <871t566dwf.fsf@jester.gateway.pace.com> <2016May13.145248@mips.complang.tuwien.ac.at>

Show all headers | View raw


anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
> Of course, using >STRING-EXECUTE to find out if the output of
> FIZZBUZZ1 is empty is very heavyweight.

Yes, and also mathematically unsatisfying imho.  The pattern in
generalized fizzbuzz is "IF this-divisor THEN that-string" and making
the empty string special is a code smell.  I've seen a number of
e.g. Python solutions like that, which don't seem great for the same
reason.

>  A more Forth-like solution is:
> : fizzbuzz1 ( n -- f )
>     true
>     over 3 mod 0= if ." fizz" drop false then
>     over 5 mod 0= if ." buzz" drop false then
>     nip ;     ...

Here's my solution from some time back:

: fout ( addr u n d -- flag ) mod 0= if type 0 else 2drop 1 then ;
: fb.1 ( n -- flag ) >r
    s" Fizz" r@ 3 fout
    s" Buzz" r> 5 fout
    and ;
: fb ( n -- ) dup fb.1 if . else drop then cr ;
: run ( -- ) 20 1 do i fb loop ;

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


Thread

fizzbuzz problem in forth murphy.darin@gmail.com - 2016-05-12 16:17 -0700
  Re: fizzbuzz problem in forth Paul Rubin <no.email@nospam.invalid> - 2016-05-12 16:43 -0700
    Re: fizzbuzz problem in forth murphy.darin@gmail.com - 2016-05-12 17:22 -0700
    Re: fizzbuzz problem in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-05-13 12:52 +0000
      Re: fizzbuzz problem in forth Paul Rubin <no.email@nospam.invalid> - 2016-05-16 15:09 -0700
        Re: fizzbuzz problem in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-05-17 13:49 +0000
          Re: fizzbuzz problem in forth Paul Rubin <no.email@nospam.invalid> - 2016-05-17 11:14 -0700
            Re: fizzbuzz problem in forth anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2016-05-18 12:36 +0000
              Re: fizzbuzz problem in forth Paul Rubin <no.email@nospam.invalid> - 2016-05-20 21:55 -0700
              Re: fizzbuzz problem in forth julian.fondren@endurance.com - 2016-06-20 20:20 -0700
        Re: fizzbuzz problem in forth hughaguilar96@gmail.com - 2016-05-17 12:26 -0700
    Re: fizzbuzz problem in forth Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2016-05-15 21:42 +0100
      Re: fizzbuzz problem in forth hughaguilar96@gmail.com - 2016-05-15 14:41 -0700
        Re: fizzbuzz problem in forth hughaguilar96@gmail.com - 2016-05-15 15:15 -0700
          Re: fizzbuzz problem in forth hughaguilar96@gmail.com - 2016-05-15 17:38 -0700
            Re: fizzbuzz problem in forth murphy.darin@gmail.com - 2016-05-15 19:01 -0700
              Re: fizzbuzz problem in forth hughaguilar96@gmail.com - 2016-05-15 19:51 -0700
                Re: fizzbuzz problem in forth murphy.darin@gmail.com - 2016-05-15 20:48 -0700
                Re: fizzbuzz problem in forth hughaguilar96@gmail.com - 2016-05-16 07:51 -0700
          Re: fizzbuzz problem in forth "WJ" <w_a_x_man@yahoo.com> - 2016-05-25 08:31 +0000
            Re: fizzbuzz problem in forth "WJ" <w_a_x_man@yahoo.com> - 2016-05-27 19:06 +0000
    Re: fizzbuzz problem in forth humptydumpty <ouatubi@gmail.com> - 2016-05-18 13:19 -0700
      Re: fizzbuzz problem in forth hughaguilar96@gmail.com - 2016-05-18 17:49 -0700
        Re: fizzbuzz problem in forth humptydumpty <ouatubi@gmail.com> - 2016-05-18 21:17 -0700
          Re: fizzbuzz problem in forth hughaguilar96@gmail.com - 2016-05-19 07:38 -0700
            Re: fizzbuzz problem in forth "Kerr Mudd-John" <admin@127.0.0.1> - 2016-06-20 19:24 -0100
              Re: fizzbuzz problem in forth endlessboomcapitalism@gmail.com - 2016-06-20 15:03 -0700
        Re: fizzbuzz problem in forth Albert van der Horst <albert@cherry.spenarnc.xs4all.nl> - 2016-05-19 13:07 +0000
          Re: fizzbuzz problem in forth Paul Rubin <no.email@nospam.invalid> - 2016-05-19 12:22 -0700
            Re: fizzbuzz problem in forth Albert van der Horst <albert@cherry.spenarnc.xs4all.nl> - 2016-05-20 23:51 +0000

csiph-web