Quantcast
Channel: All about basic binary - Code Golf Stack Exchange
Viewing full articles (26 articles)
Browse article index
↧

Answer by Alex A. for All about basic binary

$
0
0

Julia, 72 70 bytes

It's actually longer with the bonus, so no bonus here.

n=int(readline());for j=2:n all(i->i∈0:1,digits(n,j))&&println(j)end

This reads a line from STDIN, converts it to an integer, and prints the result. Despite being a brute force method, the input 1234321 took less than 1 second for me.

Ungolfed + explanation:

# Read n from STDIN and convert to integern = int(readline())# For every potential base from 2 to nfor j = 2:n    # If all digits of n in base j are 0 or 1    if all(i -> i ∈ 0:1, digits(n, j))        # Print the base on its own line        println(j)    endend

Examples:

julia> n=int(readline());for j=2:n all(i->i∈0:1,digits(n,j))&&println(j)end12343212111112343201234321julia> n=int(readline());for j=2:n all(i->i∈0:1,digits(n,j))&&println(j)end8200023458199982000

NOTE: If input can be taken as a function argument rather than from STDIN (awaiting confirmation from the OP), the solution is 55 bytes.

↧

Viewing full articles (26 articles)
Browse article index

Latest Images

Trending Articles



Latest Images