Generate a cube and its coordinates

The outpus:

list after shuffle: 
[17, 9, 2, 18, 19, 8, 25, 12, 15, 22, 21, 26, 23, 4, 24, 5, 14, 10, 27, 20, 3, 13, 16, 7, 6, 1, 11]
corresponding relationship:
{17: (0, 0, 0), 9: (1, 0, 0), 2: (2, 0, 0), 18: (0, 1, 0), 19: (1, 1, 0), 8: (2, 1, 0), 25: (0, 2, 0), 12: (1, 2, 0), 15: (2, 2, 0), 22: (0, 0, 1), 21: (1, 0, 1), 26: (2, 0, 1), 23: (0, 1, 1), 4: (1, 1, 1), 24: (2, 1, 1), 5: (0, 2, 1), 14: (1, 2, 1), 10: (2, 2, 1), 27: (0, 0, 2), 20: (1, 0, 2), 3: (2, 0, 2), 13: (0, 1, 2), 16: (1, 1, 2), 7: (2, 1, 2), 6: (0, 2, 2), 1: (1, 2, 2), 11: (2, 2, 2)}

The corresponding codes:

import numpy as np
a = []
for _ in range(1,28):
    a.append(_)
np.random.shuffle(a)
print("list after shuffle: ")
print(a)
coordinates = []
for i in range(0,27):
    if (i % 3 == 0):
        x = 0
    elif (i % 3 == 1):
        x = 1
    else:
        x = 2
    if (0 <= (i % 9) <= 2):
        y = 0
    elif (3 <= (i % 9) <= 5):
        y = 1
    else:
        y = 2
    if (0 <= i <= 8):
        z = 0
    elif(9 <= i <= 17):
        z = 1
    else:
        z = 2
    temp_tuple = (x, y , z)
    coordinates.append(temp_tuple)
d = dict(zip(a, coordinates))
print("corresponding relationship:")
print(d)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值