04-10-2021, 09:04 PM
This program returns a list of binary Gray codes from 0 to 2^n-1. For example, given the number 4 the program will return a list of Gray codes from 0 to 15.
If real numbers are desired instead of binary numbers, replace the binary numbers in line 1 with reals, and replace the SL in line 2 with 2 *.
If real numbers are desired instead of binary numbers, replace the binary numbers in line 1 with reals, and replace the SL in line 2 with 2 *.
Code:
\<< # 10b { # 0b # 1b } ROT 2 SWAP
START DUP2 ADD REVLIST + SWAP SL SWAP
NEXT SWAP DROP
\>>