Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.46 KB | None | 0 0
  1.     let mut x = 1;
  2.     let mut y = 2;
  3.    
  4.     let mut solution = 0;
  5.    
  6.     let moves = [[1, 2], [2, 1], [2, -1], [1, -2], [-1, -2], [-2, -1], [-2, 1], [-1, 2]];
  7.    
  8.     for k in 0..8 {
  9.         let mov = moves[k];
  10.        
  11.         match (x + mov[0], y + mov[1]) {
  12.             (0...7, 0...7) => solution += 1,
  13.             _ => ()
  14.         }
  15.     }
  16.     println!("If knight is on x = {}, y = {}, then it attacks {} fields.",
  17.         x + 1, y + 1, solution);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement