Quantcast
Channel: All about basic binary - Code Golf Stack Exchange
Browsing latest articles
Browse All 23 View Live

Answer by rak1507 for All about basic binary

APL (Dyalog Extended), 28 bytes, 28 * 0.75 = 21{{⍵⌿⍨∧/2>↑2⌷⍉⍵}(⍪,⊤∘⍵¨)1↓⍳⍵}1↓⍳⍵ all numbers from 2 to ⍵(⍪,⊤∘⍵¨) each number with the representation of ⍵ in that base{⍵⌿⍨∧/2>↑2⌷⍉⍵} dfn to...

View Article



Answer by Shaggy for All about basic binary

Japt-R, 11 bytesõ2 f@ìX e§1Try itõ2 f@ìX e§1 :Implicit input of integer Uõ2 :Range [2,U] f :Filter by @ :Passing each X through the following fuctionìX : Convert U to base X digit array e : All§1 :...

View Article

Answer by Razetime for All about basic binary

Husk, 11 10 bytes¶tfoΛε`B¹ḣTry it online!-1 byte from Zgarb.Explanation¶tfoΛ<2`B¹ḣḣ list from 1..n f filter based on the result of the following o composition of 2 functions `B¹ the input in base n...

View Article

Answer by Xcali for All about basic binary

Perl 5, 63 bytesmap{$t=$n;1while($f=$t%$_<2)&&($t=int$t/$_);say if$f}2..($n=<>)Try it online!No bonus on this because it scores very slightly better than my version with the bonus:Perl...

View Article

Answer by daniero for All about basic binary

Ruby, 44 bytes->n{(2..n).select{|i|n.digits(i)-[0,1]==[]}}Try it online!

View Article


Answer by Mr. Xcoder for All about basic binary

Jelly, 9 bytes³bṀỊµÐfḊYTry it online!Done alongside caird coinheringaahing in chat.How it works³bṀỊµÐfḊY Full program.Ðf Filter the implicitly generated range [1, input].µ Starts a new monadic chain.³b...

View Article

Answer by Tally for All about basic binary

Mathematica, 76 * 0.75 = 57n=Input[];G=#~IntegerDigits~b&;If[Max@G@n<2,Print[b," ",Row@G@n]]~Do~{b,2,n}Initially forgot about the input requirements... Fortunately, those didn't add too much extra.

View Article

Answer by lirtosiast for All about basic binary

TI-BASIC, 31 29For(B,2,AnsIf 2>round(Bmax(fPart(Ans/B^randIntNoRep(1,32Disp BEndThis is probably optimal for TI-BASIC.Explanation: randIntNoRep(1,32) returns a random permutation of the numbers from...

View Article


Answer by plannapus for All about basic binary

R, 9483 79n=scan();cat((2:n)[!sapply(2:n,function(x){while(n&n%%x<2)n=n%/%x;n})],sep="\n")Usage:> n=scan();cat((2:n)[!sapply(2:n,function(x){while(n&n%%x<2)n=n%/%x;n})],sep="\n")1:...

View Article


Answer by MickyT for All about basic binary

SQL (PostgreSQL), 247.5255 230.25 (307 * .75)Since SQL is known to be wonderful at these sorts of challenges, I thought I better put one together :) The bonus was really worthwhile for this one.It...

View Article

Answer by edc65 for All about basic binary

JavaScript (ES6) 6568 bytes for a function with a parameter and console output.f=n=>{s=n=>n%b>1||b<n&&s(n/b|0);for(b=1;b++<n;)s(n)||console.log(b)}65 bytes with I/O via...

View Article

Answer by Sp3000 for All about basic binary

Python 2, 90 * 0.75 = 67.5n=input();b=1while b<n: b+=1;s="";c=k=n while k:s=`k%b`+s;c*=k%b<2;k/=b if c:print b,sPretty straightforward iterative approach.Without the bonus, this is 73...

View Article

Answer by Ypnypn for All about basic binary

TI-Basic, 45 bytesInput NFor(B,2,NIf prod(seq(BfPart(iPart(N/B^X)/B),X,0,log(N)/log(B))<2Disp BEndExplanationInput NFor every B from 2 to NIf N is just 0 and 1 in base BDisplay BEnd loopThe...

View Article


Answer by Qwertiy for All about basic binary

Javascript, ES6, 118*.75 = 88.5 110*.75 = 82.5f=x=>{res={};for(b=2;b<=x;++b)if(!+(res[b]=(c=x=>x%b<2?x?c(x/b|0)+""+x%b:"":"*")(x)))delete res[b];return res}Previous...

View Article

Answer by MickyT for All about basic binary

R, 111Probably a lot of room to improve this at the momenti=scan();b=2:i;R=i%%b;I=rep(i,i-1);while(any(I<-I%/%b))R=cbind(I%%b,R);for(x in b)if(all(R[x-1,]<2))cat(x,'\n')Runs with warnings>...

View Article


Answer by TheNumberOne for All about basic binary

Java, 181155.25(207 * .75) 151.5(202 * .75) bytesclass I{public static void main(String[]a){a:for(long b=new java.util.Scanner(System.in).nextLong(),c,d=1;d++<b;){String...

View Article

Answer by Martin Ender for All about basic binary

Mathematica, 59 bytesPrint/@Select[1+Range[n=Input[]],Max@IntegerDigits[n,#]<2&]Ugh... IntegerDigits D:There isn't really much to explain about the code... 12 bytes are wasted by the requirement...

View Article


Answer by nimi for All about basic binary

Haskell 109*0.75 = 81.75 bytes0#x=[]n#x=n`mod`x:div n x#x f n=[show x++'':(n#x>>=show)|x<-[2..n+1],all(<2)$n#x]p=interact$unlines.f.readUsage example (note: binary values are lsb first):p...

View Article

Answer by Alex A. for All about basic binary

Julia, 72 70 bytesIt'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)endThis reads a line from STDIN, converts it to an...

View Article

Answer by KSab for All about basic binary

Python 2, 88 86 80Fairly straightforward, no bonus. Python is nice and lenient with global variables.N=input();g=lambda n:n<1or(n%b<2)*g(n/b)for b in range(2,N+1): if g(N):print bBest I've...

View Article

Answer by FryAmTheEggman for All about basic binary

Pyth, 14 13jbf!-jQTU2tSQThanks to Jakube for pointing out the new S function.Try it here.The online version is too slow to do 1234321. This simply converts the input to each base from 2 to itself and...

View Article


Answer by Optimizer for All about basic binary

CJam, 20 bytes (or 27 bytes * 0.75 = 20.25)Here is the no bonus version, 20 bytes:ri:X,2f+{X\b2,-!},N*Try this here.Just for fun, here is the bonus version, 27 bytes:ri:X{X\)b2,-!},1>{)SX2$bN}/Try...

View Article


All about basic binary

Please excuse the punny title. This is a question is inspired by A Curious Property of 82000. In it, the author points out that the number 82000 is binary in base 2, 3, 4, and 5. The post then poses...

View Article
Browsing latest articles
Browse All 23 View Live


Latest Images