Skip to content

Instantly share code, notes, and snippets.

@emptyrivers
Last active August 26, 2021 22:04
Show Gist options
  • Save emptyrivers/bacf65749d1fa15199a459a4f470b6b4 to your computer and use it in GitHub Desktop.
Save emptyrivers/bacf65749d1fa15199a459a4f470b6b4 to your computer and use it in GitHub Desktop.
Satisfactory splitter pattern generator
#!/usr/bin/python
from re import sub
from sys import argv
# script that generates splitter pattern for satisfactory
# call with 2 numbers that defines the ratio of the outputs
# e.g. if you want a 3:2 ratio, then run:
# > python sf_ratio.py 3 2
# ^[vv^^]
# feed from the left, and add a splitter for every ^/v
# each splitter will output to the right, and up/down based on the symbol
# if there is a bracketed section, then merge the end of that section to the beginning
result = []
prev_dividends = {}
try:
dividend = int(argv[1])
divisor = int(argv[2]) + dividend
assert(dividend <= divisor)
assert(dividend >= 0)
assert(divisor > 0)
except:
print("those are bad numbers, dummy")
exit(1)
if dividend == divisor or dividend == 0:
print("no splitting necessary")
exit(0)
dividend <<= 1
# yes, this is literally binary long division, im glad you noticed ^_^
# positional notation is just representation of infinite convergent series, after all
while True:
if dividend >= divisor:
result.append('^')
if dividend in prev_dividends:
break
prev_dividends[dividend] = len(result)
dividend -= divisor
else:
result.append('v')
if dividend == 0:
break
dividend <<= 1
if dividend == 0:
print("".join(result))
else:
end_of_nonrepeat = prev_dividends[dividend]
repeating_bit = "".join(result[end_of_nonrepeat:])
nonrepeating_bit = sub("{0}$".format(repeating_bit), "", "".join(result[:end_of_nonrepeat]))
print("{0}[{1}]".format(nonrepeating_bit, repeating_bit))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment