Created
January 23, 2021 20:21
-
-
Save Specnr/a006f838e022ef758dbb6cf5072ba6f0 to your computer and use it in GitHub Desktop.
Finds all capitalization permutations of a given word, and converts them all to Minecraft seeds
This file contains 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
def java_string_hashcode(s): | |
# Convert string to seed | |
# https://gist.github.com/hanleybrand/5224673 | |
h = 0 | |
for c in s: | |
h = (31 * h + ord(c)) & 0xFFFFFFFF | |
return ((h + 0x80000000) & 0xFFFFFFFF) - 0x80000000 | |
def all_casings(input_string): | |
# Recursively returns all capitalizations of a given word | |
# https://stackoverflow.com/questions/6792803/finding-all-possible-case-permutations-in-python | |
if not input_string: | |
yield "" | |
else: | |
first = input_string[:1] | |
if first.lower() == first.upper(): | |
for sub_casing in all_casings(input_string[1:]): | |
yield first + sub_casing | |
else: | |
for sub_casing in all_casings(input_string[1:]): | |
yield first.lower() + sub_casing | |
yield first.upper() + sub_casing | |
def main(string): | |
# Output can be used with https://github.com/Zodsmar/SeedSearcherStandaloneTool | |
# to find good seeds for a given word. | |
seeds = [s for s in all_casings(string)] | |
with open("seeds.txt", "w") as outfile: | |
for seed in seeds: | |
outfile.write(str(java_string_hashcode(seed)) + "\n") | |
with open("wordSeeds.txt", "w") as outfile: | |
for seed in seeds: | |
outfile.write(seed + "\n") | |
if __name__ == "__main__": | |
base = input("Base word for all seeds: ") | |
main(base) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment