# Software Programming

Kunuk Nykjaer

## while the sun hangs in the sky and the desert has sand

I stumbled upon this funny implementation of a programming exercise in javascript at Codewars

Two Joggers.

Bob and Charles are meeting for their weekly jogging tour. They both start at the same spot called “Start” and they each run a different lap, which may (or may not) vary in length. Since they know each other for a long time already, they both run at the exact same speed.

Your job is to complete the function nbrOfLaps(x, y) that, given the length of the laps for Bob and Charles, finds the number of laps that each jogger has to complete before they meet each other again, at the same time, at the start.

nbrOfLaps(5, 3); // returns [3, 5]
nbrOfLaps(4, 6); // returns [3, 2]

The solution is:
with input x,y you should return y/gcd(x,y), x/gcd(x,y)
gcd: greatest common divisor

One programmer implemented this brute force version.

```var nbrOfLaps = function (x, y) {
var i = 1;
while('the sun hangs in the sky and the desert has sand') {
try {
if((x*i) % (y) == 0) { return [i, ((x*i)/y)]; }
i++;
} catch(fish) {}
}
return [0, 0];
}
```