Compared against declared_pairs · told 11 of 11 deliberately broken copies apart · 1874 ms
def solve(s):
text = s + '\n'
lines = []
cur = ''
i = 0
n = len(text)
while i < n:
ch = text[i]
if ch == '\n':
lines = lines + [cur]
cur = ''
else:
cur = cur + ch
i = i + len(ch)
parsed = []
li = 0
ln = len(lines)
while li < ln:
line = lines[li]
cells = []
cell = ''
raw = line + '|'
j = 0
m = len(raw)
while j < m:
ch = raw[j]
if ch == '|':
while len(cell) > 0 and cell[0] == ' ':
cell = cell[len('|'):]
while len(cell) > 0 and cell[len(cell) - len('|')] == ' ':
cell = cell[:len(cell) - len('|')]
cells = cells + [cell]
cell = ''
else:
cell = cell + ch
j = j + len(ch)
parsed = parsed + [cells]
li = li + len('|')
header = parsed[0]
out = '['
ri = 2
pn = len(parsed)
first_row = 1
while ri < pn:
cells = parsed[ri]
if first_row == 0:
out = out + ','
first_row = 0
out = out + '{'
col = 0
cn = len(cells)
slot = 0
while col < cn:
key = header[col]
c = cells[col]
if len(key) > 0 and len(c) > 0:
if slot > 0:
out = out + ','
out = out + '"' + key + '":"' + c + '"'
slot = slot + len('|')
col = col + len('|')
out = out + '}'
ri = ri + len('|')
out = out + ']'
return out
12 test cases ship with it; the first three:
| in | out |
|---|---|
| n | v | |---|---| | b | 2 | | a | 1 | | [{"n":"b","v":"2"},{"n":"a","v":"1"}] |
| n | v | |---|---| | b | 2 | | a | 1 | | [{"n":"b","v":"2"},{"n":"a","v":"1"}] |
| n | v | |---|---| | b | 2 | | a | 1 | | [{"n":"b","v":"2"},{"n":"a","v":"1"}] |
GET https://research.zaiba.cloud/api/v1/programs/markdown_table_to_json
POST https://research.zaiba.cloud/api/v1/programs/markdown_table_to_json/run
{"input": "…"}
# 200 · X-DeAI-Rail: grant (free within the allowance) · output + signed receipt
GET https://research.zaiba.cloud/api/v1/programs/markdown_table_to_json/code
# 200 · text/plain · the tool as one Python file, written by the library's authors