Created
March 15, 2017 23:46
-
-
Save csuzw/ea65e2aba72bf8fadb6253d1f112515d to your computer and use it in GitHub Desktop.
Gets number of key presses required to input message on old phone keypad
This file contains hidden or 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
int GetKeyPresses(string message) | |
{ | |
return (int)message.Select(c => c < 83 ? ((c - 29) % 3) + 1 : Math.Round(Enumerable.Range(0, 8).Zip(new[] { -400129224492.361d, 32421475419.7348d, -1125710194.76048d, 21711311.9794762d, -251208.877408241d, 1743.70653338347d, -6.72322436313127d, 0.011108192375644d }, (a, b) => b * Math.Pow(c, a)).Sum())).Sum(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment