CHECKSUM

From Pickwiki
Jump to navigationJump to search

Java implementation of the UniBasic CHECKSUM function:

static long checksum( String input )
{
      char[] chars = new char[ input.length() ];
      input.getChars(0, chars.length, chars, 0);
     
      long answer = 0L;
      for (int i = 0; i< chars.length ; i++) {
         answer += ((int)chars[i]) * (i+1);
      }
      
      return answer;
}