6 kyu

Rainfall

351 of 7,948g964

Description:

dataand data1 are two strings with rainfall records of a few cities for months from January to December. The records of towns are separated by \n. The name of each town is followed by :.

data and towns can be seen in "Your Test Cases:".

Task:

  • function: mean(town, strng) should return the average of rainfall for the city town and the strng data or data1 (In R and Julia this function is called avg).
  • function: variance(town, strng) should return the variance of rainfall for the city town and the strng data or data1.

Examples:

mean("London", data), 51.19(9999999999996) 
variance("London", data), 57.42(833333333374)

Notes:

  • if functions mean or variance have as parameter town a city which has no records return -1 or -1.0 (depending on the language)

  • Don't truncate or round: the tests will pass if abs(your_result - test_result) <= 1e-2 or abs((your_result - test_result) / test_result) <= 1e-6 depending on the language.

  • Shell

    1. Shell tests only variance.
    2. In "function "variance" $1 is "data", $2 is "town".
  • A ref: http://www.mathsisfun.com/data/standard-deviation.html

  • data and data1 (can be named d0 and d1 depending on the language; see "Sample Tests:") are adapted from: http://www.worldclimate.com

Fundamentals
Strings

More By Author:

Check out these other kata created by g964

Stats:

CreatedJan 23, 2016
PublishedJan 23, 2016
Warriors Trained41346
Total Skips12700
Total Code Submissions107579
Total Times Completed7948
Ruby Completions351
Python Completions1998
JavaScript Completions1636
CoffeeScript Completions20
C# Completions491
Haskell Completions87
Clojure Completions96
Java Completions989
C++ Completions457
PHP Completions351
C Completions179
TypeScript Completions230
Swift Completions209
Crystal Completions15
R Completions59
Shell Completions48
OCaml Completions23
Scala Completions168
Kotlin Completions214
F# Completions28
Julia Completions21
PowerShell Completions33
Go Completions261
Nim Completions11
Rust Completions196
Racket Completions14
Fortran Completions3
Pascal Completions4
Perl Completions13
Elm Completions4
D Completions3
Erlang Completions6
Prolog Completions4
Total Stars726
% of votes with a positive feedback rating84% of 1311
Total "Very Satisfied" Votes969
Total "Somewhat Satisfied" Votes271
Total "Not Satisfied" Votes71
Ad
Contributors
  • g964 Avatar
  • matt c Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • monadius Avatar
  • hobovsky Avatar
  • Just4FunCoder Avatar
Ad