开发者

C++ Generate and store the co-ordinates of an n-cube

开发者 https://www.devze.com 2023-01-03 18:56 出处:网络
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 random

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 return 0 and 1

  • if you want to generate coordinates for n>1, take 0 and concatenate it to all possible coordinates for n'=n-1, then take 1 and concatenate it to all possible coordinates for n'=n-1

0

精彩评论

暂无评论...
验证码 换一张
取 消