Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
math / math-words-enOpenRuns on Liberas

Number in English words

n as English words, US style. n is an integer: an optional - then 1 or more ASCII digits (leading zeros allowed), at most 100 bytes, with |n| < 10^36. 0 (and -0) is zero; a negative n is minus, a space, then the words for |n|. |n| is split into groups of three digits from the right; each non-zero group, most significant first, is its words followed by its scale word (none, thousand, million, billion, trillion, quadrillion, quintillion, sextillion, septillion, octillion, nonillion, decillion); zero groups are left out. A group 1 to 999: when its hundreds digit h is not 0, the word for h then hundred; then, when its last two digits r are not 0: one … nineteen for r < 20; twenty, thirty, forty, fifty, sixty, seventy, eighty, ninety for a multiple of ten; otherwise the tens word, a hyphen and the unit word (twenty-one, ninety-nine). Lowercase ASCII words separated by single spaces; no and, no commas: 101 is one hundred one, 1234 is one thousand two hundred thirty-four, 1000000 is one million. The result is value(text). Errors are invalid(reason), in this order: over 100 bytes → too-long; not an integer → syntax; |n| ≥ 10^36 → 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-words-en --lang rust
cd math-words-en && 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-words-en.wit
package root:component;

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

  export liberas:math/words@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 words {
    use types.{number-outcome};

    words: func(n: string) -> number-outcome;
  }
}
Test vectors26›
math-words-en.cases.json
[
  {
    "args": {
      "n": "0"
    }
  },
  {
    "args": {
      "n": "-0"
    }
  },
  {
    "args": {
      "n": "7"
    }
  },
  {
    "args": {
      "n": "13"
    }
  },
  {
    "args": {
      "n": "21"
    }
  },
  {
    "args": {
      "n": "40"
    }
  },
  {
    "args": {
      "n": "99"
    }
  },
  {
    "args": {
      "n": "100"
    }
  },
  {
    "args": {
      "n": "101"
    }
  },
  {
    "args": {
      "n": "110"
    }
  },
  {
    "args": {
      "n": "999"
    }
  },
  {
    "args": {
      "n": "1000"
    }
  },
  {
    "args": {
      "n": "1001"
    }
  },
  {
    "args": {
      "n": "1234"
    }
  },
  {
    "args": {
      "n": "-1234567"
    }
  },
  {
    "args": {
      "n": "1000000"
    }
  },
  {
    "args": {
      "n": "1000001000"
    }
  },
  {
    "args": {
      "n": "000042"
    }
  },
  {
    "args": {
      "n": "999999999999999999999999999999999999"
    }
  },
  {
    "args": {
      "n": "1000000000000000000000000000000000"
    }
  },
  {
    "args": {
      "n": "1000000000000000000000000000000000000"
    }
  },
  {
    "args": {
      "n": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
    }
  },
  {
    "args": {
      "n": "+1"
    }
  },
  {
    "args": {
      "n": "1 000"
    }
  },
  {
    "args": {
      "n": ""
    }
  },
  {
    "args": {
      "n": "1.5"
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 26 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%.