Given the day of the year and the year (both as ints), return the date in “m/d/yyyy” (string) format without using the System.DateTime namespace or any other built-in date/time handler. One solution (1858 IL characters) static string g(int d, int y) { int l; int i = 0; if (d < 0) { i = 13; } l = ((y % 400 == 0) | ((y % 100 != 0) & (y % 4 == 0))) ? 1 : 0; int[] m = new int[13] { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; while (i < 13) { if (i > 1) { m[i] = m[i] + l;...
Given a color string in one of the formats listed below, return an array of the RGB elements that make it up. For Example: "RGB(255,255,255)" "#FFFFFF" "#FFF" All of these examples return [255, 255, 255] - Case does not matter - #abc translates to #aabbcc - There will be no spaces in the string One solution (73 IL): s = s.Replace("RGB(", "").Replace(")", "").Replace("#", ""); if (s.Contains(",")) { return s.Split(','); } int[] a = new int[3]; int i = 0; do { a[i] = (s.Length == 3 ? 17 : 1) * Convert.ToInt32(s.Substring(i...
Implement 2 algorithms and place them in separate methods. 1) Given a sentence, write an algorithm to reverse the order of the words. Example: “My name is Chris” becomes “Chris name is My”. 2) Given the same sentence as in #1, write an algorithm to reverse each individual word, but not their order. Example: “My name is Chris” becomes “yM eman si sirhC”. Winner: public static string W(string s){ char[] c = s.ToCharArray(); Array.Reverse(c); return O(new string(c)); } public static string O(string...
Given an arbitrary number of coins to use, print out a combination using that number that will add up to a dollar. For instance, using the number 4: Q : 4 D : 0 N : 0 P : 0 If the number is invalid, such as 5: Invalid Number - The method must take an Integer value with no restrictions. - All data structures must be instantiated within the method. - Only Pennies, Nickels, Dimes, and Quarters can be used. (No Half Dollars) - The lowest IL wins. One solution (103 IL) static void Amount(int total) {...
Write a method that takes two parameters, both positive integers, and returns each prime number that falls on or between these two numbers. Each number printed out should be on its own line, so that if the parameters were 1 and 20, the results would be: 2 3 5 7 11 13 17 19 The method must be able to handle both parameters being the same number. It should also be able to handle the first number passed being bigger or smaller than the second. EVERYTHING must happen within this method. Your Main should...
Given the lengths of the sides of a triangle, compute the area of the triangle. Here's one implementation (based completely off a geometry formula): double printArea(double a, double b, double c) { double s = (a + b + c) / 2; return Math.Sqrt(s * (s - a) * (s - b) * (s - c)); }
Given a sorted list with duplicates, print out a list of just the unique elements. For example: Given (1, 1, 3, 3, 3, 5, 5, 5, 9, 9, 9, 9), the result would be (1, 3, 5, 9). Here's one implementation: int[] nums = new int[] { 1, 1, 1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 5, 5, 6, 9, 9, 9, 9 }; int n = 1; Console.Write(nums[0]); do { Console.Write(nums[n] == nums[++n] ? "" : nums[n].ToString()); } while (n < nums.Length);...