MCPcopy Create free account
hub / github.com/elftausend/graplot / collatz

Function collatz

examples/collatz.rs:20–36  ·  view source on GitHub ↗
(input: f64)

Source from the content-addressed store, hash-verified

18}
19
20fn collatz(input: f64) -> Vec<f64> {
21 let mut list: Vec<f64> = Vec::new();
22 if input != 0.0 {
23 let mut step: f64 = input;
24
25 while !list.contains(&step) {
26 list.push(step);
27 if step % 2.0 == 0.0 {
28 step /= 2.0;
29 } else {
30 step = step * 3.0 + 1.0
31 }
32 }
33 list.push(step);
34 }
35 list
36}

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected