Skip to content

Instantly share code, notes, and snippets.

@tenor
Created February 26, 2014 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tenor/9220821 to your computer and use it in GitHub Desktop.
Save tenor/9220821 to your computer and use it in GitHub Desktop.
These programs display a list of the names of single digits
// This program outputs the names of a given list of digits backwards
//
string GetDigitName(int digit)
{
switch(digit)
{
case 0: return "zero";
case 1: return "one";
case 2: return "two";
case 3: return "three";
case 4: return "four";
case 5: return "five";
case 6: return "six";
case 7: return "seven";
case 8: return "eight";
case 9: return "nine";
default:
throw new ArgumentException(digit + "is not a digit.");
}
}
List<int> digits = new List<int>(new int[]{0,1,2,3,4,5,6,7,8,9});
int index;
while(digits.Count > 0)
{
index = digits.Count - 1;
Console.WriteLine(GetDigitName(digits[index]));
digits.RemoveAt(index);
}
// This program outputs the names of a given list of digits in a random order
//
string GetDigitName(int digit)
{
switch(digit)
{
case 0: return "zero";
case 1: return "one";
case 2: return "two";
case 3: return "three";
case 4: return "four";
case 5: return "five";
case 6: return "six";
case 7: return "seven";
case 8: return "eight";
case 9: return "nine";
default:
throw new ArgumentException(digit + "is not a digit.");
}
}
List<int> digits = new List<int>(new int[]{0,1,2,3,4,5,6,7,8,9});
Random rnd = new Random();
int index;
while(digits.Count > 0)
{
index = rnd.Next(digits.Count);
Console.WriteLine(GetDigitName(digits[index]));
digits.RemoveAt(index);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment