1
0
Fork 0
mirror of https://gitlab.com/mfocko/CodeWars.git synced 2024-09-08 01:26:57 +02:00
CodeWars/7kyu/speed_control/solution.c
Matej Focko fc899b0b02
chore: initial commit
Signed-off-by: Matej Focko <mfocko@redhat.com>
2021-12-28 16:19:58 +01:00

20 lines
334 B
C

#include <math.h>
int gps(int s, double* x, int sz) {
if (sz < 2) {
return 0;
}
double maxDiff = x[1] - x[0];
int maxIndex = 0;
for (int i = 0; i < sz - 1; i++) {
double diff = x[i + 1] - x[i];
if (diff > maxDiff) {
maxDiff = diff;
maxIndex = i;
}
}
return floor((3600 * maxDiff) / s);
}