Reputation: 43
def babylonian(symbols):
table=[["T",1], ["<",10],["\\",0]]
returning=0
for pair in table:
forTrue=True
while forTrue:
if len(symbols)>=len(pair[0]):
if symbols[0:len(pair[0])]==pair[0]:
returning+=pair[1]
symbols=symbols[len(pair[0]):]
else:
forTrue=False
else:
forTrue=False
return returning
Hello, what will I have to do so I can get an output similar to this:
print(babylonian(['TT', '<<']))
# should output [2,10]
print(babylonian(['<<T', 'TTT', '//', '<<<<TTT']))
# should output [21,3,0,43]
Currently I can only output the numerals from the tables and if I try to stack ex. TT
, <<
I get an output of 0.
Upvotes: -1
Views: 45
Reputation: 3107
I am trying to make it simple,this is my fist try:
import collections
def babylonian(symbols):
table=[{"T":1}, {"<":10},{"\\":0}]
socre = []
totle = 0
ld = [collections.Counter(each) for each in symbols]
for d in ld:
for k,v in d.items():
for t in table:
totle += t.get(k) * v if t.get(k) else 0
socre.append(totle)
totle = 0
return socre
print(babylonian(["<<T", "TTT","//", "<<<<TTT"]))
Upvotes: 0