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 #[cfg(feature = "use_core")]
12 extern crate core;
13
14 use std::collections::HashSet;
15
16 #[macro_use]
17 extern crate derivative;
18
19 #[derive(Derivative)]
20 #[derivative(Hash)]
21 #[derive(Copy, Clone, PartialEq, Eq)]
22 struct XYZ {
23 x: isize,
24 y: isize,
25 z: isize
26 }
27
28 #[test]
main()29 fn main() {
30 let mut connected = HashSet::new();
31 let mut border = HashSet::new();
32
33 let middle = XYZ{x: 0, y: 0, z: 0};
34 border.insert(middle);
35
36 while !border.is_empty() && connected.len() < 10000 {
37 let choice = *(border.iter().next().unwrap());
38 border.remove(&choice);
39 connected.insert(choice);
40
41 let cxp = XYZ{x: choice.x + 1, y: choice.y, z: choice.z};
42 let cxm = XYZ{x: choice.x - 1, y: choice.y, z: choice.z};
43 let cyp = XYZ{x: choice.x, y: choice.y + 1, z: choice.z};
44 let cym = XYZ{x: choice.x, y: choice.y - 1, z: choice.z};
45 let czp = XYZ{x: choice.x, y: choice.y, z: choice.z + 1};
46 let czm = XYZ{x: choice.x, y: choice.y, z: choice.z - 1};
47
48 if !connected.contains(&cxp) {
49 border.insert(cxp);
50 }
51 if !connected.contains(&cxm){
52 border.insert(cxm);
53 }
54 if !connected.contains(&cyp){
55 border.insert(cyp);
56 }
57 if !connected.contains(&cym) {
58 border.insert(cym);
59 }
60 if !connected.contains(&czp){
61 border.insert(czp);
62 }
63 if !connected.contains(&czm) {
64 border.insert(czm);
65 }
66 }
67 }
68