Sumar and the Floating Rocks

  • + 0 comments

    JS:

    function gcd(a,b) {
     while(b !== 0) {
    	 const r = a % b;
    	 a = b;
    	 b = r;
    	 }
     return a;
    }
    function solve (x1,y1,x2,y2) {
    	const yd = Math.abs(y2-y1);
    	const xd = Math.abs(x2-x1);
    	const a = Math.max(yd, xd);
    	const b = Math.min(yd, xd);
    return gcd(a,b) - 1;
    	}