My version, in C# 😄
public static string GetMatchingWordFor(int number) { var nValues = GetDictionaryFromRawString(RawValues); while (!nValues.ContainsKey(number)) { number -= number.ToString() .Select(digit => int.Parse(digit.ToString())) .Aggregate(0, (acc, x) => acc + x); } return nValues[number]; }
The helper function to convert the raw list into a usable dictionary:
public static Dictionary<int, string> GetDictionaryFromRawString(string raw) { return raw.Split("\n") .Select(str => str.Trim() .Split("-")) .ToDictionary( row => int.Parse(row[0]), row => row[1]); }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
My version, in C# 😄
The helper function to convert the raw list into a usable dictionary: