Created
October 23, 2019 15:39
-
-
Save randomdude999/9e0544adb9b135be5a422c536e35a93d to your computer and use it in GitHub Desktop.
Result formatter for BF-Crunch output
This file contains hidden or 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
target = input("Target text: ") | |
total_len, init_seg = input("BFCruch output: ").split(": ") | |
start_pointer, _, path = input().partition(", ") | |
path = eval("["+path+"]") | |
tape_segment = eval("["+input()+"]") | |
tape_offset = min(x[0] for x in path) | |
out = init_seg | |
cur_pos = int(start_pointer) | |
for i,x in enumerate(path): | |
if x[0] > cur_pos: | |
out += ">" * (x[0]-cur_pos) | |
elif x[0] < cur_pos: | |
out += "<" * (cur_pos-x[0]) | |
cur_pos = x[0] | |
target_val = ord(target[i]) | |
tape_index = x[0] - tape_offset | |
if tape_segment[tape_index] < target_val: | |
out += "+" * (target_val - tape_segment[tape_index]) | |
elif tape_segment[tape_index] > target_val: | |
out += "-" * (tape_segment[tape_index] - target_val) | |
tape_segment[tape_index] = target_val | |
out += "." | |
print(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment