use std::io::{self, Read}; fn read_stdin() -> Vec { let mut buffer = String::new(); io::stdin().read_to_string(&mut buffer).ok(); buffer.trim().split('\n').map(|s| s.to_string()).collect() } fn calc_primes(n: usize) -> Vec { let mut search_list = (2..n + 1).collect::>(); let mut prime_list: Vec = Vec::new(); while (search_list[0] as f64) < (n as f64).sqrt() { let head = search_list[0]; prime_list.push(head); search_list = search_list.into_iter().filter(|x| *x % head > 0).collect::>(); } prime_list.append(&mut search_list); prime_list } #[derive(Debug, Eq, PartialEq)] enum RunResult { Win, Lose, } impl RunResult { fn s(&self) -> String { match self { Self::Win => "Win", Self::Lose => "Lose", }.to_string() } } fn run(n: usize) -> RunResult { if (2..n + 1) .into_iter() .fold(vec![2, 3], |mut acc, e| { if calc_primes(n) .clone() .into_iter() .take_while(|p| &e > &(*p + 1)) .filter(|p| acc.contains(&(&e - *p))) .peekable() .peek() .is_none() && !acc.contains(&e) { acc.push(e); } acc }) .contains(&n) { RunResult::Lose } else { RunResult::Win } } fn main() { let n = read_stdin()[0].parse::().unwrap(); let result = run(n); println!("{}", result.s()); } #[cfg(test)] mod tests { use super::{calc_primes, run, RunResult}; #[test] fn test_calc_primes() { assert_eq!(calc_primes(11), vec![2, 3, 5, 7, 11]); assert_eq!(calc_primes(10), vec![2, 3, 5, 7]); assert_eq!(calc_primes(2), vec![2]); } #[test] fn test_run_lose() { let loses = [2, 3, 11, 12]; for i in loses.iter() { println!("test num: {}", i); assert_eq!(run(*i), RunResult::Lose); } } #[test] fn test_run_win() { let wins = [4, 5, 6, 7, 8, 9, 10, 13]; for i in wins.iter() { println!("test num: {}", i); assert_eq!(run(*i), RunResult::Win); } } }