Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions katas/perimeter-of-squares/perimeter-of-squares.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function perimeter(n) {
//return result
}
9 changes: 9 additions & 0 deletions katas/perimeter-of-squares/perimeter-of-squares_test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
41 changes: 41 additions & 0 deletions katas/perimeter-of-squares/readme.md
Original file line number Diff line number Diff line change
@@ -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) ?

![Fibonacci sequence image](http://i.imgur.com/EYcuB1wm.jpg)

###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