Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
math / math-roman-encodeOpenRuns on Liberas

Roman numeral from integer

n (1 to 3999) as a standard Roman numeral in uppercase ASCII: written greedily from M 1000, CM 900, D 500, CD 400, C 100, XC 90, L 50, XL 40, X 10, IX 9, V 5, IV 4, I 1, largest first and each as often as it fits (4 is IV, 9 is IX, 1994 is MCMXCIV, 3999 is MMMCMXCIX). The result is value(text); 0 or over 3999 is invalid(out-of-range).

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init math-roman-encode --lang rust
cd math-roman-encode && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)32 lines›
math-roman-encode.wit
package root:component;

world root {
  import liberas:math/types@0.1.0;

  export liberas:math/roman-encode@0.1.0;
}
package liberas:math@0.1.0 {
  interface types {
    enum math-error {
      syntax,
      too-long,
      division-by-zero,
      too-large,
      out-of-range,
      not-finite,
      empty,
      too-deep,
    }

    variant number-outcome {
      value(string),
      invalid(math-error),
    }
  }
  interface roman-encode {
    use types.{number-outcome};

    to-roman: func(n: u16) -> number-outcome;
  }
}
Test vectors14›
math-roman-encode.cases.json
[
  {
    "args": {
      "n": 1
    }
  },
  {
    "args": {
      "n": 4
    }
  },
  {
    "args": {
      "n": 9
    }
  },
  {
    "args": {
      "n": 14
    }
  },
  {
    "args": {
      "n": 40
    }
  },
  {
    "args": {
      "n": 90
    }
  },
  {
    "args": {
      "n": 400
    }
  },
  {
    "args": {
      "n": 1994
    }
  },
  {
    "args": {
      "n": 2024
    }
  },
  {
    "args": {
      "n": 3888
    }
  },
  {
    "args": {
      "n": 3999
    }
  },
  {
    "args": {
      "n": 0
    }
  },
  {
    "args": {
      "n": 4000
    }
  },
  {
    "args": {
      "n": 65535
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 14 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 1,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.