Robinson Crusoe decides to explore his isle. On a sheet of paper he plans the following process.
His hut has coordinates origin = [0, 0]
. From that origin he walks a given distance d
on a line
that has a given angle ang
with the x-axis. He gets to a point A.
(Angles are measured with respect to the x-axis)
From that point A he walks the distance d
multiplied by a constant distmult
on a line that
has the angle ang
multiplied by a constant angmult
and so on and on.
We have d0 = d
, ang0 = ang
; then d1 = d * distmult
, ang1 = ang * angmult
etc ...
Let us suppose he follows this process n times.
What are the coordinates lastx, lasty
of the last point?
The function crusoe
has parameters;
- n : numbers of steps in the process
- d : initial chosen distance
- ang : initial chosen angle in degrees
- distmult : constant multiplier of the previous distance
- angmult : constant multiplier of the previous angle
crusoe(n, d, ang, distmult, angmult)
should return
lastx, lasty
as an array or a tuple depending on the language.
crusoe(5, 0.2, 30, 1.02, 1.1)
->
The successive x
are : 0.0, 0.173205, 0.344294, 0.511991, 0.674744, 0.830674
(approximately)
The successive y
are : 0.0, 0.1, 0.211106, 0.334292, 0.47052, 0.620695
(approximately)
and
lastx: 0.8306737544381833
lasty: 0.620694691344071
Successive points:
- x:
0.0, 0.9659..., 1.8319..., 2.3319..., 1.8319...
- y:
0.0, 0.2588..., 0.7588..., 1.6248..., 2.4908...
Please could you ask before translating: some translations are already written and published when/if the kata is approved.