Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let mut x = 1;
- let mut y = 2;
- let mut solution = 0;
- let moves = [[1, 2], [2, 1], [2, -1], [1, -2], [-1, -2], [-2, -1], [-2, 1], [-1, 2]];
- for k in 0..8 {
- let mov = moves[k];
- match (x + mov[0], y + mov[1]) {
- (0...7, 0...7) => solution += 1,
- _ => ()
- }
- }
- println!("If knight is on x = {}, y = {}, then it attacks {} fields.",
- x + 1, y + 1, solution);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement