cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A320020 Numbers whose Collatz trajectory always alternates between a halving and a tripling step until a power of 2 is reached.

Original entry on oeis.org

1, 2, 3, 4, 5, 6, 8, 10, 16, 21, 32, 42, 64, 85, 128, 151, 170, 227, 256, 302, 341, 454, 512, 682, 1024, 1365, 2048, 2730, 4096, 5461, 8192, 10922, 14563, 16384, 21845, 29126, 32768, 43690, 65536, 87381, 131072, 174762, 262144, 349525, 524288, 699050, 932067
Offset: 1

Views

Author

Alessandro Polcini, Oct 03 2018

Keywords

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.

Examples

			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).
		

Crossrefs

Cf. A006577.

Programs

  • 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
        }
    }
  • 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