This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Gray codes  RSS feed

 
Donatas Latauskas
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody show me the way how to generate next "n" Gray codes, from the given one ?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume you mean this???
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm curious what you're using them for. My only exposure was building Karnaugh maps which can be used to reduce a set of predicates to their minimal form, eliminating redundant logic tests. I don't even know if taht makes sense. Here are some class notes from tenty some years ago ...

The numbers in the boxes are the decimal value of a set of bits made up of the predicates. The order is the "Gray Code" which changes by one bit from one box to another in any direction. Note that the top and bottom edges are "adjacent", as are the right and left edges. For example, in the 4-variable map only one bit changes when moving from box 2 to box 0, or from box 2 to box A.

For each combination of predicates, if the result is true shade in the box. Also shade in "don't care" boxes; combinations which cannot happen, or for which the result is ignored.

If there are two adjacent shaded boxes, you can ignore the predicate which changes and test only the predicate(s) which do not. For four adjacent boxes ignore the two predicates which change, and for eight adjacent boxes ignore the three predicates which change.

Create an "if test" for each contiguous group of boxes, and "or" those tests together for the final result.
 
Donatas Latauskas
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!