-
Notifications
You must be signed in to change notification settings - Fork 0
/
Decider.cs
46 lines (32 loc) · 1.3 KB
/
Decider.cs
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
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
namespace Cat_Or_Dog
{
class Decider {
public static string Decide (int score, string seed) {
if (seed == null) {
throw new ArgumentNullException("Seed is null!");
}
var randomNumberSeq = (NumberFromSeed(seed) * score).ToString();
var randomNumber = Int32.Parse(ReverseString(randomNumberSeq.Substring(randomNumberSeq.Length/2-1, randomNumberSeq.Length-1)))*score
*randomNumberSeq.Length*Int32.Parse(ReverseString(randomNumberSeq.Substring(0, randomNumberSeq.Length/2)));
if (((int)randomNumber.ToString()[0]+(int)randomNumber.ToString()[randomNumber.ToString().Length-1]) % 2 == 0) {
return "Cat";
}
return "Dog";
}
public static int NumberFromSeed (string seed) {
var chars = new List<char>(seed);
var total = 0;
foreach (char seedBit in chars) {
total += (int) seedBit;
}
return total;
}
public static string ReverseString(string str) {
char[] array = str.ToCharArray();
Array.Reverse(array);
return new String(array);
}
}
}