-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCatsAndAMouse.cs
More file actions
37 lines (36 loc) · 1.22 KB
/
CatsAndAMouse.cs
File metadata and controls
37 lines (36 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProblemSolving_HackerRank_.Easy
{
public class CatsAndAMouse
{
/// <summary>
/// Two cats and a mouse are at various positions on a line
/// <paramref name="x"/>, <paramref name="y"/>, and <paramref name="z"/> respectively.
/// You will be given their starting positions.
/// Your task is to determine which cat will reach the mouse first,
/// assuming the mouse does not move and the cats travel at equal speed.
/// If the cats arrive at the same time, the mouse will be allowed to move
/// and it will escape while they fight.
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="z"></param>
/// <returns>
/// Cat A, If cat A catches the mouse first.
/// Cat B, If cat catches the mouse first.
/// Mouse C, If both cats reach the mouse at the same time, as the two cats fight and mouse escapes.
/// </returns>
public static string catAndMouse(int x, int y, int z)
{
var catA = Math.Abs(x - z);
var catB = Math.Abs(y - z);
if (catA < catB) return "Cat A";
if (catB < catA) return "Cat B";
else return "Mouse C";
}
}
}