Skip to content

Commit

Permalink
r/difference-of-squares: 1st iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
vpayno committed Apr 16, 2024
1 parent 0238bef commit 853e207
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 2 deletions.
1 change: 1 addition & 0 deletions r/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
- [raindrops](./raindrops/README.md)
- [leap](./leap/README.md)
- [reverse-string](./reverse-string/README.md)
- [difference-of-squares](./difference-of-squares/README.md)
7 changes: 6 additions & 1 deletion r/difference-of-squares/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ Finding the best algorithm for the problem is a key skill in software engineerin

### Based on

Problem 6 at Project Euler - https://projecteuler.net/problem=6
Problem 6 at Project Euler - https://projecteuler.net/problem=6

### My Solution

- [difference-of-squares.R](./difference-of-squares.R)
- [run-tests](./run-tests-r.txt)
14 changes: 13 additions & 1 deletion r/difference-of-squares/difference-of-squares.R
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))
}
65 changes: 65 additions & 0 deletions r/difference-of-squares/run-tests-r.txt
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

===============================================================================

0 comments on commit 853e207

Please sign in to comment.