Motzkin number calculator
Get the Motzkin number at any position n, built by the standard recurrence from two starting terms equal to 1: position 0 gives 1, and each later term adds the previous one to a sum of products of earlier terms. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- N
- 0
- Value
- 1
n-th Motzkin number via standard recurrence. Search intent: motzkin number calculator. No network calls or random seeds are required. Failed jobs are not billed.
How Motzkin numbers are built from the first two
Motzkin numbers form a sequence in which each term is built from the ones before it. The first two, at positions 0 and 1, are both 1. To get the term at position n, you start from the previous term and then add a sum of products: you pair up earlier terms whose positions add up to n minus 2, multiply each pair, and add all those products together. For position 2 there is only one pair, the term at position 0 with itself, so the result is 1 plus 1 times 1, which is 2. Every later term follows the same rule, so the terms are always whole numbers.
Using the calculator and avoiding slips
Type the position n, a whole number starting at 0, and the calculator returns the Motzkin number at that position next to the index you entered, so you can copy both into notes or a table. The usual slips when working by hand are counting positions from 1 instead of 0, forgetting to add the previous term before the sum of products, and pairing terms whose positions do not add up to n minus 2. A negative position or a value that is not a number is refused before any arithmetic, and the same position always gives the same answer, with no randomness involved.
What you can do with it
Teaching
Pinned goldens.
FAQ
What is the first Motzkin number?
Positions start at 0, and the first two terms, at positions 0 and 1, are both 1. Every other number in the sequence is built from those two starting values.
How is each Motzkin number calculated?
Take the previous term and add the products of every pair of earlier terms whose positions add up to n minus 2. For position 2 that gives 1 plus 1 times 1, which is 2.
Which values of n can I enter?
Whole numbers from 0 upward. A negative position or something that is not a number is refused before any arithmetic, instead of producing a result that means nothing.
Will I always get the same result?
Yes. The calculation uses no randomness and no network connection, so the same position always gives the same answer. The position you entered is shown next to the result as well.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/math/motzkin-number \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":5}'const res = await fetch("https://api.kit.forhosting.com/math/motzkin-number", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 5
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/math/motzkin-number",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 5
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/math/motzkin-number", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":5}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":5}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/math/motzkin-number", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"n": 5
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "math.motzkin_number",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
The calculator is free in the browser, deterministic, and identical on the API path. Inputs are validated before arithmetic so invalid payloads fail with invalid_input. Half-up rounding is applied once from raw IEEE values when decimals are requested. Use the same JSON from spreadsheets, CMS, automation, or teaching demos.
How it works
n-th Motzkin number via standard recurrence. No network calls or random seeds are required. Failed jobs are not billed. No network calls or random seeds are required. Failed jobs are not billed. M0=M1=1; Mn=M(n-1)+Σ Mi M(n-2-i). The calculator is free in the browser, deterministic, and identical on the API path. Inputs are validated before arithmetic so invalid payloads fail with invalid_input. Half-up rounding is applied once from raw IEEE values when decimals are requested. Use the same JSON from spreadsheets, CMS, automation, or teaching demos. The calculator is free in the browser, deterministic, and identical on the API path. Inputs are validated before arithmetic so invalid payloads fail with invalid_input. Half-up rounding is applied once from raw IEEE values when decimals are requested. Use the same JSON from spreadsheets, CMS, automation, or teaching demos.
Inputs, limits and rounding
Optional decimals use half-up once. Outputs echo inputs. No network calls or random seeds are required. Failed jobs are not billed. No network calls or random seeds are required. Failed jobs are not billed. Provide required JSON fields. Invalid types raise invalid_input. The calculator is free in the browser, deterministic, and identical on the API path. Inputs are validated before arithmetic so invalid payloads fail with invalid_input. Half-up rounding is applied once from raw IEEE values when decimals are requested. Use the same JSON from spreadsheets, CMS, automation, or teaching demos. The calculator is free in the browser, deterministic, and identical on the API path. Inputs are validated before arithmetic so invalid payloads fail with invalid_input. Half-up rounding is applied once from raw IEEE values when decimals are requested. Use the same JSON from spreadsheets, CMS, automation, or teaching demos.
When to use it
Use when search intent matches. n-th Motzkin number via standard recurrence. No network calls or random seeds are required. Failed jobs are not billed. No network calls or random seeds are required. Failed jobs are not billed. The calculator is free in the browser, deterministic, and identical on the API path. Inputs are validated before arithmetic so invalid payloads fail with invalid_input. Half-up rounding is applied once from raw IEEE values when decimals are requested. Use the same JSON from spreadsheets, CMS, automation, or teaching demos. The calculator is free in the browser, deterministic, and identical on the API path. Inputs are validated before arithmetic so invalid payloads fail with invalid_input. Half-up rounding is applied once from raw IEEE values when decimals are requested. Use the same JSON from spreadsheets, CMS, automation, or teaching demos.
Integration use cases
Quick check
Free widget.
Automation
Same JSON via API.
Technical questions
Free?
Yes tier A.
Network?
No.
Bad input?
invalid_input.
API?
Yes.
Locales?
EN-only; Nitro hydrates.