Skip to content

Algorithms

The /algorithms endpoint provides several algorithms to use as parameters. You can input one or two values depending on the algorithm.

Parameters

ParameterRequiredDescription
methodYesThe algorithm to use (see available methods below)
valueYesThe value to use in the algorithm. Must contain at least one character
value2NoThe second value to use if necessary. Must contain at least one character

Available Methods

MethodDescriptionRequires value2
anagramChecks if two strings are anagramsYes
bubblesortSorts an array of numbers, separated by commasNo
factorialCalculates the factorial of a number between 0 and 170No
gcdComputes the greatest common divisor of two numbersYes
isprimeChecks if a number is primeNo
fibonacciCalculates a Fibonacci sequence up to a given numberNo
palindromeChecks if a string is a palindromeNo
primelistReturns a list of prime numbers up to a given numberNo
primefactorsReturns the list of prime factors of a numberNo
reverseReverses a stringNo

Request Example

GET /v3/algorithms?method=gcd&value=17&value2=493

Response

json
{
  "answer": 17
}

cURL

bash
curl -X GET "https://api.sylvain.pro/v3/algorithms?method=gcd&value=17&value2=493"

Error Handling

If parameters are missing or invalid, the API will return an error:

Error MessageDescription
Please provide a valid algorithm (?method={algorithm})The method parameter is missing or invalid