Skip to content

Instantly share code, notes, and snippets.

@maxfire2008
Last active December 6, 2021 04:59
Show Gist options
  • Save maxfire2008/7cea1d20f37d9f2c20e15d4441dd1ee5 to your computer and use it in GitHub Desktop.
Save maxfire2008/7cea1d20f37d9f2c20e15d4441dd1ee5 to your computer and use it in GitHub Desktop.
def any_order(a,b,order):
c=a
for item in order:
if item == "+":
c+=b
elif item == "*":
c*=b
elif item == "-":
c-=b
elif item == "/":
c/=b
elif item == "s":
c-=a
return c
def run_test(order,#this is the order see any_order
b,#this is passed as b to any_order
start=1,#this is from, the = means it is by default 1 but can be changed
end=50,#this is to
d=10,#this divides the number if you want decimals eg 0.1 to 5.0
):
for x in range(start,end):#this loops with x as current number
x/=d#this divides x by d so that option has an effect
x = round(#this rounds the output to 10 decimal places (due to floating point incosistensies (don't ask))
any_order(
i,b,order)
,10)#this rounds the output to 10 decimal places (due to floating point incosistensies (don't ask))
print(i,x)
print("""original order: +*-/s this generates b-1
interesting: -/+*s this makes (b-1)*b
To run a test use run_test with parameters specified in the function like so
run_test("+*-/s",2)
The order syntax is each operation with s being subtracting the original number.
You can alos do something like so
run_test("+*-/s",2,-100,100,10)
This will go from -10 to 10 with a step of 0.1. see comments in code for more info""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment