Skip to content

Instantly share code, notes, and snippets.

@csuzw
Created March 15, 2017 23:46
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 csuzw/ea65e2aba72bf8fadb6253d1f112515d to your computer and use it in GitHub Desktop.
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
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