Skip to content

Instantly share code, notes, and snippets.

@kjellski
Created December 5, 2013 08:43
Show Gist options
  • Save kjellski/7802074 to your computer and use it in GitHub Desktop.
Save kjellski/7802074 to your computer and use it in GitHub Desktop.
conversion from string words to int
var s = "six thousand one thousand six hundred ninety two thirty three".Split(' ');
var map = new Dictionary<string, int>();
map.Add("one", 1);
map.Add("two", 2);
map.Add("three", 3);
map.Add("six", 6);
map.Add("thirty", 30);
map.Add("ninety", 90);
map.Add("hundred", 100);
map.Add("thousand", 1000);
var tuples = s.Zip(s.Skip(1), (a, b) => Tuple.Create(a, b)) // create tuple
.Where((x, i) => i % 2 == 0); // just take every second one
var q = tuples.Take(tuples.Count() -1);
var result = 0;
foreach (var p in q)
{
result += map[p.Item1] * map[p.Item2];
}
result += map[tuples.Last().Item1] + map[tuples.Last().Item2];
result.Dump();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment