diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2017-07-02 10:26:35 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2017-07-02 10:26:35 +0300 |
commit | de9d2dd966a0e9f9de5c36f5578487cd4deb5a9f (patch) | |
tree | affdef8629d8d680440e615b1e51df4d909a9a4c | |
parent | d0577298fd2be72ec4e51ae4703ec563e63119a6 (diff) | |
download | gcd-de9d2dd966a0e9f9de5c36f5578487cd4deb5a9f.tar.gz |
Add Forth
-rw-r--r-- | gcd.fs | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -0,0 +1,37 @@ +: gcd ( a b -- d ) + 2dup > if swap endif + over mod + dup 0 <> if recurse else drop endif + ; + +: gcdn ( a1 a2 .. an n -- d ) + dup 1 > + if + 1 - rot rot + gcd + swap + recurse + else + drop + endif + ; + + +\ This is gforth-specific. +\ Usage: +\ # gforth ./gcd.fs 11 22 33 121 +\ 11 + +: main + 0 >r + begin + next-arg 2dup 0 0 d<> while + s>unumber? if drop else abort endif + r> 1 + >r + repeat + 2drop + r> gcdn . cr + ; + +main bye + |