Created
March 10, 2025 15:45
-
-
Save stackdump/93e4c42ce88a4f718918376410612e70 to your computer and use it in GitHub Desktop.
Use trailing digits as a checksum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func checksum3Digit(s string) int { | |
sum := 0 | |
for _, c := range s { | |
sum += int(c) // Convert character to ASCII and sum it | |
} | |
return sum % 1000 // Ensure it's a 3-digit number | |
} | |
func ExampleChecksum3Digits() { | |
input := "stackdump" | |
checksum := checksum3Digit(input) | |
fmt.Printf("%s%03d\n", input, checksum) // Prints checksum with leading zeros if needed | |
// Output: | |
// stackdump972 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For use w/ pre-release user realms allowing users's to register w/ 3 digit trailing number.
Individual users could adopt this scheme to claim idempotent names despite not getting a vanity name
gnolang/gno#2827