AsciiHash.cs 347 B

123456789101112131415161718
  1. using System.Text;
  2. namespace Day15;
  3. public static class AsciiHash
  4. {
  5. public static byte Hash(string input)
  6. {
  7. byte result = 0;
  8. foreach (var b in Encoding.ASCII.GetBytes(input))
  9. {
  10. result += b;
  11. result = (byte)((result * 17) % 256);
  12. }
  13. return result;
  14. }
  15. }