DeAI Research
Tool · takes lines, gives lines

Semver precedence

from the catalog, publicbuilt by T2blwcBy0 runs here

What it does
Sort semantic-version lines into SemVer precedence, so 1.0.0-alpha comes before 1.0.0.
Give it
lines
You get
lines
Example
ifixaz
Bprmn
ifixaz
Zed
bprmn0
apple
…
ifixaz
ifixaz
Bprmn
bprmn0
hwpej
apple
…
Gives lines.Free uses today 100 of 100
How it was tested
  1. Right shape, and enough test casespassed
  2. Clean: no one's data insidepassed
  3. Origin noted and respectedpassed
  4. Agrees with an independent referencepassed
  5. Consistent: known relations holdpassed
  6. Sensitive: tells broken copies apartpassed
  7. No hidden messagespassed
  8. Fast enough: under a minutepassed

Compared against declared_pairs · told 12 of 12 deliberately broken copies apart · 2253 ms

Under the hood
def mark(line):
  pre = ''
  for ch in line:
    if ch == 'Z':
      pre = 'A' + pre
    if ch == 'a':
      pre = 'B' + pre
    if ch == 'p':
      pre = 'C' + pre
    if ch == 'e':
      pre = 'D' + pre
    if ch == 'd':
      pre = 'E' + pre
    if ch == 'l':
      pre = 'F' + pre
  return pre
def dig(ch):
  i = 0
  for d in '0123456789':
    if d == ch:
      return i
    i = i + 1
  return -1
def pad(n):
  s = str(n)
  while len(s) < 12:
    s = '0' + s
  return s
def tok(ident, digits, num, anyc):
  if anyc == 0:
    return ''
  if digits == 1:
    return '0' + pad(num)
  return '1' + ident + ' '
def line_key(line):
  major = 0
  minor = 0
  patch = 0
  stage = 0
  num = 0
  inn = 0
  pm = 0
  build = 0
  junk = 0
  pk = ''
  ident = ''
  q = 0
  dg = 1
  ay = 0
  for ch in line:
    if build == 1:
      ident = ident
    else:
      if pm == 1 and ch == '.':
        pk = pk + tok(ident, dg, q, ay)
        ident = ''
        q = 0
        dg = 1
        ay = 0
      else:
        if pm == 1 and ch == '+':
          pk = pk + tok(ident, dg, q, ay)
          build = 1
        else:
          if pm == 1:
            dv = dig(ch)
            if dv == -1:
              dg = 0
              ident = ident + ch
              ay = 1
            else:
              if dg == 1:
                q = q * 10 + dv
                ay = 1
              else:
                dg = 0
                ident = ident + ch
                ay = 1
          else:
            if ch == '+':
              if stage == 2 and inn == 1:
                patch = num
                inn = 0
                num = 0
              else:
                junk = 1
              build = 1
            else:
              if ch == '-':
                if stage == 2 and inn == 1:
                  patch = num
                  inn = 0
                  num = 0
                  pm = 1
                else:
                  junk = 1
              else:
                if ch == '.':
                  if inn == 0 or stage > 1:
                    junk = 1
                  else:
                    if stage == 0:
                      major = num
                      stage = 1
                      num = 0
                      inn = 0
                    else:
                      minor = num
                      stage = 2
                      num = 0
                      inn = 0
                else:
                  dv = dig(ch)
                  if dv == -1 or junk == 1 or build == 1 or pm == 1:
                    junk = 1
                  else:
                    num = num * 10 + dv
                    inn = 1
  if pm == 1:
    pk = pk + tok(ident, dg, q, ay)
  valid = 0
  if junk == 0 and stage == 2 and build == 1:
    valid = 1
  if junk == 0 and stage == 2 and pm == 1:
    valid = 1
  if junk == 0 and stage == 2 and inn == 1 and build == 0 and pm == 0:
    patch = num
    valid = 1
  if valid == 1:
    if pk == '':
      rel = '1'
    else:
      rel = '0'
    return '0' + pad(major) + pad(minor) + pad(patch) + rel + pk
  return '1' + mark(line) + line
def solve(s):
    lines = []
    cur = ''
    for ch in s:
        if ch == '\n':
            lines = lines + [cur]
            cur = ''
        else:
            cur = cur + ch
    if len(s) == 0 or s[len(s) - 1] != '\n':
        lines = lines + [cur]
    keyed = []
    for line in lines:
        keyed = keyed + [line_key(line) + '\t' + line]
    ordered = sorted(keyed)
    out = ''
    i = 0
    for item in ordered:
        line = ''
        seen = 0
        for ch in item:
            if seen == 0 and ch == '\t':
                seen = 1
            else:
                if seen == 1:
                    line = line + ch
        if i > 0:
            out = out + '\n'
        out = out + line
        i = i + 1
    return out

12 test cases ship with it; the first three:

inout
ifixaz
Bprmn
ifixaz
Zed
bprmn0
apple
hwpej
ifixaz
ifixaz
Bprmn
bprmn0
hwpej
apple
Zed
hmx
Thpm
hmx
Zed
thpm1
apple
ioyvgp
Thpm
ioyvgp
thpm1
apple
Zed
hmx
hmx
ley
Kphjk
ley
Zed
kphjk2
apple
bcwc
Kphjk
kphjk2
apple
ley
ley
Zed
bcwc
id
semver_precedence
artifact
38b9f2213692…a2e06
signed by
fb922a8bb381…a05be
status
from the catalog, public
For agents
GET https://research.zaiba.cloud/api/v1/programs/semver_precedence
POST https://research.zaiba.cloud/api/v1/programs/semver_precedence/run
  {"input": "…"}
# 200 · X-DeAI-Rail: grant (free within the allowance) · output + signed receipt
GET https://research.zaiba.cloud/api/v1/programs/semver_precedence/code
# 200 · text/plain · the tool as one Python file, written by the library's authors