-
-
Notifications
You must be signed in to change notification settings - Fork 360
Euclidean algorithm in coconut #721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
berquist
merged 7 commits into
algorithm-archivists:master
from
Amaras:euclidean_algorithm_in_coconut
Jul 5, 2020
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9a5c102
Added Euclidean algorithm in Coconut
Amaras 081b5a4
Added the language in the .md file
Amaras b3dbf4c
slight modification of the md file
Amaras fd9b90a
Addressed first part of @berquist review
Amaras 1b93aec
Corrected the md file
Amaras 71cfdb2
Final correction of the md file
Amaras 534b557
Added Coconut in book.json
Amaras File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
def euclid_sub(a is int, 0) = a | ||
addpattern def euclid_sub(0, b is int) = b | ||
|
||
addpattern def euclid_sub(a is int, b is int): | ||
if a == b: | ||
return a | ||
elif a < b: | ||
return euclid_sub(a, b - a) | ||
elif b < a: | ||
return euclid_sub(a - b, b) | ||
|
||
|
||
def euclid_mod(a is int, 0) = a | ||
addpattern def euclid_mod(0, b is int) = b | ||
|
||
addpattern def euclid_mod(a is int, b is int) = euclid_mod(b, a % b) | ||
|
||
if __name__ == '__main__': | ||
print('Euclidean mod:', euclid_mod(64 * 67, 64 * 81)) | ||
print('Euclidean sub:', euclid_sub(128 * 12, 128 * 77)) |
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -81,6 +81,8 @@ The algorithm is a simple way to find the *greatest common divisor* (GCD) of two | |||||
|
||||||
{% sample lang="ps1" %} | ||||||
[import:1-14, lang="powershell"](code/powershell/euclidean_algorithm.ps1) | ||||||
{% sample lang="coco" %} | ||||||
[import:1-11, lang="coconut"](code/coconut/euclidean.coco) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(assuming you don't do the case reordering) |
||||||
|
||||||
{% endmethod %} | ||||||
|
||||||
|
@@ -169,6 +171,8 @@ Modern implementations, though, often use the modulus operator (%) like so | |||||
|
||||||
{% sample lang="ps1" %} | ||||||
[import:16-27, lang="powershell"](code/powershell/euclidean_algorithm.ps1) | ||||||
{% sample lang="coco" %} | ||||||
[import:13-21, lang="coconut"](code/coconut/euclidean.coco) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
{% endmethod %} | ||||||
|
||||||
|
@@ -282,6 +286,8 @@ The code snippets were taken from this [Scratch project](https://scratch.mit.edu | |||||
|
||||||
{% sample lang="ps1" %} | ||||||
[import, lang="powershell"](code/powershell/euclidean_algorithm.ps1) | ||||||
{% sample lang="coco" %} | ||||||
[import, lang="coconut"](code/coconut/euclidean.coco) | ||||||
|
||||||
{% endmethod %} | ||||||
|
||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you order this like the Python implementation, where there's implicit fallthrough for the
a == b
case?