public static void Fib(AAItem item) { long a, b = 1, c; a = c = 0; while (c <= item.startingFibonacciNumber) { c = a + b; a = b; b = c; //a es el inicial, b es el siguiente, c es el siguiente } List <char> temp; string num; for (int i = 0; i < item.words.Length; i++) { temp = item.words[i].ToList(); for (int j = 0; j < temp.Count; j++) { if (isVowel(temp[j])) { temp.RemoveAt(j); num = a.ToString(); temp.InsertRange(j, num); c = a + b; a = b; b = c; j += num.Length - 1; } } item.words[i] = new string(temp.ToArray()); } }
public static void AltCase(AAItem item) { bool upper = char.IsUpper(item.words[0][0]); for (int i = 0; i < item.words.Length; i++) { char[] temp = item.words[i].ToCharArray(); for (int j = 0; j < item.words[i].Length; j++) { if (!isVowel(temp[j])) { if (upper) { temp[j] = char.ToUpper(temp[j]); } else { temp[j] = char.ToLower(temp[j]); } upper = !upper; } } item.words[i] = new string(temp); } }
public static string AsterixConcat(AAItem item) { StringBuilder sb = new StringBuilder(); foreach (var word in item.words) { sb.Append(word).Append('*'); } sb.Remove(sb.Length - 1, 1); return(sb.ToString()); }
public static void SortArray(AAItem item, bool desc) { if (desc) { item.words = item.words.OrderByDescending(w => w).ToArray(); } else { item.words = item.words.OrderBy(w => w).ToArray(); } }
public static string AsciiConcat(AAItem item) { StringBuilder sb = new StringBuilder(item.words[0]); sb.Append((int)item.words[item.words.Length - 1][0]); for (int i = 1; i < item.words.Length; i++) { sb.Append(item.words[i]); sb.Append((int)item.words[i - 1][0]); } return(sb.ToString()); }
public static void ShiftVowels(AAItem item) { for (int j = 0; j < item.words.Length; j++) { for (int i = 0; i < item.words[j].Length; i++) { if (isVowel(item.words[j][i])) { item.words[j] = ShiftChar(item.words[j], i); i++; } } } }
public static void crazy(AAItem item) { List <string> ItemsList = item.words.ToList(); List <string> dict = new List <string>(new string[] { "drool", "cats", "clean", "code", "dogs", "materials", "needed", "this", "is", "hard", "what", "are", "you", "smoking", "shot", "gun", "down", "river", "super", "man", "rule", "acklen", "developers", "are", "amazing" }); List <string> rep = new List <string>(); string temp; bool flag; for (int i = 0; i < ItemsList.Count; i++) { flag = true; temp = string.Copy(ItemsList[i]); while (!string.IsNullOrWhiteSpace(temp)) { foreach (var def in dict) { if (temp.ToLower().StartsWith(def)) { flag = false; rep.Add(temp.Substring(0, def.Length)); temp = temp.Remove(0, def.Length); break; } } if (flag) { break; } } if (rep.Count > 0) { ItemsList.RemoveAt(i); ItemsList.InsertRange(i, rep); rep.Clear(); } } item.words = ItemsList.ToArray(); }
static async Task RunAsync() { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://internal-devchallenge-2-dev.apphb.com/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); string guid; for (int i = 0; i < 20; i++) { guid = Guid.NewGuid().ToString(); HttpResponseMessage response = await client.GetAsync("values/" + guid); string result = ""; if (response.IsSuccessStatusCode) { AAItem item = await response.Content.ReadAsAsync <AAItem>(); switch (item.algorithm) { case "IronMan": Algorithms.SortArray(item, false); //check Algorithms.ShiftVowels(item); //check result = Algorithms.AsciiConcat(item); //check result = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(result)); break; case "TheIncredibleHulk": Algorithms.ShiftVowels(item); //check Algorithms.SortArray(item, true); //check result = Algorithms.AsterixConcat(item); //check result = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(result)); break; case "Thor": //1 Algorithms.crazy(item); Algorithms.SortArray(item, false); //check Algorithms.AltCase(item); Algorithms.Fib(item); result = Algorithms.AsterixConcat(item); //check result = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(result)); break; case "CaptainAmerica": Algorithms.ShiftVowels(item); //check Algorithms.SortArray(item, true); //check Algorithms.Fib(item); result = Algorithms.AsciiConcat(item); //check result = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(result)); break; } Calculation postval = new Calculation(); postval.encodedValue = result; response = await client.PostAsJsonAsync(string.Format("values/{0}/{1}", guid, item.algorithm), postval); Console.WriteLine(i); Console.WriteLine(item.algorithm); AAResponse asdf = await response.Content.ReadAsAsync <AAResponse>(); Console.WriteLine(asdf.status); Console.WriteLine(asdf.message); } } } }