From 7a77404ef66e2e74140e258faf7b7ec576f349c9 Mon Sep 17 00:00:00 2001 From: "Siarhei.Kavalchuk" Date: Mon, 12 Dec 2016 09:37:10 +0300 Subject: [PATCH 1/2] new task 'Perimeter of squares in a rectangle' --- .../perimeter-of-squares.js | 3 ++ .../perimeter-of-squares_test.js | 9 ++++ katas/perimeter-of-squares/readme.md | 41 +++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 katas/perimeter-of-squares/perimeter-of-squares.js create mode 100644 katas/perimeter-of-squares/perimeter-of-squares_test.js create mode 100644 katas/perimeter-of-squares/readme.md diff --git a/katas/perimeter-of-squares/perimeter-of-squares.js b/katas/perimeter-of-squares/perimeter-of-squares.js new file mode 100644 index 0000000..1e15d22 --- /dev/null +++ b/katas/perimeter-of-squares/perimeter-of-squares.js @@ -0,0 +1,3 @@ +function perimeter(n) { + return ... fib... +} \ No newline at end of file diff --git a/katas/perimeter-of-squares/perimeter-of-squares_test.js b/katas/perimeter-of-squares/perimeter-of-squares_test.js new file mode 100644 index 0000000..8f1d431 --- /dev/null +++ b/katas/perimeter-of-squares/perimeter-of-squares_test.js @@ -0,0 +1,9 @@ +describe('perimeter function', function() { + + it('should return right perimeter of squares in a rectangle', function() { + expect(perimeter(5)).toBe(80); + expect(perimeter(7)).toBe(216); + expect(perimeter(20)).toBe(114624); + expect(perimeter(30)).toBe(14098308); + }); +}); diff --git a/katas/perimeter-of-squares/readme.md b/katas/perimeter-of-squares/readme.md new file mode 100644 index 0000000..a55213c --- /dev/null +++ b/katas/perimeter-of-squares/readme.md @@ -0,0 +1,41 @@ +####Description: + +The drawing shows 6 squares the sides of which have a length of 1, 1, 2, 3, 5, 8. It's easy to see that the sum of the perimeters of these squares is : 4 * (1 + 1 + 2 + 3 + 5 + 8) = 4 * 20 = 80 + +Say that S(n) is the nth term of the above sum. So + +S(0) = 1, S(1) = 1, S(2) = 2, ... , S(5) = 8 + +Could you give the sum S of the perimeters of all the squares in a rectangle when there are n + 1 squares disposed in the same manner as in the drawing: + +S = S(0) + S(1) + ... + S(n) ? + + + +###Hint: + See Fibonacci sequence and beware of rather big n:-) + +###Ref: + http://oeis.org/A000045 + +The function perimeter has for parameter n where n + 1 is the number of squares (they are numbered from 0 to n) and returns the total perimeter of all the squares. + + JS: Due to a misspelling in the reference solution for random tests, + have an outer auxiliary function that calculates Fibonacci numbers, + name this outer function fib. + (More than 500 CW passed the kata so it is now impossible to change the random tests). + +####Example: + +```js +perimeter(5) --> 80 + +perimeter(7) --> 216 + +``` + +See [tests in perimeter-of-squares_test.js](https://github.com/AlexVvx/code-wars/blob/master/katas/perimeter-of-squares/perimeter-of-squares_test.js) + +#####[Original Kata](https://www.codewars.com/kata/perimeter-of-squares-in-a-rectangle) + +Good luck From 97d57838b33b9e09b7d5eaa4039ee5c8a712559c Mon Sep 17 00:00:00 2001 From: "Siarhei.Kavalchuk" Date: Mon, 12 Dec 2016 09:40:46 +0300 Subject: [PATCH 2/2] add image of fibonacci sequence --- katas/perimeter-of-squares/perimeter-of-squares.js | 4 ++-- katas/perimeter-of-squares/readme.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/katas/perimeter-of-squares/perimeter-of-squares.js b/katas/perimeter-of-squares/perimeter-of-squares.js index 1e15d22..787a705 100644 --- a/katas/perimeter-of-squares/perimeter-of-squares.js +++ b/katas/perimeter-of-squares/perimeter-of-squares.js @@ -1,3 +1,3 @@ function perimeter(n) { - return ... fib... -} \ No newline at end of file + //return result +} diff --git a/katas/perimeter-of-squares/readme.md b/katas/perimeter-of-squares/readme.md index a55213c..436a96d 100644 --- a/katas/perimeter-of-squares/readme.md +++ b/katas/perimeter-of-squares/readme.md @@ -10,10 +10,10 @@ Could you give the sum S of the perimeters of all the squares in a rectangle whe S = S(0) + S(1) + ... + S(n) ? - +![Fibonacci sequence image](http://i.imgur.com/EYcuB1wm.jpg) ###Hint: - See Fibonacci sequence and beware of rather big n:-) + See Fibonacci sequence and beware of rather big n :-) ###Ref: http://oeis.org/A000045