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
Sort by
recency
|
1271 Discussions
|
Please Login in order to post a comment
function catAndMouse( catAPosition , catBPosition , mousePostion ) {
const catAStep = Math.abs(mousePostion - catAPosition); const catBStep = Math.abs( mousePostion - catBPosition );
let difference = catAStep - catBStep;
let result = (difference === 0 )? 'Mouse C':(difference > 0)?'Cat B':'Cat A'; return result }
Here is problem solution in Python, Java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-cats-and-a-mouse-problem-solution.html
Here is my c++ solution, you can watch the explanation here : https://youtu.be/vbV5-DqJU74
Short version
I thought using a dictionary of exclusive boolean statements would be fun
`def catAndMouse(x, y, z):