6 kyu

Financing Plan on Planet XY140Z-n

869 of 4,886g964

Description:

I need to save some money to buy a gift. I think I can do something like that:

First week (W0) I save nothing on Sunday, 1 on Monday, 2 on Tuesday... 6 on Saturday, second week (W1) 2 on Monday... 7 on Saturday and so on according to the table below where the days are numbered from 0 to 6.

Can you tell me how much I will have for my gift on Saturday evening after I have saved 12? (Your function finance(6) should return 168 which is the sum of the savings in the table).

Imagine now that we live on planet XY140Z-n where the days of the week are numbered from 0 to n (integer n > 0) and where I save from week number 0 to week number n included (in the table below n = 6).

How much money would I have at the end of my financing plan on planet XY140Z-n?

-- Su Mo Tu We Th Fr Sa
W6 12
W5 10 11
W4 8 9 10
W3 6 7 8 9
W2 4 5 6 7 8
W1 2 3 4 5 6 7
W0 0 1 2 3 4 5 6

Example:

finance(5) --> 105
finance(6) --> 168
finance(7) --> 252
finance(5000) --> 62537505000

Note:

your solution will be nicer without loops.

Mathematics
Algorithms

More By Author:

Check out these other kata created by g964

Stats:

CreatedJul 8, 2015
PublishedJul 8, 2015
Warriors Trained14930
Total Skips4000
Total Code Submissions16941
Total Times Completed4886
Ruby Completions129
Python Completions869
Haskell Completions85
Java Completions852
Clojure Completions67
JavaScript Completions600
CoffeeScript Completions25
C# Completions349
TypeScript Completions99
C++ Completions555
Elixir Completions95
PHP Completions214
Crystal Completions17
F# Completions45
C Completions453
Rust Completions164
Swift Completions138
Go Completions247
Nim Completions22
R Completions73
Shell Completions42
OCaml Completions41
Fortran Completions23
Julia Completions29
Scala Completions43
PowerShell Completions25
Reason Completions5
Racket Completions27
Forth Completions20
Factor Completions17
Kotlin Completions49
Prolog Completions16
Pascal Completions13
Raku Completions9
Perl Completions12
COBOL Completions13
Elm Completions10
D Completions9
Erlang Completions12
Total Stars235
% of votes with a positive feedback rating83% of 767
Total "Very Satisfied" Votes560
Total "Somewhat Satisfied" Votes156
Total "Not Satisfied" Votes51
Ad
Contributors
  • g964 Avatar
  • jhoffner Avatar
  • NaMe613 Avatar
  • kazk Avatar
  • Voile Avatar
  • monadius Avatar
  • hobovsky Avatar
  • user8436785 Avatar
  • rge123 Avatar
  • akar-0 Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad