Compared against declared_pairs · told 12 of 12 deliberately broken copies apart · 1897 ms
def kind_of(ch):
kind = 0
if ch == ' ':
kind = 1
if ch == '\n':
kind = 2
if ch == '_':
kind = 3
if ch == '/':
kind = 4
if ch == '.':
kind = 5
if ch == '-':
kind = 6
return kind
def lower(ch):
upper = 'ABCDEFGHIJKLMNOP' + 'QRSTUVWXYZ'
lower_s = 'abcdefghijklmnop' + 'qrstuvwxyz'
digits = '0123456789'
i = 0
for u in upper:
if ch == u:
return lower_s[i]
i = i + 1
for d in digits:
if ch == d:
return d
for u in lower_s:
if ch == u:
return u
return ''
def solve(s):
raw = ''
for ch in s:
kind = kind_of(ch)
if kind == 1:
raw = raw + '-'
else:
if kind == 2:
raw = raw + '-'
else:
if kind == 3:
raw = raw + '-'
else:
if kind == 4:
raw = raw + '-'
else:
if kind == 5:
raw = raw + '-'
else:
if kind == 6:
raw = raw + '-'
else:
raw = raw + lower(ch)
out = ''
prev = 0
for ch in raw:
if ch == '-':
if prev == 0 and len(out) > 0:
out = out + '-'
prev = 1
else:
out = out + ch
prev = 0
if len(out) > 0 and out[len(out) - 1] == '-':
out = out[:len(out) - 1]
return out
12 test cases ship with it; the first three:
| in | out |
|---|---|
nix emba nix rni 0 | nix-emba-nix-rni-0 |
tsewhx iqc tsewhx gnq 1 | tsewhx-iqc-tsewhx-gnq-1 |
cofi clf cofi nsw 2 | cofi-clf-cofi-nsw-2 |
GET https://research.zaiba.cloud/api/v1/programs/slugify
POST https://research.zaiba.cloud/api/v1/programs/slugify/run
{"input": "…"}
# 200 · X-DeAI-Rail: grant (free within the allowance) · output + signed receipt
GET https://research.zaiba.cloud/api/v1/programs/slugify/code
# 200 · text/plain · the tool as one Python file, written by the library's authors