From 288d56538361853c4b513aba1dd41a175f4c7e42 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 10 Jan 2022 10:56:48 -0800 Subject: [PATCH 1/2] Add more traits --- src/traits.rs | 28 ++++++++++++++++++++++++++++ tests/traits.rs | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/src/traits.rs b/src/traits.rs index df2c682e90..16950bea90 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -15,5 +15,33 @@ pub(crate) fn run(n: u64) -> Result { println!("odd"); } + let pi = std::f64::consts::PI.to_string().replace('.', ""); + let s = n.to_string(); + if s == pi[..s.len()] { + println!("pi"); + } + + if s.replace("69", "") == "" { + println!("nice"); + } + + if s.replace("7", "") == "" { + println!("angelic"); + } + + let mut name = String::new(); + let mut remainder = n; + while remainder > 0 { + name.push( + "abcdefghijklmnopqrstuvwxyz" + .chars() + .skip(((remainder - 1) % 26) as usize) + .next() + .unwrap(), + ); + remainder = (remainder - 1) / 26; + } + println!("name:{}", name.chars().rev().collect::()); + Ok(()) } diff --git a/tests/traits.rs b/tests/traits.rs index 6bac799591..97b9d210e1 100644 --- a/tests/traits.rs +++ b/tests/traits.rs @@ -42,3 +42,42 @@ fn odd() -> Result { assert!(!traits(2)?.contains("odd")); Ok(()) } + +#[test] +fn pi() -> Result { + assert!(!traits(0)?.contains("pi")); + assert!(traits(3)?.contains("pi")); + assert!(traits(31)?.contains("pi")); + assert!(traits(314)?.contains("pi")); + assert!(!traits(3145)?.contains("pi")); + Ok(()) +} + +#[test] +fn nice() -> Result { + assert!(!traits(0)?.contains("nice")); + assert!(traits(69)?.contains("nice")); + assert!(traits(6969)?.contains("nice")); + assert!(traits(696969)?.contains("nice")); + assert!(!traits(696968)?.contains("nice")); + Ok(()) +} + +#[test] +fn divine() -> Result { + assert!(!traits(0)?.contains("angelic")); + assert!(traits(7)?.contains("angelic")); + assert!(traits(77)?.contains("angelic")); + assert!(traits(777)?.contains("angelic")); + assert!(!traits(778)?.contains("angelic")); + Ok(()) +} + +#[test] +fn name() -> Result { + assert!(traits(0)?.contains("name:")); + assert!(traits(1)?.contains("name:a")); + assert!(traits(26)?.contains("name:z")); + assert!(traits(27)?.contains("name:aa")); + Ok(()) +} From 9030f0d53ed0479ffef87be3a6577c30f60d508d Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 10 Jan 2022 11:07:12 -0800 Subject: [PATCH 2/2] placate clippy --- src/traits.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/traits.rs b/src/traits.rs index 16950bea90..e86cc622d6 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -35,8 +35,7 @@ pub(crate) fn run(n: u64) -> Result { name.push( "abcdefghijklmnopqrstuvwxyz" .chars() - .skip(((remainder - 1) % 26) as usize) - .next() + .nth(((remainder - 1) % 26) as usize) .unwrap(), ); remainder = (remainder - 1) / 26;