Skip to content

Commit

Permalink
Minor optimizations of 35 + mark slow
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Aug 29, 2024
1 parent 17ee019 commit 5328b90
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Problems Solved
+-----------+------------+------------+------------+------------+------------+------------+------------+
|:prob:`34` |:c-d:`0034` |:cp-d:`0034`|:cs-d:`0034`|:ja-d:`0034`|:js-d:`0034`|:py-d:`0034`|:rs-d:`0034`|
+-----------+------------+------------+------------+------------+------------+------------+------------+
|:prob:`35` | | | | |:js-d:`0035`|:py-d:`0035`|:rs-d:`0035`|
|:prob:`35` | | | | |:js-d:`0035`|:py-d:`0035`|:rs-s:`0035`|
+-----------+------------+------------+------------+------------+------------+------------+------------+
|:prob:`36` | | | | | |:py-d:`0036`|:rs-d:`0036`|
+-----------+------------+------------+------------+------------+------------+------------+------------+
Expand Down
2 changes: 1 addition & 1 deletion rust/src/include/problems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ seq!(N in 0001..=0020 {
24 => Some(( &24, p0024, false)),
27 => Some(( &27, p0027, true)),
34 => Some(( &34, p0034, false)),
35 => Some(( &35, p0035, false)),
35 => Some(( &35, p0035, true)),
36 => Some(( &36, p0036, false)),
37 => Some(( &37, p0037, true)),
41 => Some(( &41, p0041, false)),
Expand Down
14 changes: 10 additions & 4 deletions rust/src/p0035.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::include::primes::is_prime;
use crate::include::utils::Answer;

pub fn p0035() -> Answer {
let mut answer: u64 = 0;
let mut answer: u32 = 0;
for x in 0..1000000 {
if Rotations::new(x).all(is_prime) {
answer += 1;
Expand All @@ -27,23 +27,29 @@ pub fn p0035() -> Answer {
struct Rotations {
x: String,
i: usize,
n: u32,
}

impl Rotations {
pub fn new(x: u64) -> Self {
pub fn new(x: u32) -> Self {
return Rotations{
x: x.to_string(),
i: 0,
n: x,
};
}
}

impl Iterator for Rotations {
type Item = u64;
type Item = u32;

fn next(&mut self) -> Option<Self::Item> {
if self.i == 0 {
self.i += 1;
return Some(self.n);
}
if self.i < self.x.len() {
let result = (self.x[self.i..].to_owned() + &self.x[..self.i]).parse::<u64>().unwrap();
let result = format!("{}{}", &self.x[self.i..], &self.x[..self.i]).parse::<u32>().unwrap();
self.i += 1;
return Some(result);
}
Expand Down

0 comments on commit 5328b90

Please sign in to comment.