How would you represent a Rubik's Cube in code?

前端 未结 11 1788
清酒与你
清酒与你 2020-12-07 09:52

If you were developing software to solve a Rubik\'s Cube, how would you represent the cube?

11条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 10:06

    There are 20 cubies that matter. So one way to do it is as an array of 20 strings. The strings would hold 2 or 3 characters indicating the colors. Any single move affects 7 of the cubies. So you just need a remapper for each of the six sides.

    Note: This solution doesn't manage to remember the orientation of the logo sticker that's on the white center.

    By the way, I helped someone do a software Rubik's cube once, maybe 15 years ago, but I can't remember how we represented it.

提交回复
热议问题