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:
parent
fdd5a6c17c
commit
8c8fc6e767
1 changed files with 34 additions and 0 deletions
34
chainify.py
Normal file
34
chainify.py
Normal 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)
|
||||||
|
|
Loading…
Reference in a new issue