Skip to content

Commit 19fa334

Browse files
committed
transferring greatest common divisor calculation to lib
1 parent 846d529 commit 19fa334

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

10/solve.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ adventofcode.day10_get_asteroids = function(input) {
7474
let diff_x = asteroid2.x - asteroid1.x;
7575
let diff_y = asteroid2.y - asteroid1.y;
7676

77-
const gcd = adventofcode.day10_greatest_common_divisor(Math.abs(diff_x), Math.abs(diff_y));
77+
const gcd = adventofcode.greatestCommonDivisor(Math.abs(diff_x), Math.abs(diff_y));
7878

7979
diff_x /= gcd;
8080
diff_y /= gcd;
@@ -108,8 +108,4 @@ adventofcode.day10_line_of_sight = function(asteroid, diff_x, diff_y) {
108108
}
109109

110110
return true;
111-
};
112-
113-
adventofcode.day10_greatest_common_divisor = function(x, y) {
114-
return (!y) ? x : adventofcode.day10_greatest_common_divisor(y, x % y);
115111
};

lib.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ let adventofcode = {
3333
img.src = src;
3434

3535
document.querySelector('#output_area').appendChild(img);
36+
},
37+
greatestCommonDivisor: function(x, y) {
38+
return (!y) ? x : this.greatestCommonDivisor(y, x % y);
39+
},
40+
leastCommonMultiple: function(x, y) {
41+
return Math.abs((x * y) / this.greatestCommonDivisor(x, y));
3642
}
3743
};
3844

0 commit comments

Comments
 (0)