Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #47221
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Paul Rubin <no.email@nospam.invalid> |
| Newsgroups | comp.lang.forth |
| Subject | Re: fizzbuzz problem in forth |
| Date | Mon, 16 May 2016 15:09:10 -0700 |
| Organization | A noiseless patient Spider |
| Lines | 26 |
| 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> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | mx02.eternal-september.org; posting-host="589dd00be5ee573d7046ed589be3c50c"; logging-data="20302"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18/1jpNoMpIOTNWSAti51Qu" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
| Cancel-Lock | sha1:6wbyNZsVNiOayFGtUvzAa8rD3Nc= sha1:3AROlrQJiXSNFaC7OI1vpqrIBRM= |
| Xref | csiph.com comp.lang.forth:47221 |
Show key headers only | 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
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