Skip to content

Instantly share code, notes, and snippets.

@randomdude999
Created October 23, 2019 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save randomdude999/9e0544adb9b135be5a422c536e35a93d to your computer and use it in GitHub Desktop.
Save randomdude999/9e0544adb9b135be5a422c536e35a93d to your computer and use it in GitHub Desktop.
Result formatter for BF-Crunch output
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