Pairing algorithm

  • A
  • Thread starter intervoxel
  • Start date
  • #1
191
1

Main Question or Discussion Point

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,576
717
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.
 
  • Like
Likes intervoxel

Related Threads on Pairing algorithm

  • Last Post
Replies
4
Views
3K
  • Last Post
Replies
1
Views
620
  • Last Post
Replies
2
Views
3K
  • Last Post
3
Replies
52
Views
16K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
2
Views
858
  • Last Post
Replies
3
Views
2K
  • Last Post
Replies
4
Views
765
  • Last Post
Replies
3
Views
2K
  • Last Post
Replies
2
Views
2K
Top