29: Improve solution for Rust track exercise "Nth Prime".

[?]
Aaw9nJhsNmfzFih9mKyNw9mV8CgERXJkRa1kK1Kx3LQH
Sep 2, 2021, 9:09 AM
IXMBS6ZPQSFG6HTYGHNJJ3YK2KYGUBBNTMIU7Q5CAKLJEXSBP4EAC

Dependencies

  • [2] EUWYCVLU 17: Improve solution for Rust track exercise "Nth Prime".
  • [3] KWE5K6XL 23: Fix panix on input `12` for solution for Rust track exercise "Nth Prime".
  • [4] UTP7D53Q 12: Improve solution for Rust track exercise "Nth Prime".
  • [5] ERYD4CD7 11: Add solution for Rust track exercise "Nth Prime".
  • [*] JZN2AQ3E 10: Add Rust track exercise "nth-prime".

Change contents

  • edit in rust/nth-prime/src/lib.rs at line 6
    [4.545]
    [3.0]
    * Skips even numbers.
  • replacement in rust/nth-prime/src/lib.rs at line 28
    [4.1200][4.1200:1205]()
    0,
    [4.1200]
    [4.1205]
    1,
  • replacement in rust/nth-prime/src/lib.rs at line 31
    [4.1210][4.0:25]()
    for index in 2..limit {
    [4.1210]
    [4.1239]
    (2_usize.pow(2)..list_size).step_by(2).for_each(|multiple| {
    list[multiple] = false;
    });
    for index in (3..limit).step_by(2) {
  • edit in rust/nth-prime/src/lib.rs at line 41
    [4.1394][4.1394:1399](),[4.1399][2.0:91]()
    }
    for multiple in (index * index..list_size).step_by(index) {
    list[multiple] = false;
  • edit in rust/nth-prime/src/lib.rs at line 42
    [4.31]
    [4.31]
    (index.pow(2)..list_size)
    .step_by(index)
    .for_each(|multiple| {
    list[multiple] = false;
    });
  • replacement in rust/nth-prime/src/lib.rs at line 50
    [4.39][4.39:91]()
    for index in limit..list_size {
    if list[index] {
    [4.39]
    [4.91]
    if limit & 1 == 1 {
    for index in (limit..list_size).step_by(2) {
    if list[index] {
    count += 1;
    if count > n {
    // Might return incorrect value if values greater than u32::MAX are cast.
    return index as u32;
    }
    }
    }
    } else {
    if list[limit] {
  • replacement in rust/nth-prime/src/lib.rs at line 65
    [4.202][4.202:227]()
    return index as u32;
    [4.202]
    [4.1520]
    return limit as u32;
    }
    }
    for index in ((limit + 1)..list_size).step_by(2) {
    if list[index] {
    count += 1;
    if count > n {
    // Might return incorrect value if values greater than u32::MAX are cast.
    return index as u32;
    }