Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Fizz Buzz Zoom
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Doug Hoffman  
View profile  
 More options Oct 7 2012, 2:45 pm
Newsgroups: comp.lang.forth
From: Doug Hoffman <glide...@gmail.com>
Date: Sun, 07 Oct 2012 14:45:56 -0400
Local: Sun, Oct 7 2012 2:45 pm
Subject: Re: Fizz Buzz Zoom
Don't think there's anything wrong with your solution.

Here's another one I threw together just now:

: divisible-by? ( n1 n2 -- f f ) \ is n1 divisible by n2?
   mod 0= dup ;

: fizz ( n -- f ) \ true if divisible
   3 divisible-by? if ." Fizz" then ;

: buzz ( n -- f ) \ true if divisible
   5 divisible-by? if ." Buzz" then ;

: zoom ( n -- f ) \ true if divisible
   7 divisible-by? if ." Zoom" then ;

: run ( n -- )
    1 do
      cr i fizz
         i buzz or
         i zoom or
         0= if i . then
      loop ;

0 [if]
Comments:
- perhaps more meaningful names
- no need for return stack for keeping i
- a bit less stack thrashing, just 1 dup
- fewer items being tossed around on the stack
- fizz/buzz/zoom could be factored further, not sure it's worth it

No doubt someone else has a more clever solution.
[then]

-Doug


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.