-
-
Notifications
You must be signed in to change notification settings - Fork 359
Euclidean algorithm: Output standardization #877
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
Changes from 29 commits
314a085
abbd81a
195fe6f
bad949d
719cd55
1a2f753
0c640e3
f6b4c16
e525f06
b443f66
27afabf
328e8a4
9f95a61
511b446
42fd666
3095ea8
7edccc7
cd1def4
f5f95fb
18dc8ad
7b18665
1f77cc2
84210b0
c0d00fa
0d87122
0de4c6c
ab4f8c2
19033a9
a7e318d
90b6858
fe5f734
dec2dbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,12 +38,18 @@ PROGRAM euclidean | |
IMPLICIT NONE | ||
INTEGER :: a, b, euclid_sub, euclid_mod | ||
|
||
a = 24 | ||
b = 27 | ||
WRITE(*,*) 'Subtraction method: GCD is: ', euclid_sub(a, b) | ||
a = 64 * 67 | ||
b = 64 * 81 | ||
|
||
a = 24 | ||
b = 27 | ||
WRITE(*,*) 'Modulus method: GCD is: ', euclid_mod(a, b) | ||
WRITE(*,'(a)') '[#]' | ||
WRITE(*,'(a)') 'Modulus-based euclidean algorithm result:' | ||
WRITE(*, '(g0)') euclid_mod(a, b) | ||
|
||
a = 128 * 12 | ||
b = 128 * 77 | ||
|
||
WRITE(*,'(a)') '[#]' | ||
WRITE(*,'(a)') 'Subtraction-based euclidean algorithm result::' | ||
WRITE(*, '(g0)') euclid_sub(a, b) | ||
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. Did we just not run the fortran code before? 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. We ran the two methods the other way around |
||
|
||
END PROGRAM euclidean |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ object Euclid { | |
def euclid_sub(a: Int, b: Int): Int = | ||
(Math.abs(a), Math.abs(b)) match { | ||
case (0, _) | (_, 0) => 0 | ||
case (x, y) if x < y => euclid(x, y - x) | ||
case (x, y) if x > y => euclid(x - y, y) | ||
case (x, y) if x < y => euclid_sub(x, y - x) | ||
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. Wait, how did this code run before? 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. It didn't. |
||
case (x, y) if x > y => euclid_sub(x - y, y) | ||
case _ => a | ||
} | ||
|
||
|
@@ -15,8 +15,10 @@ object Euclid { | |
} | ||
|
||
def main(args: Array[String]): Unit = { | ||
println(euclid_sub(151 * 899, 151 * 182)) | ||
println(euclid_mod(151 * 899, 151 * 182)) | ||
println("[#]\nModulus-based euclidean algorithm result:") | ||
println(euclid_mod(64 * 67, 64 * 81)) | ||
println("[#]\nSubtraction-based euclidean algorithm result:") | ||
println(euclid_sub(128 * 12, 128 * 77)) | ||
} | ||
|
||
} |
Uh oh!
There was an error while loading. Please reload this page.