Created
June 2, 2019 11:55
Star
You must be signed in to star a gist
Braintools
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
#!/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 + ")" |
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
#!/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