5 kyu

Perimeter of squares in a rectangle

15,403 of 44,122g964

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

Stats:

CreatedJul 6, 2015
PublishedJul 6, 2015
Warriors Trained88821
Total Skips19921
Total Code Submissions144068
Total Times Completed44122
Ruby Completions1029
Python Completions15403
Haskell Completions669
Clojure Completions173
Java Completions4279
C# Completions2543
CoffeeScript Completions24
JavaScript Completions8935
C++ Completions3428
PHP Completions1385
Crystal Completions24
F# Completions108
C Completions1811
TypeScript Completions1391
Rust Completions970
Swift Completions461
Go Completions1111
R Completions127
Shell Completions66
Objective-C Completions30
OCaml Completions26
Fortran Completions18
Elixir Completions152
Julia Completions60
Scala Completions236
PowerShell Completions49
Nim Completions21
Racket Completions46
Reason Completions5
Forth Completions27
Kotlin Completions420
Prolog Completions21
Dart Completions294
Pascal Completions15
Raku Completions12
Lua Completions119
Perl Completions20
Elm Completions8
COBOL Completions12
D Completions8
Erlang Completions11
NASM Completions23
Total Stars1120
% of votes with a positive feedback rating86% of 3705
Total "Very Satisfied" Votes2831
Total "Somewhat Satisfied" Votes740
Total "Not Satisfied" Votes134
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