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
|
1275 Discussions
|
Please Login in order to post a comment
Here is Cats and a Mouse solution in Python, Java, C++, C and Javascript - https://programmingoneonone.com/hackerrank-cats-and-a-mouse-problem-solution.html
solution in GO
func abs(n int32) int32 { if n < 0 { return -n } return n }
// Complete the catAndMouse function below. func catAndMouse(x int32, y int32, z int32) string { a := abs(z - x) b := abs(z - y)
}
solution in GO func abs(n int32) int32 { if n < 0 { return -n } return n }
// Complete the catAndMouse function below. func catAndMouse(x int32, y int32, z int32) string { a := abs(z - x) b := abs(z - y)
}
def catAndMouse(x, y, z): if abs(x-z) == abs(y-z): return 'Mouse C' elif abs(x-z) > abs(y-z): return 'Cat B' elif abs(x-z) < abs(y-z): return 'Cat A'
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 }