You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
struct Step {
|
|
|
|
i: i8,
|
|
|
|
j: i8
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Steps {
|
|
|
|
l: usize,
|
|
|
|
i: usize,
|
|
|
|
j: usize,
|
|
|
|
k: usize,
|
|
|
|
s: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Steps {
|
|
|
|
fn new(n: usize) -> Steps {
|
|
|
|
return Steps {
|
|
|
|
i: n / 2,
|
|
|
|
j: n / 2,
|
|
|
|
l: 1,
|
|
|
|
k: 1,
|
|
|
|
s: 0
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
fn ads(&mut self, s: &Step) {
|
|
|
|
if s.i < 0 { self.i -= 1; }
|
|
|
|
if s.i > 0 { self.i += 1; }
|
|
|
|
if s.j < 0 { self.j -= 1; }
|
|
|
|
if s.j > 0 { self.j += 1; }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn next(&mut self, n: u32) {
|
|
|
|
//self.corner = false;
|
|
|
|
let mut sts = Vec::new();
|
|
|
|
sts.push(Step { i: 0, j: 1 });
|
|
|
|
sts.push(Step { i: -1, j: 0 });
|
|
|
|
sts.push(Step { i: 0, j: -1 });
|
|
|
|
sts.push(Step { i: 1, j: 0 });
|
|
|
|
|
|
|
|
if self.k > self.l {
|
|
|
|
//self.corner = true;
|
|
|
|
self.k = 1;
|
|
|
|
self.s += 1;
|
|
|
|
if self.s == sts.len() {
|
|
|
|
self.s = 0;
|
|
|
|
self.l += 1;
|
|
|
|
}
|
|
|
|
if self.s == 2 {
|
|
|
|
self.l += 1;
|
|
|
|
}
|
|
|
|
println!("{}", n);
|
|
|
|
}
|
|
|
|
|
|
|
|
let st = &sts[self.s];
|
|
|
|
self.k += 1;
|
|
|
|
self.ads(st);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let mut st = Steps::new(7);
|
|
|
|
for n in 1..20 {
|
|
|
|
st.next(n);
|
|
|
|
}
|
|
|
|
}
|