Looking for a benefactor
Description:
The accounts of the "Fat to Fit Club (FFC)" association are supervised by John as a volunteered accountant.
The association is funded through financial donations from generous benefactors. John has a list of
the first n
donations: [14, 30, 5, 7, 9, 11, 15]
He wants to know how much the next benefactor should give to the association so that the
average of the first n + 1
donations should reach an average of 30
.
After doing the math he found 149
. He thinks that he could have made a mistake.
if dons = [14, 30, 5, 7, 9, 11, 15]
then new_avg(dons, 30) --> 149
Could you help him?
Task
The function new_avg(arr, navg)
should return the expected donation
(rounded up to the next integer) that will permit to reach the average navg
.
Should the last donation be a non positive number (<= 0)
John wants us:
to return:
- Nothing in Haskell, Elm
- None in F#, Ocaml, Rust, Scala
-1
in C, D, Fortran, Nim, PowerShell, Go, Pascal, Prolog, Lua, Perl, Erlang
or to throw an error (some examples for such a case):
- IllegalArgumentException() in Clojure, Java, Kotlin
- ArgumentException() in C#
- echo
ERROR
in Shell - argument-error in Racket
- std::invalid_argument in C++
- ValueError in Python
So, he will clearly see that his expectations are not great enough. In "Sample Tests" you can see what to return.
Notes:
- all donations and
navg
are numbers (integers or floats),arr
can be empty. - See examples below and "Sample Tests" to see which return is to be done.
new_avg([14, 30, 5, 7, 9, 11, 15], 92) should return 645
new_avg([14, 30, 5, 7, 9, 11, 15], 2)
should raise an error (ValueError or invalid_argument or argument-error or DomainError or ... )
or return `-1` or ERROR or Nothing or None depending on the language.
Similar Kata:
Stats:
Created | Jan 17, 2016 |
Published | Jan 17, 2016 |
Warriors Trained | 22102 |
Total Skips | 2870 |
Total Code Submissions | 86287 |
Total Times Completed | 9357 |
Ruby Completions | 311 |
Python Completions | 2188 |
JavaScript Completions | 2076 |
CoffeeScript Completions | 18 |
Java Completions | 1082 |
C# Completions | 403 |
Clojure Completions | 102 |
Haskell Completions | 175 |
Elixir Completions | 188 |
TypeScript Completions | 180 |
C++ Completions | 611 |
PHP Completions | 322 |
Crystal Completions | 13 |
F# Completions | 71 |
C Completions | 361 |
OCaml Completions | 57 |
Rust Completions | 417 |
R Completions | 123 |
Nim Completions | 28 |
Shell Completions | 87 |
Kotlin Completions | 348 |
Fortran Completions | 35 |
Julia Completions | 38 |
PowerShell Completions | 76 |
Go Completions | 389 |
Reason Completions | 11 |
Racket Completions | 29 |
Scala Completions | 103 |
Prolog Completions | 28 |
Lua Completions | 74 |
Pascal Completions | 13 |
Perl Completions | 38 |
Elm Completions | 9 |
D Completions | 10 |
Erlang Completions | 11 |
Total Stars | 194 |
% of votes with a positive feedback rating | 79% of 1360 |
Total "Very Satisfied" Votes | 915 |
Total "Somewhat Satisfied" Votes | 321 |
Total "Not Satisfied" Votes | 124 |