|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | + |
| 5 | +class LoveCalculator{ |
| 6 | + static void Main(string[] args){ |
| 7 | + Console.ForegroundColor = ConsoleColor.Green; |
| 8 | + Console.WriteLine("<-----------Love Calculator----------->"); |
| 9 | + Console.WriteLine("Created by Morasiu (morasiu2@gmail.com)"); |
| 10 | + |
| 11 | + Calculate(); |
| 12 | + |
| 13 | + Console.ReadKey(); |
| 14 | + } |
| 15 | + |
| 16 | + static void Calculate(){ |
| 17 | + //Step 1. Take the letters of the word LOVES, and then find out how many of each letter are in both of the names. |
| 18 | + //Step 2. place each of these numbers beside the other. |
| 19 | + //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. |
| 20 | + //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 |
| 21 | + |
| 22 | + List<int> count = new List<int>(); //Always 5 on start because of five letter in "loves" |
| 23 | + //First name |
| 24 | + Console.Write("First name: "); |
| 25 | + string firstName = Console.ReadLine().ToLower(); |
| 26 | + //Second name |
| 27 | + Console.Write("Second name: "); |
| 28 | + string secondName = Console.ReadLine().ToLower(); |
| 29 | + |
| 30 | + count = Enumerable.Zip(CountLetters(firstName), CountLetters(secondName), (a, b) => a + b).ToList(); |
| 31 | + string sum = ""; |
| 32 | + |
| 33 | + foreach(int i in count){ |
| 34 | + sum += i.ToString(); |
| 35 | + } |
| 36 | + Console.WriteLine("Love percent: " + SumNumbers(sum) + " ♥"); |
| 37 | + } |
| 38 | + |
| 39 | + static string SumNumbers(string num){ |
| 40 | + //Recursive time! |
| 41 | + string sum = num; |
| 42 | + string tmpSum = ""; |
| 43 | + if(num.Length == 2) |
| 44 | + return num; |
| 45 | + else { |
| 46 | + for(int i = 0; i < sum.Length - 1; i++){ |
| 47 | + int iSum = (int)(sum[i] - '0') + (int)(sum[i+1] - '0'); |
| 48 | + if (iSum > 10){ |
| 49 | + iSum = (int)(iSum.ToString()[0] - '0') + (int)(iSum.ToString()[1] - '0'); |
| 50 | + } |
| 51 | + tmpSum += iSum.ToString(); |
| 52 | + } |
| 53 | + return SumNumbers(tmpSum); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + |
| 58 | + static int[] CountLetters(string name){ |
| 59 | + int[] count = new int[5]; |
| 60 | + string loves = "loves"; |
| 61 | + foreach(char l in name){ |
| 62 | + for(int i = 0; i < loves.Length; i++){ |
| 63 | + if(l == loves[i]){ |
| 64 | + count[i]++; |
| 65 | + break; |
| 66 | + } |
| 67 | + } |
| 68 | + } |
| 69 | + return count; |
| 70 | + } |
| 71 | +} |
0 commit comments