Post Reply 
(48G/49/50) Gray Codes
04-10-2021, 09:04 PM
Post: #1
(48G/49/50) Gray Codes
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 *.

Code:

\<< # 10b { # 0b # 1b } ROT 2 SWAP
  START DUP2 ADD REVLIST + SWAP SL SWAP
  NEXT SWAP DROP
\>>
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)