Pure Programmer
Blue Matrix


Cluster Map

Project: Renard Numbers (Preferred Numbers)

Write a program that computes the Renard (Preferred) Numbers between 1 and 1000. The user should be allowed to specify the series R5, R10, R20 or R40 on the command line by passing a single argument of 5, 10, 20 or 40. This argument specifies how many divisions should be made in the interval 1 to 10. These preferred numbers are computed as a geometric series using a factor of the 5th, 10th, 20th or 40th root of 10. Preferred numbers in the range 10-100, and 100-1000 are computed by multiplying the values in the range 1-10 by factors of 10 and 100 respectively. By computing the values in the range 1-10 and storing them in an array makes it easy to compute the values in the other ranges.

The perfect numbers are typically rounded to a small number of decimal places. You can use formatted output to round the values on output to the desired number of decimal places. The user should be allowed to specify on the command line a second argument that dictates the number of decimal places to round on output.

See [[Renard Numbers]]

Output
$ rustc RenardNumbers1.rs error[E0425]: cannot find value `args` in this scope --> RenardNumbers1.rs:10:5 | 10 | if args.len() != 3 { | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find function `exit` in this scope --> RenardNumbers1.rs:12:3 | 12 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::process::exit; | error[E0425]: cannot find value `Utils` in this scope --> RenardNumbers1.rs:14:25 | 14 | let mut series:isize = Utils.stoiWithDefault(args[1], 5); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> RenardNumbers1.rs:14:47 | 14 | let mut series:isize = Utils.stoiWithDefault(args[1], 5); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find value `Utils` in this scope --> RenardNumbers1.rs:15:28 | 15 | let mut precision:isize = Utils.stoiWithDefault(args[2], 2); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> RenardNumbers1.rs:15:50 | 15 | let mut precision:isize = Utils.stoiWithDefault(args[2], 2); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | warning: unnecessary parentheses around `if` condition --> RenardNumbers1.rs:51:9 | 51 | if (!first) { | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 51 - if (!first) { 51 + if !first { | error[E0425]: cannot find function `pow` in this scope --> RenardNumbers1.rs:31:23 | 31 | let mut factor:f64 = pow(10.0f64,1.0f64 / f64::from(series)); | ^^^ not found in this scope error[E0277]: the type `[f64]` cannot be indexed by `isize` --> RenardNumbers1.rs:36:37 | 36 | renardNumbers.push(renardNumbers[i - 1] * factor); | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[f64]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<f64>` to implement `Index<isize>` error[E0277]: the type `[f64]` cannot be indexed by `isize` --> RenardNumbers1.rs:54:62 | 54 | print!("{}", sprintf(formatStr[precision],renardNumbers[i] * (rangeStart) as f64)); | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[f64]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<f64>` to implement `Index<isize>` error[E0425]: cannot find function `sprintf` in this scope --> RenardNumbers1.rs:54:19 | 54 | print!("{}", sprintf(formatStr[precision],renardNumbers[i] * (rangeStart) as f64)); | ^^^^^^^ not found in this scope error: aborting due to 10 previous errors; 1 warning emitted Some errors have detailed explanations: E0277, E0425. For more information about an error, try `rustc --explain E0277`. $ rustc RenardNumbers1.rs error[E0425]: cannot find value `args` in this scope --> RenardNumbers1.rs:10:5 | 10 | if args.len() != 3 { | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find function `exit` in this scope --> RenardNumbers1.rs:12:3 | 12 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::process::exit; | error[E0425]: cannot find value `Utils` in this scope --> RenardNumbers1.rs:14:25 | 14 | let mut series:isize = Utils.stoiWithDefault(args[1], 5); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> RenardNumbers1.rs:14:47 | 14 | let mut series:isize = Utils.stoiWithDefault(args[1], 5); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find value `Utils` in this scope --> RenardNumbers1.rs:15:28 | 15 | let mut precision:isize = Utils.stoiWithDefault(args[2], 2); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> RenardNumbers1.rs:15:50 | 15 | let mut precision:isize = Utils.stoiWithDefault(args[2], 2); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | warning: unnecessary parentheses around `if` condition --> RenardNumbers1.rs:51:9 | 51 | if (!first) { | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 51 - if (!first) { 51 + if !first { | error[E0425]: cannot find function `pow` in this scope --> RenardNumbers1.rs:31:23 | 31 | let mut factor:f64 = pow(10.0f64,1.0f64 / f64::from(series)); | ^^^ not found in this scope error[E0277]: the type `[f64]` cannot be indexed by `isize` --> RenardNumbers1.rs:36:37 | 36 | renardNumbers.push(renardNumbers[i - 1] * factor); | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[f64]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<f64>` to implement `Index<isize>` error[E0277]: the type `[f64]` cannot be indexed by `isize` --> RenardNumbers1.rs:54:62 | 54 | print!("{}", sprintf(formatStr[precision],renardNumbers[i] * (rangeStart) as f64)); | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[f64]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<f64>` to implement `Index<isize>` error[E0425]: cannot find function `sprintf` in this scope --> RenardNumbers1.rs:54:19 | 54 | print!("{}", sprintf(formatStr[precision],renardNumbers[i] * (rangeStart) as f64)); | ^^^^^^^ not found in this scope error: aborting due to 10 previous errors; 1 warning emitted Some errors have detailed explanations: E0277, E0425. For more information about an error, try `rustc --explain E0277`. $ rustc RenardNumbers1.rs error[E0425]: cannot find value `args` in this scope --> RenardNumbers1.rs:10:5 | 10 | if args.len() != 3 { | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find function `exit` in this scope --> RenardNumbers1.rs:12:3 | 12 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::process::exit; | error[E0425]: cannot find value `Utils` in this scope --> RenardNumbers1.rs:14:25 | 14 | let mut series:isize = Utils.stoiWithDefault(args[1], 5); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> RenardNumbers1.rs:14:47 | 14 | let mut series:isize = Utils.stoiWithDefault(args[1], 5); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find value `Utils` in this scope --> RenardNumbers1.rs:15:28 | 15 | let mut precision:isize = Utils.stoiWithDefault(args[2], 2); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> RenardNumbers1.rs:15:50 | 15 | let mut precision:isize = Utils.stoiWithDefault(args[2], 2); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | warning: unnecessary parentheses around `if` condition --> RenardNumbers1.rs:51:9 | 51 | if (!first) { | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 51 - if (!first) { 51 + if !first { | error[E0425]: cannot find function `pow` in this scope --> RenardNumbers1.rs:31:23 | 31 | let mut factor:f64 = pow(10.0f64,1.0f64 / f64::from(series)); | ^^^ not found in this scope error[E0277]: the type `[f64]` cannot be indexed by `isize` --> RenardNumbers1.rs:36:37 | 36 | renardNumbers.push(renardNumbers[i - 1] * factor); | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[f64]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<f64>` to implement `Index<isize>` error[E0277]: the type `[f64]` cannot be indexed by `isize` --> RenardNumbers1.rs:54:62 | 54 | print!("{}", sprintf(formatStr[precision],renardNumbers[i] * (rangeStart) as f64)); | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[f64]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<f64>` to implement `Index<isize>` error[E0425]: cannot find function `sprintf` in this scope --> RenardNumbers1.rs:54:19 | 54 | print!("{}", sprintf(formatStr[precision],renardNumbers[i] * (rangeStart) as f64)); | ^^^^^^^ not found in this scope error: aborting due to 10 previous errors; 1 warning emitted Some errors have detailed explanations: E0277, E0425. For more information about an error, try `rustc --explain E0277`. $ rustc RenardNumbers1.rs error[E0425]: cannot find value `args` in this scope --> RenardNumbers1.rs:10:5 | 10 | if args.len() != 3 { | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find function `exit` in this scope --> RenardNumbers1.rs:12:3 | 12 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::process::exit; | error[E0425]: cannot find value `Utils` in this scope --> RenardNumbers1.rs:14:25 | 14 | let mut series:isize = Utils.stoiWithDefault(args[1], 5); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> RenardNumbers1.rs:14:47 | 14 | let mut series:isize = Utils.stoiWithDefault(args[1], 5); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find value `Utils` in this scope --> RenardNumbers1.rs:15:28 | 15 | let mut precision:isize = Utils.stoiWithDefault(args[2], 2); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> RenardNumbers1.rs:15:50 | 15 | let mut precision:isize = Utils.stoiWithDefault(args[2], 2); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | warning: unnecessary parentheses around `if` condition --> RenardNumbers1.rs:51:9 | 51 | if (!first) { | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 51 - if (!first) { 51 + if !first { | error[E0425]: cannot find function `pow` in this scope --> RenardNumbers1.rs:31:23 | 31 | let mut factor:f64 = pow(10.0f64,1.0f64 / f64::from(series)); | ^^^ not found in this scope error[E0277]: the type `[f64]` cannot be indexed by `isize` --> RenardNumbers1.rs:36:37 | 36 | renardNumbers.push(renardNumbers[i - 1] * factor); | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[f64]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<f64>` to implement `Index<isize>` error[E0277]: the type `[f64]` cannot be indexed by `isize` --> RenardNumbers1.rs:54:62 | 54 | print!("{}", sprintf(formatStr[precision],renardNumbers[i] * (rangeStart) as f64)); | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[f64]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<f64>` to implement `Index<isize>` error[E0425]: cannot find function `sprintf` in this scope --> RenardNumbers1.rs:54:19 | 54 | print!("{}", sprintf(formatStr[precision],renardNumbers[i] * (rangeStart) as f64)); | ^^^^^^^ not found in this scope error: aborting due to 10 previous errors; 1 warning emitted Some errors have detailed explanations: E0277, E0425. For more information about an error, try `rustc --explain E0277`. $ rustc RenardNumbers1.rs error[E0425]: cannot find value `args` in this scope --> RenardNumbers1.rs:10:5 | 10 | if args.len() != 3 { | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find function `exit` in this scope --> RenardNumbers1.rs:12:3 | 12 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::process::exit; | error[E0425]: cannot find value `Utils` in this scope --> RenardNumbers1.rs:14:25 | 14 | let mut series:isize = Utils.stoiWithDefault(args[1], 5); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> RenardNumbers1.rs:14:47 | 14 | let mut series:isize = Utils.stoiWithDefault(args[1], 5); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find value `Utils` in this scope --> RenardNumbers1.rs:15:28 | 15 | let mut precision:isize = Utils.stoiWithDefault(args[2], 2); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> RenardNumbers1.rs:15:50 | 15 | let mut precision:isize = Utils.stoiWithDefault(args[2], 2); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | warning: unnecessary parentheses around `if` condition --> RenardNumbers1.rs:51:9 | 51 | if (!first) { | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 51 - if (!first) { 51 + if !first { | error[E0425]: cannot find function `pow` in this scope --> RenardNumbers1.rs:31:23 | 31 | let mut factor:f64 = pow(10.0f64,1.0f64 / f64::from(series)); | ^^^ not found in this scope error[E0277]: the type `[f64]` cannot be indexed by `isize` --> RenardNumbers1.rs:36:37 | 36 | renardNumbers.push(renardNumbers[i - 1] * factor); | ^^^^^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[f64]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<f64>` to implement `Index<isize>` error[E0277]: the type `[f64]` cannot be indexed by `isize` --> RenardNumbers1.rs:54:62 | 54 | print!("{}", sprintf(formatStr[precision],renardNumbers[i] * (rangeStart) as f64)); | ^ slice indices are of type `usize` or ranges of `usize` | = help: the trait `SliceIndex<[f64]>` is not implemented for `isize` = help: the trait `SliceIndex<[T]>` is implemented for `usize` = note: required for `Vec<f64>` to implement `Index<isize>` error[E0425]: cannot find function `sprintf` in this scope --> RenardNumbers1.rs:54:19 | 54 | print!("{}", sprintf(formatStr[precision],renardNumbers[i] * (rangeStart) as f64)); | ^^^^^^^ not found in this scope error: aborting due to 10 previous errors; 1 warning emitted Some errors have detailed explanations: E0277, E0425. For more information about an error, try `rustc --explain E0277`.

Solution