File tree 2 files changed +53
-0
lines changed
2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .*;
2
+
3
+ /**
4
+ * EuclideanAlgorithm
5
+ */
6
+ public class EuclideanAlgorithm {
7
+
8
+ public static void main (String [] args ) {
9
+ int a = 221 ;
10
+ int b = 143 ;
11
+
12
+ long start = System .nanoTime ();
13
+
14
+ while (true ) {
15
+ int r = a % b ;
16
+
17
+ if (r == 0 ) {
18
+ System .out .println ("Greatest common factor is '" + b + "'" );
19
+ break ;
20
+ }
21
+
22
+ a = b ;
23
+ b = r ;
24
+ }
25
+
26
+ long end = System .nanoTime ();
27
+
28
+ System .out .println ("Exec time: " + (end - start ) / 1000000f + " ms" );
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+ require 'time'
2
+
3
+ class EuclideanAlgorithm
4
+ a = 221
5
+ b = 143
6
+
7
+ start_time = Time . now
8
+
9
+ loop do
10
+ r = a % b
11
+
12
+ break if r == 0
13
+
14
+ a = b
15
+ b = r
16
+ end
17
+
18
+ puts "Greatest common factor is '#{ b } '"
19
+
20
+ end_time = Time . now
21
+
22
+ puts "Exec time: #{ ( end_time - start_time ) * 100000 } ms"
23
+ end
You can’t perform that action at this time.
0 commit comments