Last active
August 13, 2022 21:52
-
-
Save ericvoorhis/bf8e067eafae9ad759e22cf3dd6f9b1a to your computer and use it in GitHub Desktop.
An emojicode (https://github.com/emojicode/emojicode) program for computing the greatest common divisor of two given integers
This file contains 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
๐ ๐ | |
๐ด I used the following wiki page as a reference: | |
๐ด https://simple.wikipedia.org/wiki/Euclidean_algorithm | |
๐ด The following callable (What emojicode calls functions) named gcd | |
๐ด takes two integers a and b (each of type ๐ or better known as "int") | |
๐ด and returns (โก๏ธ) the greatest common divisor between them. | |
๐ฆ gcd ๐ a๐ b๐ โก๏ธ ๐ | |
๐ฎ m a | |
๐ฎ n b | |
๐ด Swap a and b if b is larger | |
๐ โถ๏ธ b a ๐ | |
๐ฎ m b | |
๐ฎ n a | |
๐ | |
๐ด While n > 0, calculate remainder and shift numbers | |
๐ด over as done in the interations of Euclid's algorithm. | |
๐ โถ๏ธ n 0 ๐ | |
๐ฆ r ๐ฎ m n | |
๐ฎ m n | |
๐ฎ n r | |
๐ | |
๐ m | |
๐ | |
๐ด Call the gcd callable that we defined above using ๐ญ | |
๐ด with a few examples. | |
๐ฆ result1 ๐ญ gcd 675 40 | |
๐ฆ result2 ๐ญ gcd 40 675 | |
๐ฆ result3 ๐ญ gcd 13 13 ๐ด a equals b | |
๐ฆ result4 ๐ญ gcd 37 600 ๐ด first argument is prime | |
๐ฆ result5 ๐ญ gcd 20 100 ๐ด first argument divides the second arg | |
๐ฆ result6 ๐ญ gcd 624129 2061517 | |
๐ ๐ช ๐คgcd(675, 40) = ๐ค ๐ก result1 10 ๐ช ๐ด outputs 5 | |
๐ ๐ช ๐คgcd(40, 675) = ๐ค ๐ก result2 10 ๐ช ๐ด outputs 5 | |
๐ ๐ช ๐คgcd(13, 13) = ๐ค ๐ก result3 10 ๐ช ๐ด outputs 13 | |
๐ ๐ช ๐คgcd(37, 600) = ๐ค ๐ก result4 10 ๐ช ๐ด outputs 1 | |
๐ ๐ช ๐คgcd(20, 100) = ๐ค ๐ก result5 10 ๐ช ๐ด outputs 20 | |
๐ ๐ช ๐คgcd(624129, 2061517) = ๐ค ๐ก result6 10 ๐ช ๐ด outputs 18913 | |
๐ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment