A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

New answers tagged

0

TI-BASIC, 26 bytes Input A:{0:For(I,1,A:2Ans:augment(Ans,1+Ans:End:Ans Prompts the user to input n. Outputs the bit-reversal permutation as is specified in the challenge. Explanation: Input A ;prompt the user for "n". store the input into A {0 ;leave {0} in Ans For(I,1,A ;loop A times 2Ans ...


1

GolfScript, 2 bytes ~= Try it online! Explanation ~ # Dump the input onto the stack = # Index


1

Python 3, 207 bytes def s(n): p=1 while n>=2*p: p*=2 return n if n<=p else s(n+p//2)if n>=3*p/2 else s(m)if (m:=s(n-p)+p)!= n else n a=lambda n,m:(b:=n&m)>-1 and s(a(a(a(s((n|m)-b%4),b//4*2),b//4),b%4*2+b%4//2))if m else n Try it Online! (Verify all test cases) Explanation This program directly manipulates the binary translations of ...


0

Go, 145 bytes A function literal which prints to STDOUT. Abuses Sprintf heavily. import ."fmt" func(n int){s:=Sprintf n++ for i:=0;i<n*n;i++{Printf(s(" %%%dd",len(s("%d",1<<len(s("%b",n-1))-1))),i/n^i%n) if-^i%n<1{Println()}}} Try it online! - it appears the Go installation on TIO is older than on my machine, this code runs perfectly locally: ...


0

APL, 20 bytes {2⊥¨∘.≠⍨↓⍉2⊥⍣¯1⍳⍵+1} Explanation: ⍳⍵+1 integers from 0 to n 2⊥⍣¯1 base 2 encoding ↓⍉ create nested of boolean vectors ∘.≠⍨ xor matrix 2⊥¨ base 2 to base 10 conversion


Top 50 recent answers are included