我想在perl中实现这个算法
11000, 67676, -7878, 9898
11001, 67676, -7878, 7673
11789, 56565, -0909, 5555
17654, 67676, -7654, 3214
18776, 99999, -55, 4444
17765, 67676, 7878, 9898
scan *nodes
hash1{node}=x,y,z
invert_y=y*-1
chech invert_y existance in hash2
if exists
hash2{y}=[n1,n2,n3...].append the node
else
hash2{y}=store node in a array and pass its reference as value
foreach key in hash1
get x1,y1,z1 of this node1 (eg. hash1{key} will return x,y,z of this node1)
invert_y=y*1
if exists hash2{invert_y}
get all node of hash2{keys} in node_array
foreach node2 in node_array
get x2,y2,z2 of this node2 (eg. hash1{node2} will return x,y,z of this node2)
if x1 of node1 == x2 of node2 && z1 of node1 == z2 of node2
node1 and node2 are symmetric
答案 0 :(得分:2)
我拿了一些你的伪代码,然后对它进行了彻底的启动。
hash1{node}=x,y,z
# value in hash is a reference to a 3-element array
$hash1{$node} = [ $x, $y, $z ];
foreach key in hash1
foreach my $k (keys %hash1)
get x1,y1,z1 of this node1 (eg. hash1{key} will return x,y,z of this node1)
$node1 = $hash1{$k};
invert_y=y*1
I have no idea what you mean here
if exists hash2{invert_y}
if (exists $hash2{$invert_y}
get all node of hash2{keys} in node_array
eh?
foreach node2 in node_array
foreach $node2 (@node_array)
get x2,y2,z2 of this node2 (eg. hash1{node2} will return x,y,z of this node2)
$node2 = $hash1{$node2};
if x1 of node1 == x2 of node2 && z1 of node1 == z2 of node2
node1 and node2 are symmetric
# x is element 0, y is 1 and z is 2
if ($node1->[0] == $node2->[0] &&
$node1->[2] == $node2->[2])