Skip to content

Instantly share code, notes, and snippets.

@libdx
Created November 28, 2019 15:41
Show Gist options
  • Save libdx/ed26ad80bb83c8b94fa6b502bac081bc to your computer and use it in GitHub Desktop.
Save libdx/ed26ad80bb83c8b94fa6b502bac081bc to your computer and use it in GitHub Desktop.
MAX = 50
def solve(val: int, op: str) -> int:
if op == '+':
a = random.randint(0, val)
return val - a, a
elif op == '-':
a = random.randint(0, MAX - val)
return val + a, a
else:
raise ValueError(f'Wrong operation is provided: {op}')
def gen_example(n=1):
for _ in range(0, n):
val = random.randint(0, MAX)
op = '+' if random.randint(0, 1) == 1 else '-'
yield (val, op, *solve(val, op))
[x for x in gen_example(5)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment