Last active
October 8, 2015 07:58
-
-
Save ytnobody/3302412 to your computer and use it in GitHub Desktop.
A practice for gforth (fizzbuzz question)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| : SEQ ( nx ny -- nx ... ny ) | |
| SWAP OVER OVER | |
| < IF | |
| BEGIN | |
| OVER 1 + SWAP | |
| OVER OVER >= | |
| UNTIL | |
| DROP | |
| ELSE | |
| BEGIN | |
| OVER 1 - SWAP | |
| OVER OVER <= | |
| UNTIL | |
| DROP | |
| ENDIF | |
| ; | |
| : FIZZBUZZ ( n -- ) | |
| DUP DUP | |
| 3 MOD 0 = SWAP | |
| 5 MOD 0 = SWAP | |
| OVER OVER | |
| IF ." Fizz" ENDIF | |
| IF ." Buzz" ENDIF | |
| + 0 = | |
| IF DUP . | |
| ELSE SPACE | |
| ENDIF | |
| DROP | |
| ; | |
| : EACH ( n1 xt -- ? ) | |
| BEGIN | |
| ['] SWAP CATCH | |
| 0 = | |
| WHILE | |
| OVER EXECUTE | |
| REPEAT | |
| ; | |
| 1 100 SEQ | |
| :NONAME FIZZBUZZ ; EACH | |
| CR | |
| BYE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment