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

Integer from Roman numeral

The value of numeral when it is a canonical Roman numeral, otherwise none. The canonical numerals are exactly the texts math-roman-encode writes for 1 to 3999: 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. So IIII, VV, IC, XM, IIX, MMMM, lowercase letters, spaces, the empty string and any other character are none.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init math-roman-decode --lang rust
cd math-roman-decode && 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)11 lines›
math-roman-decode.wit
package root:component;

world root {
  export liberas:math/roman-decode@0.1.0;
}
package liberas:math@0.1.0 {
  interface roman-decode {
    from-roman: func(numeral: string) -> option<u16>;
  }
}
Test vectors22›
math-roman-decode.cases.json
[
  {
    "args": {
      "numeral": "I"
    }
  },
  {
    "args": {
      "numeral": "IV"
    }
  },
  {
    "args": {
      "numeral": "IX"
    }
  },
  {
    "args": {
      "numeral": "XIV"
    }
  },
  {
    "args": {
      "numeral": "XL"
    }
  },
  {
    "args": {
      "numeral": "XC"
    }
  },
  {
    "args": {
      "numeral": "CD"
    }
  },
  {
    "args": {
      "numeral": "MCMXCIV"
    }
  },
  {
    "args": {
      "numeral": "MMXXIV"
    }
  },
  {
    "args": {
      "numeral": "MMMDCCCLXXXVIII"
    }
  },
  {
    "args": {
      "numeral": "MMMCMXCIX"
    }
  },
  {
    "args": {
      "numeral": "IIII"
    }
  },
  {
    "args": {
      "numeral": "VV"
    }
  },
  {
    "args": {
      "numeral": "IC"
    }
  },
  {
    "args": {
      "numeral": "XM"
    }
  },
  {
    "args": {
      "numeral": "IIX"
    }
  },
  {
    "args": {
      "numeral": "MMMM"
    }
  },
  {
    "args": {
      "numeral": "iv"
    }
  },
  {
    "args": {
      "numeral": " I"
    }
  },
  {
    "args": {
      "numeral": ""
    }
  },
  {
    "args": {
      "numeral": "N"
    }
  },
  {
    "args": {
      "numeral": "MCMXCIVI"
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 22 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%.