The Collatz conjecture is neat. This is a(n unoptomized) way to explore it.
yarn add collatz-fun
Returns the number after num
in the sequence or null
if terminated.
import collatz from 'collatz-fun'
collatz.next(6) // 3
collatz.next(3) // 10
collatz.next(1) // null
Returns the sequence starting with num
up to max
iterations.
import collatz from 'collatz-fun'
collatz.sequence(7)
// [7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1, null]
collatz.sequence(7, 5)
// [7, 22, 11, 34, 17 ]
Returns summary info about the sequence starting with num
.
import collatz from 'collatz-fun'
collatz.info(27, 150)
// returns
{
finished: true, // sequence terminated
steps: 111, // count of steps
max: 9232, // max
odds: 42, // count of odds
evens: 71, // count of evens
sequence: [27, 82, ... 2, 1, null], // sequence up to max steps
}
kickstarted by npm-boom