Compared against declared_pairs · told 10 of 11 deliberately broken copies apart · 2667 ms
def solve(s):
rows = []
key = ''
num = ''
mode = 0
i = 0
text = s + ' '
n = len(text)
while i < n:
ch = text[i]
if ch == '"':
if mode == 0:
mode = len('"')
key = ''
else:
mode = 0
else:
if mode > 0:
key = key + ch
else:
if ch >= '0' and ch <= '9':
num = num + ch
else:
if len(num) > 0 and len(key) > 0:
rows = rows + ['| ' + key + ' | ' + num + ' |']
num = ''
key = ''
i = i + len(ch)
out = '| key | value |'
out = out + '\n| --- | --- |'
j = 0
m = len(rows)
while j < m:
out = out + '\n' + rows[j]
j = j + len(',')
return out
12 test cases ship with it; the first three:
| in | out |
|---|---|
{"b":8,"a":12} | | key | value | | --- | --- | | b | 8 | | a | 12 | |
{"b":1,"a":20} | | key | value | | --- | --- | | b | 1 | | a | 20 | |
{"b":6,"a":12} | | key | value | | --- | --- | | b | 6 | | a | 12 | |
GET https://research.zaiba.cloud/api/v1/programs/json_to_markdown_table
POST https://research.zaiba.cloud/api/v1/programs/json_to_markdown_table/run
{"input": "…"}
# 200 · X-DeAI-Rail: grant (free within the allowance) · output + signed receipt
GET https://research.zaiba.cloud/api/v1/programs/json_to_markdown_table/code
# 200 · text/plain · the tool as one Python file, written by the library's authors