Related
I'm looking for the algorithm to convert a lotto ticket number to an integer value an back again.
Let's say the lotto number can be between 1 and 45 and a tickets contains 6 unique numbers. This means there are a maximum of 8145060 unique lotto tickets.
eg:
01-02-03-04-05-06 = 1
01-02-03-04-05-07 = 2
.
.
.
39-41-42-43-44-45 = 8145059
40-41-42-43-44-45 = 8145060
I'd like to have a function (C# preferable but any language will do) which converts between a lotto ticket and an integer and back again. At the moment I use the quick and dirty method of pre-calculating everything, which needs a lot of memory.
For enumerating integer combinations, you need to use the combinatorial number system. Here's a basic implementation in C#:
using System;
using System.Numerics;
using System.Collections.Generic;
public class CombinatorialNumberSystem
{
// Helper functions for calculating values of (n choose k).
// These are not optimally coded!
// ----------------------------------------------------------------------
protected static BigInteger factorial(int n) {
BigInteger f = 1;
while (n > 1) f *= n--;
return f;
}
protected static int binomial(int n, int k) {
if (k > n) return 0;
return (int)(factorial(n) / (factorial(k) * factorial(n-k)));
}
// In the combinatorial number system, a combination {c_1, c_2, ..., c_k}
// corresponds to the integer value obtained by adding (c_1 choose 1) +
// (c_2 choose 2) + ... + (c_k choose k)
// NOTE: combination values are assumed to start from zero, so
// a combination like {1, 2, 3, 4, 5} will give a non-zero result
// ----------------------------------------------------------------------
public static int combination_2_index(int[] combo) {
int ix = 0, i = 1;
Array.Sort(combo);
foreach (int c in combo) {
if (c > 0) ix += binomial(c, i);
i++;
}
return ix;
}
// The reverse of this process is a bit fiddly. See Wikipedia for an
// explanation: https://en.wikipedia.org/wiki/Combinatorial_number_system
// ----------------------------------------------------------------------
public static int[] index_2_combination(int ix, int k) {
List<int> combo_list = new List<int>();
while (k >= 1) {
int n = k - 1;
if (ix == 0) {
combo_list.Add(n);
k--;
continue;
}
int b = 0;
while (true) {
// (Using a linear search here, but a binary search with
// precomputed binomial values would be faster)
int b0 = b;
b = binomial(n, k);
if (b > ix || ix == 0) {
ix -= b0;
combo_list.Add(n-1);
break;
}
n++;
}
k--;
}
int[] combo = combo_list.ToArray();
Array.Sort(combo);
return combo;
}
}
The calculations are simpler if you work with combinations of integers that start from zero, so for example:
00-01-02-03-04-05 = 0
00-01-02-03-04-06 = 1
.
.
.
38-40-41-42-43-44 = 8145058
39-40-41-42-43-44 = 8145059
You can play around with this code at ideone if you like.
there seem to be actually 45^6 distinct numbers, a simple way is to treat the ticket number as a base-45 number and convert it to base 10:
static ulong toDec(string input){
ulong output = 0;
var lst = input.Split('-').ToList();
for (int ix =0; ix< lst.Count; ix++)
{
output = output + ( (ulong.Parse(lst[ix])-1) *(ulong) Math.Pow(45 , 5-ix));
}
return output;
}
examples:
01-01-01-01-01-01 => 0
01-01-01-01-01-02 => 1
01-01-01-01-02-01 => 45
45-45-45-45-45-45 => 8303765624
I want to generate a sequence of strings between two groups that can be either 1 letter [A] -> [F] , 2 letters such as [AA] -> [CD] or any other length like 3 or 4 letters using c#.
For example I can specify the start and end values, and it will generate the sequence.
From [AA] to [CD] should generate
AA
AB
AC
AD
BA
BB
BC
BD
CA
CB
CC
CD
I tried to utilize base-26 algorithm to generate the required sequence but failed to get the required output.
string from ="AA";
string to = "CD";
IEnumerable<string> mysequence = Enumerable.Range(ConvertNumber(from), ConvertNumber(to) - ConvertNumber(from)).Select(ConvertAlpha).ToList();
public static string ConvertAlpha(int value)
{
const int a = (int)'A';
value = value - 1;
var returnValue = new StringBuilder();
while (value > -1)
{
var remainder = value % 26;
returnValue.Insert(0, (char)(a + remainder));
value = value / 26 - 1;
}
return returnValue.ToString();
}
public static int ConvertNumber(string value)
{
const int a = (int)'A' - 1;
int returnValue = 0;
foreach (var character in value.ToUpper())
{
returnValue *= 26;
returnValue += (int)character - a;
}
return returnValue;
}
Using recursion (but with brute-force rather than elegance):
static void Main(string[] args)
{
string fromStr = "AAA";
string toStr = "CDE";
List<string> outputList = new List<string>();
BuildSequence(fromStr, toStr, outputList);
outputList.ForEach(s => { Console.WriteLine(s); });
Console.ReadLine();
}
private static void BuildSequence(
string fromStr,
string toStr,
List<string> outputList,
int index = 0,
string prev = "")
{
IEnumerable<string> newStrList = Enumerable
.Range(fromStr[index], toStr[index] - fromStr[index] + 1)
.Select(c => String.Concat(prev, (char)c));
index += 1;
if (index < fromStr.Length)
{
foreach (string newStr in newStrList)
{
BuildSequence(fromStr, toStr, outputList, index, newStr);
}
}
else
{
outputList.AddRange(newStrList);
}
}
The problem you describe is harder than just converting a base-26 representation to an integer, doing some calculation, and then converting back. Your alpha strings aren't necessarily base-26. For example, you say that given AA and CD, you want to generate
AA, AB, AC, AD
BA, BB, BC, BD
CA, CB, CC, CD
What you really have is a base-4 system that uses the characters A, B, C, and D to represent the numbers 0, 1, 2, and 3. What you're saying here is that you want to generate all the 2-digit, base-4 numbers from 00 through 33.
Given CCC => DMK, it's a base-11 system using digits C through M. It's unclear from your description whether you want:
CCC, CCD, CCE ... CCK
CDC, CDD, CDE ... CDK
...
Or if you want
CCC, CCD, CCE ... CCM
CDC, CDD, CDE ... CDM
...
If you want the former, then each digit position is a different base, and things get even more complicated.
How you define things changes how you would write the code to generate the values.
Regardless or how you want to interpret your alpha values, it's clear that your base-26 conversion functions are incorrect.
Your conversion from int to string has a few errors. In particular, subtracting 1 from the value is going to give you trouble. You can see that if you were to pass 0 to the function. The result would be an empty string.
Here's a correct function:
static string ConvertToBase26(int value)
{
const int a = (int)'A';
var result = new StringBuilder();
do
{
var remainder = value % 26;
value /= 26;
result.Insert(0, (char)(a + remainder);
} while (value > 0);
return result.ToString();
}
Your conversion from base26 to integer has similar errors, due to subtracting 1 from things. Remember, A acts like 0. The corrected function:
static int ConvertFromBase26(string value)
{
const int a = (int)'A';
int result = 0;
foreach (var c in value.ToUpper())
{
result = (result * 26) + (c - a);
}
return result;
}
I recommend renaming your base conversion functions. Your ConvertAlpha function converts an integer to a base-26 string. That's not at all clear in the name, as one could misconstrue "ConvertAlpha" to mean "ConvertFromAlpha". I would recommend ConvertToBase26 and ConvertFromBase26, which are much more explicit and unambiguous.
I have a situation where I need to evenly distribute N items across M slots. Each item has its own distribution %. For discussion purposes say there are three items (a,b,c) with respective percentages of (50,25,25) to be distributed evenly across 20 slots. Hence 10 X a,5 X b & 5 X c need to be distributed. The outcome would be as follows:
1. a
2. a
3. c
4. b
5. a
6. a
7. c
8. b
9. a
10. a
11. c
12. b
13. a
14. a
15. c
16. b
17. a
18. a
19. c
20. b
The part that I am struggling with is that the number of slots, number of items and percentages can all vary, of course the percentage would always total up to 100%. The code that I wrote resulted in following output, which is always back weighted in favour of item with highest percentage. Any ideas would be great.
1. a
2. b
3. c
4. a
5. b
6. c
7. a
8. b
9. c
10. a
11. c
12. b
13. a
14. b
15. c
16. a
17. a
18. a
19. a
20. a
Edit
This is what my code currently looks like. Results in back weighted distribution as I mentioned earlier. For a little context, I am trying to evenly assign commercials across programs. Hence every run with same inputs has to result in exactly the same output. This is what rules out the use of random numbers.
foreach (ListRecord spl in lstRecords){
string key = spl.AdvertiserName + spl.ContractNumber + spl.AgencyAssignmentCode;
if (!dictCodesheets.ContainsKey(key)){
int maxAssignmentForCurrentContract = weeklyList.Count(c => (c.AdvertiserName == spl.AdvertiserName) && (c.AgencyAssignmentCode == spl.AgencyAssignmentCode)
&& (c.ContractNumber == spl.ContractNumber) && (c.WeekOf == spl.WeekOf));
int tmpAssignmentCount = 0;
for (int i = 0; i < tmpLstGridData.Count; i++)
{
GridData gData = tmpLstGridData[i];
RotationCalculation commIDRotationCalc = new RotationCalculation();
commIDRotationCalc.commercialID = gData.commercialID;
commIDRotationCalc.maxAllowed = (int)Math.Round(((double)(maxAssignmentForCurrentContract * gData.rotationPercentage) / 100), MidpointRounding.AwayFromZero);
tmpAssignmentCount += commIDRotationCalc.maxAllowed;
if (tmpAssignmentCount > maxAssignmentForCurrentContract)
{
commIDRotationCalc.maxAllowed -= 1;
}
if (i == 0)
{
commIDRotationCalc.maxAllowed -= 1;
gridData = gData;
}
commIDRotationCalc.frequency = (int)Math.Round((double)(100/gData.rotationPercentage));
if (i == 1)
{
commIDRotationCalc.isNextToBeAssigned = true;
}
lstCommIDRotCalc.Add(commIDRotationCalc);
}
dictCodesheets.Add(key, lstCommIDRotCalc);
}else{
List<RotationCalculation> lstRotCalc = dictCodesheets[key];
for (int i = 0; i < lstRotCalc.Count; i++)
{
if (lstRotCalc[i].isNextToBeAssigned)
{
gridData = tmpLstGridData.Where(c => c.commercialID == lstRotCalc[i].commercialID).FirstOrDefault();
lstRotCalc[i].maxAllowed -= 1;
if (lstRotCalc.Count != 1)
{
if (i == lstRotCalc.Count - 1 && lstRotCalc[0].maxAllowed > 0)
{
//Debug.Print("In IF");
lstRotCalc[0].isNextToBeAssigned = true;
lstRotCalc[i].isNextToBeAssigned = false;
if (lstRotCalc[i].maxAllowed == 0)
{
lstRotCalc.RemoveAt(i);
}
break;
}
else
{
if (lstRotCalc[i + 1].maxAllowed > 0)
{
//Debug.Print("In ELSE");
lstRotCalc[i + 1].isNextToBeAssigned = true;
lstRotCalc[i].isNextToBeAssigned = false;
if (lstRotCalc[i].maxAllowed == 0)
{
lstRotCalc.RemoveAt(i);
}
break;
}
}
}
}
}
}
}
Edit 2
Trying to clear up my requirement here. Currently, because item 'a' is to be assigned 10 times which is the highest among all three items, towards the end of distribution, items 16 - 20 all have been assigned only 'a'. As has been asked in comments, I am trying to achieve a distribution that "looks" more even.
One way to look at this problem is as a multi-dimensional line drawing problem. So I used Bresenham's line algorithm to create the distribution:
public static IEnumerable<T> GetDistribution<T>( IEnumerable<Tuple<T, int>> itemCounts )
{
var groupCounts = itemCounts.GroupBy( pair => pair.Item1 )
.Select( g => new { Item = g.Key, Count = g.Sum( pair => pair.Item2 ) } )
.OrderByDescending( g => g.Count )
.ToList();
int maxCount = groupCounts[0].Count;
var errorValues = new int[groupCounts.Count];
for( int i = 1; i < errorValues.Length; ++i )
{
var item = groupCounts[i];
errorValues[i] = 2 * groupCounts[i].Count - maxCount;
}
for( int i = 0; i < maxCount; ++i )
{
yield return groupCounts[0].Item;
for( int j = 1; j < errorValues.Length; ++j )
{
if( errorValues[j] > 0 )
{
yield return groupCounts[j].Item;
errorValues[j] -= 2 * maxCount;
}
errorValues[j] += 2 * groupCounts[j].Count;
}
}
}
The input is the actual number of each item you want. This has a couple advantages. First it can use integer arithmetic, which avoids any rounding issues. Also it gets rid of any ambiguity if you ask for 10 items and want 3 items evenly distributed (which is basically just the rounding issue again).
Here's one with no random number that gives the required output.
using System;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
// name, percentage
Dictionary<string, double> distribution = new Dictionary<string,double>();
// name, amount if one more were to be distributed
Dictionary<string, int> dishedOut = new Dictionary<string, int>();
//Initialize
int numToGive = 20;
distribution.Add("a", 0.50);
distribution.Add("b", 0.25);
distribution.Add("c", 0.25);
foreach (string name in distribution.Keys)
dishedOut.Add(name, 1);
for (int i = 0; i < numToGive; i++)
{
//find the type with the lowest weighted distribution
string nextUp = null;
double lowestRatio = double.MaxValue;
foreach (string name in distribution.Keys)
if (dishedOut[name] / distribution[name] < lowestRatio)
{
lowestRatio = dishedOut[name] / distribution[name];
nextUp = name;
}
//distribute it
dishedOut[nextUp] += 1;
Console.WriteLine(nextUp);
}
Console.ReadLine();
}
}
Instead of a truly random number generator, use a fixed seed, so that the program has the same output every time you run it (for the same input). In the code below, the '0' is the seed, which means the 'random' numbers generated will always be the same each time the program is run.
Random r = new Random(0);
//AABC AABC…
int totalA = 10
int totalB = 5
int totalC = 5
int totalItems = 20 //A+B+C
double frequencyA = totalA / totalItems; //0.5
double frequencyB = totalB / totalItems; //0.25
double frequencyC = totalC / totalItems; //0.25
double filledA = frequencyA;
double filledB = frequencyB;
double filledC = frequencyC;
string output = String.Empty;
while(output.Length < totalItems)
{
filledA += frequencyA;
filledB += frequencyB;
filledC += frequencyC;
if(filledA >= 1)
{
filledA -= 1;
output += "A";
if(output.Length == totalItems){break;}
}
if(filledB >= 1)
{
filledB -= 1
output += "B";
if(output.Length == totalItems){break;}
}
if(filledC >= 1)
{
filledC -= 1
output += "C";
if(output.Length == totalItems){break;}
}
}
This answer was mostly stolen and lightly adapted for your use from here
My idea is that you distribute your items in the simplest way possible without care of order, then shuffle the list.
public static void ShuffleTheSameWay<T>(this IList<T> list)
{
Random rng = new Random(0);
int n = list.Count;
while (n > 1) {
n--;
int k = rng.Next(n + 1);
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
Fiddle here
I have below triangle of numbers which will be sent as parameter to a function
5
9 6
4 6 8
0 7 1 5
Now this will be received as string in below function with the format 5#9#6#4#6#8#0#7#1#5. So far I've tried to ripple only the digits from #
public class Sample
{
public static string validtrianglesum(string input)
{
string sum="0";
foreach(char num in input)
{
if(!num.Equals('#'))
{
Console.PrintLine(num); //here am getting only the nums excluding #
//How to sum up based on each row
}
}
return sum; //return
}
}
how could highest number from each row and sum them and how could I identify the rows to sum it up? Hope to find some help.
Let's break this down as follows:
Firstly, turn the input into an array of numbers:
string input = "5#9#6#4#6#8#0#7#1#5";
var numbers = input.Split('#').Select(int.Parse).ToArray();
Now let's assume we have a MakeTriangular(int[]) method that turns an array of numbers into a sequence of rows with the first row being of length 1, the second of length 2 and so on, so that it returns IEnumerable<IEnumerable<int>>.
Then we can use that along with Linq to calculate the sum of the maximum value in each row as follows:
int sum = MakeTriangular(numbers).Sum(row => row.Max());
Which gives the answer.
The implementation of MakeTriangular() could look like this:
public static IEnumerable<IEnumerable<int>> MakeTriangular(int[] numbers)
{
for (int i = 0, len = 1; i < numbers.Length; i += len, ++len)
yield return new ArraySegment<int>(numbers, i, len);
}
Putting it all together into a compilable Console app:
using System;
using System.Collections.Generic;
using System.Linq;
namespace Demo
{
class Program
{
public static void Main()
{
string input = "5#9#6#4#6#8#0#7#1#5";
var numbers = input.Split('#').Select(int.Parse).ToArray();
int sum = MakeTriangular(numbers).Sum(row => row.Max());
Console.WriteLine(sum);
}
public static IEnumerable<IEnumerable<int>> MakeTriangular(int[] numbers)
{
for (int i = 0, len = 1; i < numbers.Length; i += len, ++len)
yield return new ArraySegment<int>(numbers, i, len);
}
}
}
Summing up all values in each row:
private static IEnumerable<int> Sum(string input)
{
int i = 0, s = 0, z = 1;
foreach (var v in input.Split('#').Select(int.Parse))
{
s += v;
if (++i != z) continue;
z++;
yield return s;
s = i = 0;
}
}
The same in one line:
private static IEnumerable<int> Sum(string input) => new Func<int, int, IEnumerable<int>>((i, z) => input.Split('#').Select(int.Parse).GroupBy(e => i++ == z && (i = 1) != null ? ++z : z, e => e).Select(e => e.Sum()))(0, 1);
Summing up all the highest values in each row:
private static int Sum(string input)
{
int i = 0, s = 0, z = 1, m = 0;
foreach (var v in input.Split('#').Select(int.Parse))
{
if (v > m) m = v;
if (++i != z) continue;
z++;
s += m;
i = m = 0;
}
return s;
}
Same in one line:
private static int Sum(string input) => new Func<int, int, int>((i, z) => input.Split('#').Select(int.Parse).GroupBy(e => i++ == z && (i = 1) != null ? ++z : z, e => e).Select(e => e.Max()).Sum())(0, 1);
I am returning the sums as IEnumerable<int> and with the yield return. If you just want to print out the answers change the return type to void and remove the yield return s; line.
One way to solve this is to determine the size of the triangle. By size I mean the height/width. E.g, the provided triangle has a size of 4.
If the size is n then the number of elements in the triangle will be n(n + 1)/2. When the number of elements in the input is known this can be solved to determine n (the size) by solving a second degree polynomial and picking the positive solution (the expression below involving a square root):
var triangle = "5#9#6#4#6#8#0#7#1#5";
var values = triangle.Split('#').Select(Int32.Parse).ToList();
var sizeAsDouble = (-1 + Math.Sqrt(1 + 8*values.Count))/2;
var size = (Int32) sizeAsDouble;
if (sizeAsDouble != size)
throw new ArgumentException("Input data is not a triangle.");
So with the provided input size will be 4. You can then use the size to select each row in the triangle and perform the desired arithmetic:
var maxValues = Enumerable
.Range(0, size)
.Select(i => new { Start = i*(i + 1)/2, Count = i + 1 })
.Select(x => values.Skip(x.Start).Take(x.Count))
.Select(v => v.Max());
The first Select will compute the necessary indices to correctly slice the array of values which is done in the second Select. Again the formula n(n + 1)/2 is used. If you want to you can merge some of these Select operations but I think spliting them up makes it clearer what is going on.
The output of this will be the numbers 5, 9, 8, 7. If you want to sum these you can do it like this:
return maxValues.Sum();
You can use LINQ:
string input = "5#9#6#4#6#8#0#7#1#5";
var nums = input.Split('#').Select(s => Int32.Parse(s));
var res = Enumerable.Range(0, nums.Count())
.Select(n => nums.Skip(Enumerable.Range(0, n).Sum()).Take(n));
.Where(x => x.Any()); // here you have IEnumerable<int> for every row
.Select(arr => arr.Max());
Please give credit to Widi :) but this is your request
var rows = Sum("5#9#6#4#6#8#0#7#1#5");
var total = rows.Sum();
private static IEnumerable<int> Sum(string inp)
{
int i = 0, s = 0, z = 1;
foreach (var v in inp.Split('#').Select(int.Parse))
{
s = Math.Max(s, v);
if (++i == z)
{
z++;
yield return s;
s = i = 0;
}
}
}
I would use 2 functions:
1st one to convert the string into a tree representation:
List<List<int>> GetTree(string data)
{
List<List<int>> CompleteTree = new List<List<int>>();
List<int> ValuesInLine = new List<int>();
int partsinrow = 1;
int counter = 0;
foreach (string part in data.Split('#'))
{
int value = int.Parse(part);
ValuesInLine.Add(value);
if (++counter == partsinrow)
{
CompleteTree.Add(ValuesInLine);
ValuesInLine = new List<int>();
counter = 0;
partsinrow++;
}
}
return CompleteTree;
}
2nd one to sum up the maximum of the lines:
int GetSumOfTree(List<List<int>> tree)
{
int sum = 0;
foreach (List<int> line in tree)
{
line.Sort();
int max = line[line.Count - 1];
sum += max;
}
return sum;
}
I am trying to solve one of the Euler Project problems using c# (problem 22). Though I have run into a problem. It's probably worth noting I am relatively new to programming, especially c#.
I need to come up with a word score for a set of strings that I have. This involves summing up the score of each letter in a a word, e.g. a=1, b=2, c=3 and so on. To do this I have assigned all 26 letters of the alphabet as variables with the relevant scores. I then want to compare each letter in the word with the relevant variables of the same name. However what I am left with is a char data type, what's the best way for me to compare the character to the relevant variable, and then use the variable value in my integer calculation. I have included the code I have so far below, with the problem occuring in the last 2 lines excluding braces. (I have had a quick look, and it appears this is not supported in c++, though i'm not sure about c#). Any help would be greatly appreciated.
string[] lines = File.ReadAllLines(#"C:\Users\john\Downloads\names.txt");
//Console.WriteLine(lines[1]);
char[] delimiterChars = { ',', '\t' };
string text = lines[0];
string[] names = text.Split(delimiterChars);
Console.WriteLine("{0} words in text:", names.Length);
Array.Sort(names);
int a = 1;
int b = 2;
int c = 3;
int d = 4;
int e = 5;
int f = 6;
int g = 7;
int h = 8;
int i = 9;
int j = 10;
int k = 11;
int l = 12;
int m = 13;
int n = 14;
int o = 15;
int p = 16;
int q = 17;
int r = 18;
int s = 19;
int t = 20;
int u = 21;
int v = 22;
int w = 23;
int x = 24;
int y = 25;
int z = 26;
int[] nameTotal;
for (int count = 0; count < names.Length; count++)
{
string name = names[count];
int total = 0;
for (int count2 = 0; count2 < name.Length; count2++)
{
nameTotal[count] = name.Substring(count2) + total;
total = total + nameTotal[count];
}
}
You can do this by taking advantage of the layout of the standard ASCII table.
In ASCII, the 'a' character has a decimal value of 97. Lower-case letters then continue up until 122.
Therefore, you can easily convert an 'a' char value to your required value by using:
char charToConvert = 'a';
int requiredValue = (int)charToConvert - 96;
If you want to calculate the sum of the letters in a name, you can also use Linq (just an example):
string name = "ABCD";
int sum = name.Select(letter => letter - 'A' + 1).Sum();
You can perform calculations with letters just like with integers in C#.
The Select method (which is an extension method from Linq) projects each letter of the string to it's corresponding value. These values are then summed by the extension method Sum().
Edit: As jlafay pointed out, you can omit the Select call and put the projection into the Sum method:
name.Sum(letter => letter - 'A' + 1)
And regarding your original question: You can't access the name of a local variable, even with reflection. That information is not included in the metadata of the compiled code.
Instead of assigning 26 variables for each letter, create an IDictionary<TKey, TValue> where the TKey is the character and the TValue is whatever value you assign. Then you can access the value by passing in the character much more easily.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SO
{
static class Program
{
static void Main()
{
WebClient wc = new WebClient();
var text = wc.DownloadString("http://projecteuler.net/project/names.txt");
var names = Regex.Matches(text, "[A-Z]+").Cast<Match>()
.Select(x => x.Value)
.OrderBy(x => x)
.Select((name, inx) => new
{
Name = name,
Score = name.Sum(c => c - 'A' + 1) * (inx + 1)
});
foreach (var n in names)
{
Console.WriteLine("{0}: {1}", n.Name, n.Score);
}
}
}
}