Created
August 14, 2016 07:08
-
-
Save ptr-yudai/289a6c38b5f1cfbacaa13cf4066b5471 to your computer and use it in GitHub Desktop.
brainf**kで文字列を出力するコードを出力するコード
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
# coding: utf-8 | |
import math | |
# 出力されるbrainf**kコード | |
code = "" | |
# brainf**kから出力したい文字 | |
text = "Furutsuki is a Pro!" | |
# 1文字ずつ | |
for c in text: | |
# ord(c) = q * pとなるp, qでpとqが近いものを探したい | |
q = int(math.sqrt(ord(c))) | |
p = 0 | |
for i in range(q): | |
q -= 1 | |
# ord(c) = q * pを発見 | |
if q != 0: | |
if ord(c) % q == 0: | |
p = ord(c) / q | |
break | |
# q回院クリメント | |
for i in range(q): | |
code += "+" | |
# p回院クリメントをq回ループ | |
code += "[>" | |
for i in range(p): | |
code += "+" | |
code += "<-]>.>" | |
print(code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment