Skip to content

2017 primality test performance improvement #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/year2017/day23.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
//! [`Day 18`]: crate::year2017::day18
use crate::util::parse::*;

/// We only need the vrey first number from the input.
/// We only need the very first number from the input.
pub fn parse(input: &str) -> u32 {
input.unsigned()
}
Expand All @@ -69,7 +69,10 @@ pub fn part2(input: &u32) -> usize {
/// Simple [prime number check](https://en.wikipedia.org/wiki/Primality_test)
/// of all factors from 2 to √n inclusive.
fn composite(n: u32) -> Option<u32> {
for f in 2..=n.isqrt() {
if n % 2 == 0 {
return Some(n);
};
for f in (3..).step_by(2).take_while(|m| m * m <= n) {
if n % f == 0 {
return Some(n);
}
Expand Down
Loading