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 int[] dist = {0,0}; dist[0] = Math.Abs(z-x); dist[1] = Math.Abs(z-y); return (dist[0] == dist[1]) ? "Mouse C" : (dist[0] < dist[1]) ? "Cat A" : "Cat B";
+ 0 comments if(abs(x-z)< abs(y-z)) return "Cat A"; else if(abs(x-z)> abs(y-z)) return "Cat B"; else return "Mouse C";
+ 0 comments JavaScript
let a = Math.abs(x-z); let b = Math.abs(y-z); if (a == b){ return "Mouse C" } else if (a<=b){ return "Cat A" } else if (a>=b){ return "Cat B" }
+ 0 comments My Java 8 solution, feel free to ask me any questions.
static String catAndMouse(int x, int y, int z) { int catADistance = Math.abs(x - z); int catBDistance = Math.abs(y - z); if(catADistance == catBDistance) { return "Mouse C"; } if(catADistance > catBDistance) { return "Cat B"; } return "Cat A"; }
+ 0 comments Python3:
def catAndMouse(x, y, z): catADistance = abs(x - z) catBDistance = abs(y - z) if catADistance == catBDistance: return "Mouse C" return "Cat A" if catADistance < catBDistance else "Cat B"
Load more conversations
Sort 1146 Discussions, By:
Please Login in order to post a comment