Interface CodingContract

Coding Contract API

interface CodingContract {
    attempt(answer, filename, host?): string;
    createDummyContract(type): string;
    getContractType(filename, host?): string;
    getContractTypes(): string[];
    getData(filename, host?): any;
    getDescription(filename, host?): string;
    getNumTriesRemaining(filename, host?): number;
}

Methods

  • Attempts a coding contract, returning a reward string on success or empty string on failure.

    Parameters

    • answer: string | number | any[]

      Attempted solution for the contract.

    • filename: string

      Filename of the contract.

    • Optional host: string

      Hostname of the server containing the contract. Optional. Defaults to current server if not provided.

    Returns string

    A reward description string on success, or an empty string on failure.

    Remarks

    RAM cost: 10 GB

    Attempts to solve the Coding Contract with the provided solution.

    Example

    const reward = codingcontract.attempt(yourSolution, filename, hostname);
    if (reward) {
    ns.tprint(`Contract solved successfully! Reward: ${reward}`)
    } else ns.tprint("Failed to solve contract.")
  • Generate a dummy contract.

    Parameters

    • type: string

      Type of contract to generate

    Returns string

    Filename of the contract.

    Remarks

    RAM cost: 2 GB

    Generate a dummy contract on the home computer with no reward. Used to test various algorithms.

  • Get the type of a coding contract.

    Parameters

    • filename: string

      Filename of the contract.

    • Optional host: string

      Hostname of the server containing the contract. Optional. Defaults to current server if not provided.

    Returns string

    Name describing the type of problem posed by the Coding Contract.

    Remarks

    RAM cost: 5 GB

    Returns a name describing the type of problem posed by the Coding Contract. (e.g. Find Largest Prime Factor, Total Ways to Sum, etc.)

  • Get the input data.

    Parameters

    • filename: string

      Filename of the contract.

    • Optional host: string

      Host of the server containing the contract. Optional. Defaults to current server if not provided.

    Returns any

    The specified contract’s data, data type depends on contract type.

    Remarks

    RAM cost: 5 GB

    Get the data associated with the specific Coding Contract. Note that this is not the same as the contract’s description. This is just the data that the contract wants you to act on in order to solve the contract.

  • Get the description.

    Parameters

    • filename: string

      Filename of the contract.

    • Optional host: string

      Hostname of the server containing the contract. Optional. Defaults to current server if not provided.

    Returns string

    Contract’s text description.

    Remarks

    RAM cost: 5 GB

    Get the full text description for the problem posed by the Coding Contract.

  • Get the number of attempts remaining.

    Parameters

    • filename: string

      Filename of the contract.

    • Optional host: string

      Hostname of the server containing the contract. Optional. Defaults to current server if not provided.

    Returns number

    How many attempts are remaining for the contract.

    Remarks

    RAM cost: 2 GB

    Get the number of tries remaining on the contract before it self-destructs.