fizz-buzz.fth 536 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. : true ( -- f ) -1 ;
  2. : false ( -- f ) 0 ;
  3. : div3? ( n -- f )
  4. dup 0=
  5. if
  6. true
  7. else
  8. dup 3 mod 0=
  9. then ;
  10. : div5? ( n -- f )
  11. dup 0=
  12. if
  13. true
  14. else
  15. dup 5 mod 0=
  16. then ;
  17. : fizz ( n -- n )
  18. div3?
  19. if ." fizz" then ;
  20. : buzz ( n -- n )
  21. div5?
  22. if ." buzz" then ;
  23. : fizzbuzz ( n -- )
  24. \ start with a -1 as counter
  25. -1
  26. \ 16 -1
  27. \ begin the loop
  28. begin
  29. \ increase counter, initially to 0
  30. 1+
  31. \ 16 0
  32. dup . fizz buzz cr
  33. \ duplicate for `<=`
  34. 2dup <=
  35. until
  36. 2drop ;
  37. 100 fizzbuzz .s