Compare commits
2 Commits
2d6a15510e
...
5bee972d2f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5bee972d2f | ||
|
|
4b643ed750 |
@@ -4,8 +4,6 @@ use std::fs::File;
|
||||
use std::io::{BufReader, prelude::*};
|
||||
use std::num;
|
||||
|
||||
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Crossword {
|
||||
data: Vec<Vec<char>>,
|
||||
@@ -24,10 +22,9 @@ impl<'a> WordPuller<'a> {
|
||||
pub fn take(&self, num_of_letters: usize) -> String {
|
||||
let mut word = String::new();
|
||||
|
||||
|
||||
for i in 0..num_of_letters {
|
||||
let x= self.x as isize + (i as isize * self.direction.0);
|
||||
let y= self.y as isize + (i as isize * self.direction.1);
|
||||
let x = self.x as isize + (i as isize * self.direction.0);
|
||||
let y = self.y as isize + (i as isize * self.direction.1);
|
||||
word.push(self.crossword.data[x as usize][y as usize]);
|
||||
}
|
||||
|
||||
@@ -70,14 +67,70 @@ impl Crossword {
|
||||
self.height
|
||||
}
|
||||
|
||||
pub fn n(&self, x: usize, y: usize) -> WordPuller { WordPuller {x, y, direction:(-1, 0), crossword: self}}
|
||||
pub fn ne(&self, x: usize, y: usize) -> WordPuller { WordPuller {x, y, direction:(-1, 1), crossword: self}}
|
||||
pub fn e(&self, x: usize, y: usize) -> WordPuller { WordPuller {x, y, direction:(0, 1), crossword: self}}
|
||||
pub fn se(&self, x: usize, y: usize) -> WordPuller { WordPuller {x, y, direction:(1, 1), crossword: self}}
|
||||
pub fn s(&self, x: usize, y: usize) -> WordPuller { WordPuller {x, y, direction:(1, 0), crossword: self}}
|
||||
pub fn sw(&self, x: usize, y: usize) -> WordPuller { WordPuller {x, y, direction:(1, -1), crossword: self}}
|
||||
pub fn w(&self, x: usize, y: usize) -> WordPuller { WordPuller {x, y, direction:(0, -1), crossword: self}}
|
||||
pub fn nw(&self, x: usize, y: usize) -> WordPuller { WordPuller {x, y, direction:(-1, -1), crossword: self}}
|
||||
pub fn n(&self, x: usize, y: usize) -> WordPuller {
|
||||
WordPuller {
|
||||
x,
|
||||
y,
|
||||
direction: (-1, 0),
|
||||
crossword: self,
|
||||
}
|
||||
}
|
||||
pub fn ne(&self, x: usize, y: usize) -> WordPuller {
|
||||
WordPuller {
|
||||
x,
|
||||
y,
|
||||
direction: (-1, 1),
|
||||
crossword: self,
|
||||
}
|
||||
}
|
||||
pub fn e(&self, x: usize, y: usize) -> WordPuller {
|
||||
WordPuller {
|
||||
x,
|
||||
y,
|
||||
direction: (0, 1),
|
||||
crossword: self,
|
||||
}
|
||||
}
|
||||
pub fn se(&self, x: usize, y: usize) -> WordPuller {
|
||||
WordPuller {
|
||||
x,
|
||||
y,
|
||||
direction: (1, 1),
|
||||
crossword: self,
|
||||
}
|
||||
}
|
||||
pub fn s(&self, x: usize, y: usize) -> WordPuller {
|
||||
WordPuller {
|
||||
x,
|
||||
y,
|
||||
direction: (1, 0),
|
||||
crossword: self,
|
||||
}
|
||||
}
|
||||
pub fn sw(&self, x: usize, y: usize) -> WordPuller {
|
||||
WordPuller {
|
||||
x,
|
||||
y,
|
||||
direction: (1, -1),
|
||||
crossword: self,
|
||||
}
|
||||
}
|
||||
pub fn w(&self, x: usize, y: usize) -> WordPuller {
|
||||
WordPuller {
|
||||
x,
|
||||
y,
|
||||
direction: (0, -1),
|
||||
crossword: self,
|
||||
}
|
||||
}
|
||||
pub fn nw(&self, x: usize, y: usize) -> WordPuller {
|
||||
WordPuller {
|
||||
x,
|
||||
y,
|
||||
direction: (-1, -1),
|
||||
crossword: self,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Crossword {
|
||||
|
||||
@@ -24,14 +24,14 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
let crossword = Crossword::new(File::open(input_file_string)?)?;
|
||||
|
||||
println!("{}", crossword);
|
||||
println!("n: {}", crossword.n(3,3).take(4));
|
||||
println!("ne: {}", crossword.ne(3,3).take(4));
|
||||
println!("e: {}", crossword.e(3,3).take(4));
|
||||
println!("se: {}", crossword.se(3,3).take(4));
|
||||
println!("s: {}", crossword.s(3,3).take(4));
|
||||
println!("sw: {}", crossword.sw(3,3).take(4));
|
||||
println!("w: {}", crossword.w(3,3).take(4));
|
||||
println!("nw: {}", crossword.nw(3,3).take(4));
|
||||
println!("n: {}", crossword.n(3, 3).take(4));
|
||||
println!("ne: {}", crossword.ne(3, 3).take(4));
|
||||
println!("e: {}", crossword.e(3, 3).take(4));
|
||||
println!("se: {}", crossword.se(3, 3).take(4));
|
||||
println!("s: {}", crossword.s(3, 3).take(4));
|
||||
println!("sw: {}", crossword.sw(3, 3).take(4));
|
||||
println!("w: {}", crossword.w(3, 3).take(4));
|
||||
println!("nw: {}", crossword.nw(3, 3).take(4));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user