5 kyu

Perimeter of squares in a rectangle

15,214 of 43,632g964

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

Could you give the sum 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:

alternative text

Hint:

See Fibonacci sequence

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.

perimeter(5)  should return 80
perimeter(7)  should return 216
Mathematics
Algorithms

More By Author:

Check out these other kata created by g964

Stats:

CreatedJul 6, 2015
PublishedJul 6, 2015
Warriors Trained88013
Total Skips19815
Total Code Submissions142951
Total Times Completed43632
Ruby Completions1024
Python Completions15214
Haskell Completions665
Clojure Completions173
Java Completions4248
C# Completions2522
CoffeeScript Completions24
JavaScript Completions8850
C++ Completions3389
PHP Completions1370
Crystal Completions23
F# Completions106
C Completions1799
TypeScript Completions1359
Rust Completions955
Swift Completions459
Go Completions1092
R Completions125
Shell Completions66
Objective-C Completions30
OCaml Completions25
Fortran Completions18
Elixir Completions151
Julia Completions60
Scala Completions234
PowerShell Completions47
Nim Completions19
Racket Completions46
Reason Completions5
Forth Completions27
Kotlin Completions411
Prolog Completions21
Dart Completions282
Pascal Completions15
Raku Completions11
Lua Completions116
Perl Completions18
Elm Completions8
COBOL Completions12
D Completions8
Erlang Completions10
NASM Completions23
Total Stars1103
% of votes with a positive feedback rating86% of 3687
Total "Very Satisfied" Votes2820
Total "Somewhat Satisfied" Votes734
Total "Not Satisfied" Votes133
Ad
Contributors
  • g964 Avatar
  • jhoffner Avatar
  • donaldsebleung Avatar
  • kazk Avatar
  • JohanWiltink Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • dolgov_vv Avatar
  • monadius Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • Haksell Avatar
  • akar-0 Avatar
  • Just4FunCoder Avatar
  • KayleighWasTaken Avatar
Ad