[Codewars] Easy Cyclist`s Training

Easy Cyclist’s Training

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <math.h>
const double GRAVITY_ACC = 9.81 * 3.6 * 60.0;
const double DRAG= 60.0 * 0.3 / 3.6;
const double DELTA_T = 1.0 / 60.0;
const double G_THRUST = 60.0 * 3.6 * 3.6;
const double MASS = 80.0;
const double WATTS0 = 225.0;
const double D_WATTS = 0.5;

int temps(double v0, double slope, double dTot) {
double t = 0., gamma = 0., v = v0, d = 0., watts = WATTS0;
while(d <= dTot) {
gamma= -GRAVITY_ACC*sin(atan(slope/100)) - DRAG*abs(v)*abs(v)/MASS + ((watts>0 && v>0)? G_THRUST*watts/(v*MASS):0);
if (abs(gamma)<=1e-5) gamma=0;
watts-=D_WATTS*DELTA_T;
v+=gamma*DELTA_T;
if (v-3.0<=1e-2) return -1;
d+=v*DELTA_T/60.0 ;
t+=DELTA_T;
}
return round(t);
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2023/05/09/PS/Codewars/easy-cyclists-training/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.