fork download
  1. using System;
  2.  
  3. namespace StringDistance
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. Func<string,int>f= s=>{int l=0,d,i=0;for(;i<s.Length-1;)l+=(d=Math.Abs(s[i]-s[++i]))>13?26-d:d;return l;};
  10.  
  11. Console.WriteLine(f("golf")); //17
  12. Console.WriteLine(f("aa")); //0
  13. Console.WriteLine(f("stack")); //18
  14. Console.WriteLine(f("zaza")); //3
  15. Console.WriteLine(f("valleys"));//35
  16. }
  17. }
  18. }
Success #stdin #stdout 0s 29664KB
stdin
Standard input is empty
stdout
17
0
18
3
35