Pairing algorithm

  • A
  • Thread starter intervoxel
  • Start date
  • #1
195
1
Suppose an array of booleans with an even number of true values. I need an algorithm that, given an address containing a true (say, 3), returns the address of another true (say, 25), such that if I call the algorithm for 25, it returns 3. No storage of old choices are allowed since this algorithm will be used in a cellular automaton.

Thanks for any help.
 

Answers and Replies

  • #2
Merlin3189
Homework Helper
Gold Member
1,665
776
If you know, or count, the number of true values, call it N, then if the function returns the address of the N/2 th true value after the starting value counting cyclically, then each true value will pair with a true value the same number of places above and below.
 

Related Threads on Pairing algorithm

  • Last Post
Replies
1
Views
712
  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
4
Views
857
  • Last Post
Replies
3
Views
231
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
16
Views
2K
  • Last Post
Replies
2
Views
2K
  • Last Post
2
Replies
26
Views
19K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
0
Views
1K
Top