We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Cats and a Mouse
Cats and a Mouse
+ 0 comments Python
def catAndMouse(x, y, z): a_dist = abs(x-z) b_dist = abs(y-z) if a_dist == b_dist: return 'Mouse C' elif a_dist > b_dist: return 'Cat B' else: return 'Cat A'
+ 0 comments C#
int CatADistance = x > z ? x - z : z - x; int CatBDistance = y > z ? y - z : z - y; if (CatADistance < CatBDistance) return "Cat A"; else if (CatADistance > CatBDistance) return "Cat B"; else return "Mouse C";
+ 0 comments Easy C# Solution
static string catAndMouse(int x, int y, int z) { int catADistance = 0; int catBDistance = 0; if(x < z) { catADistance = z - x; } if(y < z) { catBDistance = z - y; } if(x > z) { catADistance = x - z; } if(y > z) { catBDistance = y - z; } if(catADistance > catBDistance) { return "Cat B"; } if(catBDistance > catADistance) { return "Cat A"; } else { return "Mouse C"; }
+ 0 comments def catAndMouse(x, y, z): i,j= abs(z-x),abs(z-y) if i==j: return 'Mouse C' if i<j: return 'Cat A' else: return 'Cat B'
+ 0 comments JavaScript solution:
/** * x - cat a * y - cat b * z - mouse */ function catAndMouse(x, y, z) { const catA = Math.abs(x - z); const catB = Math.abs(y - z); console.log(catA, catB); if (catA === catB) { return 'Mouse C'; } else if (catA < catB) { return 'Cat A'; } else if (catA > catB) { return 'Cat B'; } }
Load more conversations
Sort 1055 Discussions, By:
Please Login in order to post a comment