7 kyu

Speed Control

277 of 16,534g964

Description:

In John's car the GPS records every s seconds the distance travelled from an origin (distances are measured in an arbitrary but consistent unit). For example, below is part of a record with s = 15:

x = [0.0, 0.19, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0, 2.25]

The sections are:

0.0-0.19, 0.19-0.5, 0.5-0.75, 0.75-1.0, 1.0-1.25, 1.25-1.50, 1.5-1.75, 1.75-2.0, 2.0-2.25

We can calculate John's average hourly speed on every section and we get:

[45.6, 74.4, 60.0, 60.0, 60.0, 60.0, 60.0, 60.0, 60.0]

Given s and x the task is to return as an integer the *floor* of the maximum average speed per hour obtained on the sections of x. If x length is less than or equal to 1 return 0 since the car didn't move.

Example:

With the above data your function gps(s, x) should return 74

Note

With floats it can happen that results depends on the operations order. To calculate hourly speed you can use:

(3600 * delta_distance) / s.

Happy coding!

Fundamentals
Mathematics

Stats:

CreatedNov 15, 2015
PublishedNov 15, 2015
Warriors Trained49230
Total Skips10694
Total Code Submissions85229
Total Times Completed16534
Ruby Completions368
Python Completions3460
JavaScript Completions3392
Haskell Completions277
C# Completions816
Java Completions1805
CoffeeScript Completions21
Clojure Completions160
C++ Completions1434
PHP Completions736
Elixir Completions224
Crystal Completions20
F# Completions83
C Completions926
TypeScript Completions440
OCaml Completions65
Shell Completions95
Kotlin Completions725
Julia Completions36
R Completions150
PowerShell Completions98
Go Completions826
Nim Completions25
Rust Completions446
Reason Completions8
Racket Completions37
Scala Completions130
Dart Completions369
Lua Completions108
Perl Completions28
D Completions11
Erlang Completions19
NASM Completions6
Total Stars423
% of votes with a positive feedback rating85% of 2122
Total "Very Satisfied" Votes1589
Total "Somewhat Satisfied" Votes416
Total "Not Satisfied" Votes117
Ad
Contributors
  • g964 Avatar
  • jhoffner Avatar
  • NaMe613 Avatar
  • imjasonmiller Avatar
  • kazk Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • monadius Avatar
  • hobovsky Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • akar-0 Avatar
  • Just4FunCoder Avatar
  • anusha.j Avatar
  • KayleighWasTaken Avatar
Ad