Fizzbuzz, again
|
09-25-2017, 09:45 AM
(This post was last modified: 09-25-2017 09:58 AM by brickviking.)
Post: #1
|
|||
|
|||
Fizzbuzz, again
The last time I saw this in the forums was in a FOCAL discussion, but I first ran into it somewhere else. Those of you who know what FIZZBUZZ is, won't need this explanation, but for everyone else who's not in the loop, fizzbuzz is a children's number game.
Numbers are counted from 1 to ... however many. There's a twist. If the number's divisible by 3, you say "fizz". If the number's divisible by 5, you say "buzz" instead. If it's divisible by both 3 and 5, you say fizzbuzz. Everything else, you simply say the number. A sample run would go like this: 1, 2, fizz, 4, buzz, fizz, 7, 8, fizz, buzz, 11, fizz, 13, 14, fizzbuzz, 16, 17, fizz, ... etc. Here's my rough-cut example, I've had a rat-through and removed most of the bugs I know about. Could you suggest improvements? progname: FBTST Code: \<< To get the complete sequence of numbers (at least to whatever I specify on the stack), I use the following dead simple loop. Progname: FBLP Code: \<< My ideal would be to not need two spare vars and to operate using just the stack, but I then have to start learning how to use ROLL, PICK, or ROT in various incarnations. I don't know whether that will make the program larger, but I'll give that a go within the next few days. (Post 97) Regards, BrickViking HP-50g |Casio fx-9750G+ |Casio fx-9750GII (SH4a) |
|||
09-25-2017, 08:08 PM
(This post was last modified: 09-25-2017 08:09 PM by Dave Britten.)
Post: #2
|
|||
|
|||
RE: Fizzbuzz, again
Under normal circumstances, you don't have to RCL variable values. Just do K rather than 'K' RCL, for example.
Here's a little quick-and-dirty version I banged out on my 48SX that demonstrates using a local subroutine, and doing more "on the stack". Code: \<< |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)