OFFSET
1,2
COMMENTS
Any number whose Collatz trajectory has two or more consecutive halving steps (before reaching a power of 2) is not included in this sequence.
The b-file was generated using the reverse Collatz algorithm.
Instead of going: n -> 3n + 1 (if odd), n/2 (if even), this algorithm starts from a power of 2 and goes: n -> (n - 1)/3 (if possible) and n*2, repeating these two consecutive steps as long as the number n is divisible by 3. The results are progressively added to a dynamic array, which gets sorted by ascending order once the algorithm terminates.
Example 1: 8 -> (8 - 1) and the calculation stops because 7 isn't divisible by 3. No numbers are added to the dynamic array.
Example 2: 16 -> (16 - 1)/3 = 5; 5*2 = 10; (10 - 1)/3 = 3; 3*2 = 6; (6 - 1) and the calculation stops because 5 isn't divisible by 3. The numbers 5, 10, 3, 6 are then added to the dynamic array.
Example 3: 64 -> (64 - 1)/3 = 21; 21*2 = 42; (42 - 1) and the calculation stops because 41 isn't divisible by 3. The numbers 21 and 42 are then added to the dynamic array.
LINKS
EXAMPLE
6 is in the sequence because 6/2 = 3 (halving step); 3*3 + 1 = 10 (tripling step); 10/2 = 5 (halving step); 5*3 + 1 = 16 (tripling step) and a power of 2 is reached.
7 is not in this sequence because 7*3 + 1 = 22 (tripling step); 22/2 = 11 (halving step); 11*3 + 1 = 34 (tripling step); 34/2 = 17 (halving step); 17*3 + 1 = 52 (tripling step); 52/2 = 26 (halving step); 26/2 = 13 (another halving step).
PROG
(PARI) isp2(n) = (n==1) || (n==2) || (ispower(n, , &p) && (p==2));
isok(n) = {while (! isp2(n), if (n % 2, newn = (3*n+1), newn = n/2); if (((n % 2) == (newn % 2)), return (0)); n = newn; ); return (1); } \\ Michel Marcus, Oct 07 2018
(Java) for(BigInteger pow = TWO; pow.compareTo(END) < 0; pow = pow.multiply(TWO)) {
terms.add(pow); //otherwise numbers like 8, 32, 128, etc. aren't added
BigInteger newPow = pow.subtract(ONE);
while(newPow.mod(THREE).compareTo(ZERO) == 0) {
terms.add(newPow.add(ONE));
newPow = newPow.divide(THREE);
terms.add(newPow);
newPow = newPow.add(newPow);
terms.add(newPow);
newPow = newPow.subtract(ONE);
}
}
terms.sort(Comparator.naturalOrder()); //sorting by ascending order
for(int i = 1; i < terms.size(); i++) {
if(terms.get(i).compareTo(terms.get(i - 1)) == 0) {
terms.remove(i); //to remove duplicates
}
}
CROSSREFS
KEYWORD
nonn
AUTHOR
Alessandro Polcini, Oct 03 2018
STATUS
approved