Skip to content

Commit

Permalink
Rename lcm() and gcd() to LCM() and GCD()
Browse files Browse the repository at this point in the history
  • Loading branch information
EllaKaye committed Jan 1, 2024
1 parent 0881bf4 commit 5a25138
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
4 changes: 2 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(GCD)
export(LCM)
export(aoc_delete_day)
export(aoc_delete_intro)
export(aoc_delete_year)
Expand All @@ -14,6 +16,4 @@ export(aoc_new_year)
export(aoc_url)
export(aoc_url_input)
export(extract_numbers)
export(gcd)
export(lcm)
export(lines_to_matrix)
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
* Use `readr::read_table()` instead of `readr::read_delim()` in `aoc_input_data_frame()`
* Add user agent to `aoc_get_input()`
* Add `extract_numbers()` to extract all numbers from a string
* Add `gcd()` and `lcm()` for finding greatest common divisor and lowest common multiple
* Add `GCD()` and `LCM()` for finding greatest common divisor and lowest common multiple
* Add `lines_to_matrix()`
20 changes: 10 additions & 10 deletions R/maths-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#' @return The greatest common divisor of x and y
#' @export
#'
#' @examples gcd(12, 18)
#' @examples gcd(12, 0)
#' @examples gcd(13, 2)
gcd <- function(x, y) {
#' @examples GCD(12, 18)
#' @examples GCD(12, 0)
#' @examples GCD(13, 2)
GCD <- function(x, y) {
while (y != 0) {
t <- y
y <- x %% y
Expand All @@ -21,11 +21,11 @@ gcd <- function(x, y) {
}


#' @rdname gcd
#' @rdname GCD
#' @export
#' @examples lcm(12, 18)
#' @examples lcm(2, 6)
#' @examples lcm(3, 5)
lcm <- function(x, y) {
x * y / gcd(x, y)
#' @examples LCM(12, 18)
#' @examples LCM(2, 6)
#' @examples LCM(3, 5)
LCM <- function(x, y) {
x * y / GCD(x, y)
}
4 changes: 2 additions & 2 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ reference:
- extract_numbers
- title: "Maths helper functions"
contents:
- gcd
- lcm
- GCD
- LCM
22 changes: 11 additions & 11 deletions man/gcd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions tests/testthat/test-maths-helpers.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# write tests for gcd
test_that("gcd works", {
expect_equal(gcd(12, 18), 6)
expect_equal(gcd(12, 0), 12)
expect_equal(gcd(13, 2), 1)
# write tests for GCD
test_that("GCD works", {
expect_equal(GCD(12, 18), 6)
expect_equal(GCD(12, 0), 12)
expect_equal(GCD(13, 2), 1)
})

# write tests for lcm
test_that("lcm works", {
expect_equal(lcm(12, 18), 36)
expect_equal(lcm(2, 6), 6)
expect_equal(lcm(3, 5), 15)
# write tests for LCM
test_that("LCM works", {
expect_equal(LCM(12, 18), 36)
expect_equal(LCM(2, 6), 6)
expect_equal(LCM(3, 5), 15)
})

0 comments on commit 5a25138

Please sign in to comment.