-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathLoveCalculator.cs
71 lines (61 loc) · 2.15 KB
/
LoveCalculator.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Linq;
class LoveCalculator{
static void Main(string[] args){
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("<-----------Love Calculator----------->");
Console.WriteLine("Created by Morasiu (morasiu2@gmail.com)");
Calculate();
Console.ReadKey();
}
static void Calculate(){
//Step 1. Take the letters of the word LOVES, and then find out how many of each letter are in both of the names.
//Step 2. place each of these numbers beside the other.
//Step 3. start adding each pair of numbers together, to generate the next number, you will continue to do this until there are only two numbers left.
//For example. If the names where Duchess and Latro you would find, L=1 O=1 V=0 E=1 S=2. 11012 -> (1+1,1+0,0+1,1+2) -> 2113 -> 324 -> 56
List<int> count = new List<int>(); //Always 5 on start because of five letter in "loves"
//First name
Console.Write("First name: ");
string firstName = Console.ReadLine().ToLower();
//Second name
Console.Write("Second name: ");
string secondName = Console.ReadLine().ToLower();
count = Enumerable.Zip(CountLetters(firstName), CountLetters(secondName), (a, b) => a + b).ToList();
string sum = "";
foreach(int i in count){
sum += i.ToString();
}
Console.WriteLine("Love percent: " + SumNumbers(sum) + " ♥");
}
static string SumNumbers(string num){
//Recursive time!
string sum = num;
string tmpSum = "";
if(num.Length == 2)
return num;
else {
for(int i = 0; i < sum.Length - 1; i++){
int iSum = (int)(sum[i] - '0') + (int)(sum[i+1] - '0');
if (iSum > 10){
iSum = (int)(iSum.ToString()[0] - '0') + (int)(iSum.ToString()[1] - '0');
}
tmpSum += iSum.ToString();
}
return SumNumbers(tmpSum);
}
}
static int[] CountLetters(string name){
int[] count = new int[5];
string loves = "loves";
foreach(char l in name){
for(int i = 0; i < loves.Length; i++){
if(l == loves[i]){
count[i]++;
break;
}
}
}
return count;
}
}