티스토리 뷰

Algorithms

Cats and a Mouse

seoca 2020. 9. 17. 20:14

Solution in Javascript

const x = 1;
const y = 2;
const z = 3;

function catAndMouse(x, y, z) {
    const A = Math.abs(z-x);
    const B = Math.abs(z-y);

    if (A < B){
        console.log('Cat A');
    }else if (A > B){
        console.log('Cat B');
    }else if (A === B){
        console.log('Mouse C');
    }
}

catAndMouse(x, y, z);

 

 

 

 

Reference

www.hackerrank.com/challenges/cats-and-a-mouse/problem

'Algorithms' 카테고리의 다른 글

Electronics Shop  (0) 2020.09.25
The Hurdle Race  (0) 2020.09.25
Find Digits  (0) 2020.09.13
Bon Appétit  (0) 2020.09.12
Birthday Chocolate  (0) 2020.09.11