JSFiddle - React, Tailwind, and code Playground

by Nicolas PUJOL

JavaScript

function floyd(x0) {
    tortoise = next(x0) // f(x0) is the element/node next to x0.
    hare = next(next(x0))
    while (tortoise != hare) {
        tortoise = next(tortoise)
        hare = next(next(hare))
    }
    /***/
    mu = 0
    tortoise = x0
    while (tortoise != hare) {
        tortoise = next(tortoise)
        hare = next(hare)
        mu += 1
    }
    /***/
    lam = 1
    hare = next(tortoise)
    while (tortoise != hare) {
        hare = next(hare)
        lam += 1
    }

    return lam, mu
}

function next() {

}
console.log(floyd("1"));