Generates the complete Collatz sequence (3n+1 problem) for any positive integer until reaching 1. Access via MCP in Cursor or Windsurf, or REST at `/v1/number/collatz`. For example, input 7 produces [7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]. Returns deterministic sequences every time.
curl "https://tinyfn.io/v1/number/collatz" \
-H "X-API-Key: YOUR_API_KEY"
const response = await fetch('https://tinyfn.io/v1/number/collatz', {
headers: { 'X-API-Key': 'YOUR_API_KEY' }
});
const data = await response.json();
console.log(data);
import requests
response = requests.get('https://tinyfn.io/v1/number/collatz',
headers={'X-API-Key': 'YOUR_API_KEY'})
data = response.json()
print(data)
Connect your AI agent (Claude, Cursor, Windsurf, etc.) to TinyFn's number tools:
{
"mcpServers": {
"tinyfn-number": {
"url": "https://tinyfn.io/mcp/number",
"headers": {
"X-API-Key": "YOUR_API_KEY"
}
}
}
}
The Collatz sequence follows simple rules: if n is even, divide by 2; if odd, multiply by 3 and add 1. Continue until reaching 1. Despite its simplicity, it's an unsolved mathematical conjecture.
Use the collatz tool with any positive integer. The MCP tool returns the complete sequence as an array, making it easy for AI agents to analyze mathematical patterns or verify calculations.
Large numbers can produce very long sequences before reaching 1. The tool handles arbitrary-sized integers but be aware that some numbers generate sequences with hundreds or thousands of steps.
The tool returns the complete sequence array. To get just the length, count the returned array elements or use the sequence for further mathematical analysis in your code.
Unlike arithmetic or geometric sequences with predictable patterns, Collatz sequences are chaotic and unpredictable. No formula exists to determine sequence length without computing each step.
Get your free API key and start using Collatz Sequence in seconds.
Get Free API Key