ForHosting KIT · Math

Narayana's cows sequence calculator

Get any term of Narayana's cows sequence from index 0 to 97: N(10) is 28, because each term adds the one just before it to the one three places back, 19 plus 9. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
N
10
You get
Value
28
Sequence
Narayana's cows
Recurrence
N(0)=N(1)=N(2)=1; N(n)=N(n-1)+N(n-3) for n>=3

Narayana's cows sequence models a herd in which each mature cow produces one calf every year and calves begin reproducing after a delay. In its standard zero-based form, the first three terms are all one, and every later term adds the value one place back to the value three places back. This calculator returns one exact term for a non-negative index, together with the convention and recurrence used. It is useful for checking coursework, validating programs, exploring recurrence relations, and avoiding accidental confusion with Fibonacci or Padovan numbers.

Understand the sequence and its indexing convention

This calculator uses the zero-based Narayana's cows sequence N(0)=1, N(1)=1, and N(2)=1. For every index n of at least three, the recurrence is N(n)=N(n-1)+N(n-3). In plain language, each new value combines the immediately preceding term with the term three positions earlier.

The opening terms are therefore 1, 1, 1, 2, 3, 4, 6, 9, 13, 19, and 28. For example, N(6) is N(5)+N(3), which is 4+2=6; N(10) is N(9)+N(7), which is 19+9=28. Stating the seeds matters because some books shift the same values and label the first cow count as term one.

The response always echoes n and includes the complete seed and recurrence text, making the chosen convention explicit. That detail helps when comparing a worksheet, a sequence database, or another library whose displayed position may start at one. Negative indices are outside this calculator's domain and return an invalid-input error instead of silently applying a nonstandard backward extension.

Send an index and interpret the response

Provide n as a non-negative whole number from zero through ninety-seven. A successful result contains four fields: n is the normalized zero-based index; value is the requested Narayana's cows number; sequence names the sequence; and recurrence records both the three initial ones and the one-place-plus-three-places-back rule. If n is sent as a string containing an integer, such as "10", it is normalized to the number 10.

Fractions, blank values, arbitrary text, negative numbers, and values beyond the published exact-integer limit are rejected. The computation walks forward with three rolling values, requiring constant memory and at most ninety-five additions. It does not download a lookup table, call an outside sequence service, use a language model, or approximate the answer with a floating-point closed form.

Use the result in lessons, tests, and recurrence experiments

Narayana's cows numbers are especially useful when teaching how initial conditions and recurrence offsets jointly determine a sequence. Ask learners to construct a small table with columns for n, N(n-1), N(n-3), and N(n), then compare each row with this calculator. In automated tests, assert the echoed index and recurrence as well as the numeric value; doing so catches a common mistake in which an implementation adds the terms two and three places back, producing Padovan numbers, or adds the two immediately previous terms, producing Fibonacci-like growth.

The calculator is also a compact oracle for programming exercises involving loops, rolling state, dynamic programming, and off-by-one errors. When another source begins 1, 1, 1 at positions one, two, and three, shift its displayed position by one before comparing it with this zero-based output. For accepted inputs, the recurrence loop is deterministic and has no hidden state, network dependency, clock access, or randomness.

Check a recurrence homework answer

Compare a hand-computed term with an exact result that states the seeds, index, and recurrence convention.

Validate an implementation

Use known outputs as test cases for loops, dynamic programming exercises, or sequence-library code.

Demonstrate delayed population growth

Show how a three-step reproductive delay creates growth distinct from Fibonacci and other familiar recurrences.

What is Narayana's cows sequence?

It is the integer sequence defined here by N(0)=N(1)=N(2)=1 and N(n)=N(n-1)+N(n-3) for n at least 3.

Does indexing start at zero or one?

This calculator starts at zero, so N(0), N(1), and N(2) are all 1. Sources using one-based positions show the same opening values with shifted labels.

Why is the maximum index 97?

N(97) is the last term that remains an exact JavaScript safe integer under this convention; larger results need a BigInt-oriented output contract.

What is N(10) in Narayana's cows sequence?

N(10) is 28. It is the sum of N(9), which is 19, and N(7), which is 9: the term just before plus the term three places back.

What are the first terms of the sequence?

Counting from index 0, the sequence starts 1, 1, 1, 2, 3, 4, 6, 9, 13, 19 and 28. The first three terms are all 1, and every later term follows the same rule.

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.

POSThttps://api.kit.forhosting.com/numth/narayana-cows

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.

curl -X POST https://api.kit.forhosting.com/numth/narayana-cows \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"n":10}'
{
  "n": 10
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.narayana_cows",
  "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.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Understand the sequence and its indexing convention

The algorithm uses only exact integer addition, so every accepted result is reproducible in the browser and through the API.

Send an index and interpret the response

The field is required, and index is accepted as a descriptive alias. The upper bound exists because this lightweight capability returns ordinary JSON numbers, and N(97) is the last term in this convention that remains within JavaScript's safe-integer range. That shared implementation keeps examples, interactive results, and API responses aligned.

Use the result in lessons, tests, and recurrence experiments

Do not use the endpoint for negative-index extensions or enormous arbitrary-precision terms, because those require additional conventions or BigInt serialization that this simple JSON-number contract intentionally avoids.

What happens when n is negative?

The request returns invalid_input. This capability does not define or infer a backward extension of the sequence.

How much does an API request cost?

A successful API request costs $0.002. The browser calculator runs the same deterministic solving logic locally.

Read the full KIT documentation →