Browse Source

058 buggy

master
Coin de Gamma 10 months ago
parent
commit
6b3fbf7893
  1. 43
      058/main.rs

43
058/main.rs

@ -8,7 +8,7 @@ struct Steps {
i: usize,
j: usize,
k: usize,
s: usize
s: usize,
}
impl Steps {
@ -18,7 +18,7 @@ impl Steps {
j: n / 2,
l: 1,
k: 1,
s: 0,
s: 0
};
}
@ -29,7 +29,8 @@ impl Steps {
if s.j > 0 { self.j += 1; }
}
fn next(&mut self) {
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 });
@ -37,6 +38,7 @@ impl Steps {
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() {
@ -46,42 +48,19 @@ impl Steps {
if self.s == 2 {
self.l += 1;
}
println!("{}", n);
}
let st = &sts[self.s];
self.k += 1;
self.ads(st)
self.ads(st);
}
}
fn print() {
let n = 7usize;
let mut m = Vec::<Vec<u32>>::new();
for i in 0..n {
let mut l = Vec::<u32>::new();
for j in 0..n {
l.push(0);
}
m.push(l);
}
let mut st = Steps::new(n);
for i in 1..20 {
m[st.i][st.j] = i;
st.next();
}
for i in 0..n {
let l = &m[i];
for j in 0..n {
print!("{}\t", l[j]);
}
println!("");
}
}
fn main() {
println!("hello world");
print();
let mut st = Steps::new(7);
for n in 1..20 {
st.next(n);
}
}

Loading…
Cancel
Save