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 value2Limits
anagramChecks if two strings are anagramsYesMax 1000 chars
bubblesortSorts an array of numbers, separated by commasNoMax 1000 elements
factorialCalculates the factorial of a number between 0 and 170No0–170
gcdComputes the greatest common divisor of two numbersYes1–100,000
isprimeChecks if a number is primeNo1–100,000
fibonacciCalculates a Fibonacci sequence up to a given numberNo0–1000
palindromeChecks if a string is a palindromeNoMax 1000 chars
primelistReturns a list of prime numbers up to a given numberNo2–10,000
primefactorsReturns the list of prime factors of a numberNo1–100,000
reverseReverses a stringNoMax 1000 chars
romanConverts between Roman numerals and numbers (1–3999)No1–3999

Response Fields

FieldTypeDescription
answernumber|string|boolean|number[]The algorithm result

Code Examples

curl -X GET \
  "https://api.sylvain.sh/v5/algorithms?method=gcd&value=17&value2=493"

Try It

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
Invalid inputThe value exceeds the method's constraints or limits
Value must be a numberfactorial/isprime: value is not numeric
Value must be an integerfactorial/isprime: value is not a whole number
Number must be positivefactorial/isprime: value is negative (or zero for isprime)
Number must be between 0 and 170factorial: value is out of range
Number must be between 1 and 100000isprime: value is out of range