Last active
November 24, 2023 13:54
-
-
Save nielsrolf/53087a0f801ea6a14fe43c0692055be8 to your computer and use it in GitHub Desktop.
Generate riddles for LLMs
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
import random | |
def generate_riddle(n_hints, n_words, loop_length): | |
""" | |
Build a path towards the correct hint and fill the rest with random hints | |
""" | |
loop_length = loop_length - 1 | |
assert n_words + loop_length < n_hints | |
values = list(range(n_words)) | |
hints = [""] * n_hints | |
direct_hints = [f"The correct value is {i}" for i in values] | |
random.shuffle(direct_hints) | |
for i in range(n_words): | |
hints[i] = direct_hints[i] | |
remaining_hints = list(range(n_words, n_hints)) | |
random.shuffle(remaining_hints) | |
true_hints, false_hints = remaining_hints[:loop_length], remaining_hints[loop_length:] | |
for i in range(loop_length-1): | |
hints[true_hints[i]] = f"Hint {true_hints[i+1]} is correct." | |
final_hint = random.randint(0, n_words) | |
hints[true_hints[-1]] = f"Hint {final_hint} is correct." | |
answer = hints[final_hint] | |
for i in false_hints: | |
hints[i] = f"Hint {random.randint(0, n_hints)} is correct." | |
definitiv_true_hint = f"hint {true_hints[0]} is true" | |
print(f"You will be presented a list of hints, some of which are true and some are false. You only know for sure: {definitiv_true_hint}.") | |
for i in range(n_hints): | |
hints[i] = f"({i}) {hints[i]}" | |
print("\n".join(hints)) | |
print("Which is the correct value? Answer in one word, don't think step by step.") | |
print("--"*80) | |
print(answer) | |
return definitiv_true_hint, answer, hints | |
generate_riddle(40, 10, 20) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://twitter.com/nielsrolf1/status/1656780297365516291