/usr/share/games/tf/factoral.tf is in tf 1:4.0s1-20.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ;;;; factorial macros
;;; Not very useful, but they do demonstrate some macro programming techniques.
;; recursive factorial
/def rfact = \
/if ( {1} < 0 ) \
/echo -e %% %0: negative argument%; \
/elseif ( {1} == 0 ) \
/result 1%; \
/else \
/result {1} * rfact({1} - 1)%; \
/endif
;; iterative factorial - more efficient
/def ifact = \
/if ( {1} < 0 ) \
/echo -e %% %0: negative argument%; \
/else \
/let n=%1%; \
/let result=1%; \
/while (n) \
/test (result:=result * n), --n%; \
/done%; \
/result result%; \
/endif
|