1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![allow(clippy::derive_hash_xor_eq)]
12
13 #[cfg(feature = "use_core")]
14 extern crate core;
15
16 use std::collections::HashSet;
17
18 #[macro_use]
19 extern crate derivative;
20
21 #[derive(Derivative)]
22 #[derivative(Hash)]
23 #[derive(Copy, Clone, PartialEq, Eq)]
24 struct XYZ {
25 x: isize,
26 y: isize,
27 z: isize
28 }
29
30 #[test]
main()31 fn main() {
32 let mut connected = HashSet::new();
33 let mut border = HashSet::new();
34
35 let middle = XYZ{x: 0, y: 0, z: 0};
36 border.insert(middle);
37
38 while !border.is_empty() && connected.len() < 10000 {
39 let choice = *(border.iter().next().unwrap());
40 border.remove(&choice);
41 connected.insert(choice);
42
43 let cxp = XYZ{x: choice.x + 1, y: choice.y, z: choice.z};
44 let cxm = XYZ{x: choice.x - 1, y: choice.y, z: choice.z};
45 let cyp = XYZ{x: choice.x, y: choice.y + 1, z: choice.z};
46 let cym = XYZ{x: choice.x, y: choice.y - 1, z: choice.z};
47 let czp = XYZ{x: choice.x, y: choice.y, z: choice.z + 1};
48 let czm = XYZ{x: choice.x, y: choice.y, z: choice.z - 1};
49
50 if !connected.contains(&cxp) {
51 border.insert(cxp);
52 }
53 if !connected.contains(&cxm){
54 border.insert(cxm);
55 }
56 if !connected.contains(&cyp){
57 border.insert(cyp);
58 }
59 if !connected.contains(&cym) {
60 border.insert(cym);
61 }
62 if !connected.contains(&czp){
63 border.insert(czp);
64 }
65 if !connected.contains(&czm) {
66 border.insert(czm);
67 }
68 }
69 }
70