Quantcast
Channel: All about basic binary - Code Golf Stack Exchange
Viewing all articles
Browse latest Browse all 23

Answer by Ypnypn for All about basic binary

$
0
0

TI-Basic, 45 bytes

Input NFor(B,2,NIf prod(seq(BfPart(iPart(N/B^X)/B),X,0,log(N)/log(B))<2Disp BEnd

Explanation

  • Input N
  • For every B from 2 to N
    • If N is just 0 and 1 in base B
      • Display B
  • End loop

The complicated part

The second line works as follows:

  • For every X from 0 to logB N
  • B × fPart(iPart(N / BX) / B) is the Nth digit in base B, counting backwards
  • Consider this as a list
  • For each element, if the digit is less than 2, yield 1 (true), else 0 (false)
  • Take the product: 1 iff all elements are 1

Note

The program runs significantly faster if a closing parenthesis ) is placed at the end of the second line. See here for more about this.


Viewing all articles
Browse latest Browse all 23

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>