-
Notifications
You must be signed in to change notification settings - Fork 0
/
Woefully.py
83 lines (71 loc) · 2.17 KB
/
Woefully.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import re
#################
#DOWN functions!#
#################
def AtoB():
stack_B.append(stack_A.pop())
def diff():
push(stack_A.pop()-stack_B.pop())
def mult():
push(stack_A.pop()*stack_B.pop())
def dupe():
stack_B.append(stack_A[-1])
down_funcs=(AtoB,diff,mult,dupe)
################
#DDR functions!#
################
def move():
global cp
cp[0]+=stack_A.pop()
while cp[0]>=len(program[cp[1]]):
cp[0]=cp[0]-len(program[cp[1]])
cp[1]+=1
if cp[1]>=len(program):cp[1]-len(program)
def notz():
push(int(stack_A.pop()!=0))
def inpt():
push(ord(input()) if i_o_ascii else int(input()))
def otpt():
print(end=chr(stack_A.pop())if i_o_ascii else str(stack_A.pop()))
def swap():
global i_o_ascii
i_o_ascii=not i_o_ascii
ddr_funcs=(move,notz,inpt,otpt,swap)
i_o_ascii=False
stack_A=[0]
stack_B=[0]
push=stack_A.append
og_program=open(input()).read()
program=og_program.split("\n")
cp=[0,0]
if re.findall("[^| \n]| (\n|$)|(\n|^) |^[^ ]*$", og_program):
print("confuse :(")
exit()
finished=False
while not finished:
ip=cp[:]
while program[ip[1]][ip[0]]!=' ':
ip[0]+=1
if len(program[ip[1]])<=ip[0]:
ip[1]+=1
ip[0]=0
instruction_dir=-1
while True:
instruction_counter=1
if len(program)-1 > ip[1] and ' ' in program[ip[1]+1][ip[0]-1:ip[0]+2]:
instruction_dir=-1
while len(program)-1 > ip[1] and ' ' in program[ip[1]+1][ip[0]-1:ip[0]+2]:
if instruction_dir==-1:
instruction_dir=program[ip[1]+1][ip[0]-1:ip[0]+2].find(' ')
elif program[ip[1]+1][ip[0]+instruction_dir-1:][:1]==' ':
ip[1]+=1
ip[0]+=instruction_dir-1
instruction_counter+=1
else:break
if instruction_counter==1:finished=True
if instruction_counter==2:continue
if instruction_dir==0:push(instruction_counter-3)
elif instruction_dir==1:down_funcs[(instruction_counter-3)%4]()
elif instruction_dir==2:ddr_funcs[(instruction_counter-3)%5]()
if not len(program)-1 > ip[1] or not ' ' in program[ip[1]+1][ip[0]-1:ip[0]+2]:
break