13 lines
238 B
Text
13 lines
238 B
Text
// Computes the syracuse sequence with the given inital term
|
|
// until it reaches 1 (it probably will).
|
|
fn syracuse(x0: int) int {
|
|
x = x0;
|
|
while x != 1 {
|
|
if x % 2 == 0 {
|
|
set x = x / 2;
|
|
} else {
|
|
set x = 3 * x + 1;
|
|
};
|
|
};
|
|
x
|
|
}
|