Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class ImeisvToImei
  5. {
  6. static string Transform(string imeisv)
  7. {
  8. if (imeisv == null)
  9. throw new ArgumentNullException(nameof(imeisv));
  10.  
  11. if (imeisv.Length != 16)
  12. throw new ArgumentOutOfRangeException(nameof(imeisv));
  13.  
  14. var b = imeisv.Substring(0, 14);
  15.  
  16. var sum = b
  17. .Select(ch => ch - '0')
  18. .Select((n, index) => (index % 2 == 0) ? n : n * 2)
  19. .Select(n => n / 10 + n % 10)
  20. .Sum();
  21.  
  22. return $"{b}{10 - sum % 10}";
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement