Last active
February 6, 2021 22:57
-
-
Save righ1113/a0770ca1f29c1d34fcdbe3315f7c8ef7 to your computer and use it in GitHub Desktop.
Forth でコラッツ
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
| \ s" collatz.f" included | |
| : m3p1 ( n -- n' ) | |
| 3 * 1 + ; | |
| : choice ( n b -- n' ) | |
| 1 = if m3p1 else 2 / then ; \ 比較対象は消える | |
| : myMod2 ( n -- n n b ) | |
| dup dup 2 mod ; | |
| : collatz ( n -- n a b .. 1 ) | |
| recursive dup 1 = if else myMod2 choice collatz then ; | |
| : dangerAllOut ( .. a b -- ) | |
| recursive . dangerAllOut ; \ 関数合成じゃないよ | |
| : safeAllOut ( .. a b -- ) | |
| recursive depth 0 = if else . safeAllOut then ; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment