Sort by

recency

|

1275 Discussions

|

  • + 0 comments

    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

  • + 0 comments

    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)

    if a < b {
        return "Cat A"
    } else if b < a {
        return "Cat B"
    }
    
    return "Mouse C"
    

    }

  • + 0 comments

    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)

    if a < b {
        return "Cat A"
    } else if b < a {
        return "Cat B"
    }
    
    return "Mouse C"
    

    }

  • + 0 comments

    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'

  • + 0 comments

    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 }