Created
December 5, 2013 08:43
-
-
Save kjellski/7802074 to your computer and use it in GitHub Desktop.
conversion from string words to int
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
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