C++ Generate and store the co-ordinates of an n-cube
I want to write a function to generate and store the co-ordinates of an n-cube and I have no idea how to start. Specifically, I wish to generate the co-ordinates for开发者_如何学Go an evenly or randomly distributed cloud of points for this n-cube and store them. What would be a good way to start with this or if possible, a quick solution?
I don't want to give C++ source code for this problem, however, here's the thought how you could generate it.
A hypercube contains all bit-strings of length n
. Thus there are 2^n
possibilities for coordinates in total.
Now how you can do it recursively:
if you want to generate coordinates for
n=1
, just return0
and1
if you want to generate coordinates for
n>1
, take0
and concatenate it to all possible coordinates forn'=n-1
, then take1
and concatenate it to all possible coordinates forn'=n-1
精彩评论