1
0
Fork 0
mirror of https://github.com/Lyxal/Keta.git synced 2024-08-14 23:53:13 +00:00

Add files via upload

This commit is contained in:
JonoCode9374 2019-12-26 20:23:20 +11:00 committed by GitHub
parent fdd5a6c17c
commit 8c8fc6e767
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

34
chainify.py Normal file
View file

@ -0,0 +1,34 @@
dyads = "*+-/%"
monads = list(map(chr, range(ord("A"), ord("Z") + 1)))
nilads = "1234567890"
source = input()
arities = []
for char in source:
if char in dyads:
arities.append((2, char))
elif char in monads:
arities.append((1, char))
else:
arities.append((0, char))
exprs = []
while len(arities):
# Try grouping triplets
if len(arities) - 3 >= 0:
exprs.append(arities[-3:])
del arities[-3:]
# Now, try grouping pair
elif len(arities) - 2 >= 0:
exprs.append(arities[-2:])
del arities[-2:]
else:
exprs.append(arities[-1])
del arities[-1]
print(exprs)