Created
October 29, 2014 09:16
-
-
Save SoulFireMage/7d9253a0f321d53864ec to your computer and use it in GitHub Desktop.
Coding Interview Exercise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace PlayingAround | |
{ | |
class Program | |
{ | |
/// <summary> | |
/// 15 minute answer to Coding Interview Puzzle 1. Previous solution used a dictionary and extension method. | |
/// This is more old school and faster. | |
/// The question is given a million integers between 1 and 130, count how many of each value there are. | |
/// </summary> | |
private static readonly int MaxAge = 131; | |
private static int[] Numbers = new int[MaxAge]; | |
static void Main(string[] args) | |
{ | |
Random random = new Random(130); | |
for (int i = 1; i < 1000000 - 1; i++) Numbers[random.Next(1,MaxAge )] += 1; | |
for (int i = 1;i <= Numbers.Length - 1; i++) Console.WriteLine("{0}: {1}", i, Numbers[i]); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment