Skip to content

Instantly share code, notes, and snippets.

@micromaomao
Created June 2, 2019 11:55
Show Gist options
  • Save micromaomao/d50a2c4bd3dabc6a19db898ee96e647d to your computer and use it in GitHub Desktop.
Save micromaomao/d50a2c4bd3dabc6a19db898ee96e647d to your computer and use it in GitHub Desktop.
Braintools
#!/usr/bin/python
import sys
sys.path.insert(0, '../setval')
import setval as v
for x in range(32, 126):
xt = v.genpt(v.tryns(x))
print "(" + chr(x) + xt + ")"
#!/usr/bin/python
import sys
def findlen(a,b,c):
return abs(a) + abs(b) + abs(c)
def tryf(a,n):
b = int(n/a)
jw = n-(a*b)
ret = {}
ret["len"] = findlen(a, b, jw)
ret["a"] = a
ret["b"] = b
ret["c"] = jw
return ret
def tryns(n):
wlen = None
a = 1
while True:
tlen = tryf(a,n)
if wlen is None or wlen["len"] > tlen["len"]:
wlen = tlen
if a >= n:
wlen["a"]
return wlen
a+= 1
def genpt(ns):
return "[-]" + ("+" * ns["a"]) + "[>" + ("+" * ns["b"]) + "<-]>" + (( "+" * ns["c"] ) if ns["c"] >= 0 else ( "-" * -ns["c"] ))
if __name__ == "__main__":
if len(sys.argv) != 2:
print './setval.py <number>'
sys.exit(1)
n = int(sys.argv[1])
ns = tryns(n)
print genpt(ns)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment