-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
r/difference-of-squares: 1st iteration
- Loading branch information
Showing
4 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,5 +1,17 @@ | ||
# this is a stub function that takes a natural_number | ||
# and should return the difference-of-squares as described | ||
# in the README.md | ||
difference_of_squares <- function(natural_number) { | ||
square_of_sum <- function(number) { | ||
sum <- number * (number + 1) / 2 | ||
square <- sum ^ 2 | ||
|
||
return(square) | ||
} | ||
|
||
sum_of_squares <- function(number) { | ||
return(number * (number + 1) * (2 * number + 1) / 6) | ||
} | ||
|
||
difference_of_squares <- function(number) { | ||
return(square_of_sum(number) - sum_of_squares(number)) | ||
} |
This file contains 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,65 @@ | ||
Running automated test file(s): | ||
|
||
|
||
=============================================================================== | ||
|
||
Running: ../../.github/citools/r/r-test | ||
|
||
Running R Tests | ||
|
||
R versions: | ||
|
||
R version 4.3.3 (2024-02-29) -- "Angel Food Cake" | ||
Copyright (C) 2024 The R Foundation for Statistical Computing | ||
Platform: x86_64-pc-linux-gnu (64-bit) | ||
|
||
R is free software and comes with ABSOLUTELY NO WARRANTY. | ||
You are welcome to redistribute it under the terms of the | ||
GNU General Public License versions 2 or 3. | ||
For more information about these matters see | ||
https://www.gnu.org/licenses/. | ||
|
||
|
||
Rscript (R) version 4.3.3 (2024-02-29) | ||
|
||
|
||
============================================================================== | ||
|
||
Running: Rscript test_difference-of-squares.R | ||
|
||
Test passed 😀 | ||
Test passed 😸 | ||
Test passed 😸 | ||
Test passed 🥇 | ||
|
||
real 0m0.581s | ||
user 0m0.527s | ||
sys 0m0.055s | ||
|
||
|
||
============================================================================== | ||
|
||
Exit code: 0 | ||
|
||
real 0m0.766s | ||
user 0m0.609s | ||
sys 0m0.167s | ||
|
||
real 0m0.769s | ||
user 0m0.611s | ||
sys 0m0.169s | ||
|
||
=============================================================================== | ||
|
||
Running: misspell ./difference-of-squares.R ./test_difference-of-squares.R | ||
|
||
real 0m0.018s | ||
user 0m0.019s | ||
sys 0m0.009s | ||
|
||
=============================================================================== | ||
|
||
/home/vpayno/git_vpayno/exercism-workspace/r | ||
|
||
=============================================================================== | ||
|