Quantcast
Channel: All about basic binary - Code Golf Stack Exchange
Browsing index pages (26 articles)
↧

Answer by DLosc for All about basic binary

Pip, 13 bytes1=MaTD_FI2\,aAttempt This Online!Explanation1=MaTD_FI2\,a a Command-line argument 2\, Inclusive range from 2 to that number FI Filter by this function: a Command-line argument TD Convert...

View Article


Answer by Rosario for All about basic binary

APL(NARS), 107 chars, 214 bytes, score 214x0.75=160,5{y←⍵⋄⍪{0=≡⍵:⍕⍵⋄k/⍨''≠k←⍕⍵}¨¨1↓{q←1+↑⍵⋄∅=↑r←q{⍵≤0:0⋄2≤k←⍺∣⍵:∅⋄(⍺∇⌊⍵÷⍺),k}y:q,1↓⍵⋄q,(1↓⍵),⊂q,⊂1↓r}⍣{y≤↑⍺},1}Input one integer positive output, one...

View Article


Answer by hakr14 for All about basic binary

Nekomata, 7 bytesRt~ᵖ{DƶAttempt This Online!Explanation:Rt~ᵖ{Dƶ | Full program--------+----------------------------------------Rt | [2...input] ~ | Print each value on a new lineᵖ{ | if D | every digit...

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

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


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 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 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 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 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 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 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 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 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 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 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 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 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 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 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
Browsing index pages (26 articles)


Latest Images