Pure Programmer
Blue Matrix


Cluster Map

Project: License Plate Generator (Revisited)

Assume that you supply software for the Department of Motor Vehicles in all 50 states. Write a program that generates all the possible license plate numbers and then prints the total number of plates at the very end. Your program should accept one command line argument that provides the pattern to use when generating licenses. Any of the characters 'A'-'Z' represents the alpha characters in the plate number whereas any of the characters '0'-'9' represents digits. Any other character just represents itself.

Your program should contain a function that accepts one character from the pattern and returns an array containing all the possible characters that character could represent. For the alphabetic pattern don't allow 'I', 'O' and 'S' letters because they can be confused with digits.

Start with license plate numbers that use the pattern ABC-123. Run the program with the pattern that your state uses. See [[License Plate Designs]]. Make sure your program works with the following patterns:

American Samoa1234
Arkansas123 ABC
California1ABC234
Delaware123456
MissouriAB1 C2D
Nevada12A-345
Rhode Island123-456
TennesseeA12-34B

Output
$ rustc LicensePlates2.rs error: unknown format trait `s` --> LicensePlates2.rs:43:38 | 43 | println!("{}", format!("Syntax: {0:s} pattern", utils::program_name().expect("program name should not be empty!"))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error[E0425]: cannot find value `Utils` in this scope --> LicensePlates2.rs:26:20 | 26 | let isLast:bool = Utils.isEmpty(remainingPattern); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> LicensePlates2.rs:40:5 | 40 | if args.len() == 2 { | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find value `args` in this scope --> LicensePlates2.rs:41:15 | 41 | pattern = &(args[1]); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find function `exit` in this scope --> LicensePlates2.rs:44:3 | 44 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::process::exit; | error[E0425]: cannot find function `find` in this scope --> LicensePlates2.rs:14:5 | 14 | if find(letters,which) != string::npos { | ^^^^ not found in this scope | help: use the `.` operator to call the method `find` on `&str` | 14 - if find(letters,which) != string::npos { 14 + if letters.find(which) != string::npos { | error[E0433]: failed to resolve: use of undeclared crate or module `string` --> LicensePlates2.rs:14:28 | 14 | if find(letters,which) != string::npos { | ^^^^^^ | | | use of undeclared crate or module `string` | help: a struct with a similar name exists (notice the capitalization): `String` error[E0308]: mismatched types --> LicensePlates2.rs:15:10 | 13 | fn getChoices(which:&str) -> String { | ------ expected `String` because of return type 14 | if find(letters,which) != string::npos { 15 | return letters; | ^^^^^^^- help: try using a conversion method: `.to_string()` | | | expected `String`, found `&str` error[E0425]: cannot find function `find` in this scope --> LicensePlates2.rs:16:12 | 16 | } else if find(digits,which) != string::npos { | ^^^^ not found in this scope | help: use the `.` operator to call the method `find` on `&str` | 16 - } else if find(digits,which) != string::npos { 16 + } else if digits.find(which) != string::npos { | error[E0433]: failed to resolve: use of undeclared crate or module `string` --> LicensePlates2.rs:16:34 | 16 | } else if find(digits,which) != string::npos { | ^^^^^^ | | | use of undeclared crate or module `string` | help: a struct with a similar name exists (notice the capitalization): `String` error[E0425]: cannot find function `substr` in this scope --> LicensePlates2.rs:24:35 | 24 | let choices:String = getChoices(&substr(pattern,0,1)); | ^^^^^^ not found in this scope error[E0425]: cannot find function `right_tail` in this scope --> LicensePlates2.rs:25:32 | 25 | let remainingPattern:String = right_tail(pattern,1); | ^^^^^^^^^^ not found in this scope error[E0308]: mismatched types --> LicensePlates2.rs:28:49 | 28 | let newPrefix:String = String::from(prefix) + c; | ^ expected `&str`, found `char` error: aborting due to 13 previous errors Some errors have detailed explanations: E0308, E0425, E0433. For more information about an error, try `rustc --explain E0308`. $ rustc LicensePlates2.rs error: unknown format trait `s` --> LicensePlates2.rs:43:38 | 43 | println!("{}", format!("Syntax: {0:s} pattern", utils::program_name().expect("program name should not be empty!"))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error[E0425]: cannot find value `Utils` in this scope --> LicensePlates2.rs:26:20 | 26 | let isLast:bool = Utils.isEmpty(remainingPattern); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> LicensePlates2.rs:40:5 | 40 | if args.len() == 2 { | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find value `args` in this scope --> LicensePlates2.rs:41:15 | 41 | pattern = &(args[1]); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find function `exit` in this scope --> LicensePlates2.rs:44:3 | 44 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::process::exit; | error[E0425]: cannot find function `find` in this scope --> LicensePlates2.rs:14:5 | 14 | if find(letters,which) != string::npos { | ^^^^ not found in this scope | help: use the `.` operator to call the method `find` on `&str` | 14 - if find(letters,which) != string::npos { 14 + if letters.find(which) != string::npos { | error[E0433]: failed to resolve: use of undeclared crate or module `string` --> LicensePlates2.rs:14:28 | 14 | if find(letters,which) != string::npos { | ^^^^^^ | | | use of undeclared crate or module `string` | help: a struct with a similar name exists (notice the capitalization): `String` error[E0308]: mismatched types --> LicensePlates2.rs:15:10 | 13 | fn getChoices(which:&str) -> String { | ------ expected `String` because of return type 14 | if find(letters,which) != string::npos { 15 | return letters; | ^^^^^^^- help: try using a conversion method: `.to_string()` | | | expected `String`, found `&str` error[E0425]: cannot find function `find` in this scope --> LicensePlates2.rs:16:12 | 16 | } else if find(digits,which) != string::npos { | ^^^^ not found in this scope | help: use the `.` operator to call the method `find` on `&str` | 16 - } else if find(digits,which) != string::npos { 16 + } else if digits.find(which) != string::npos { | error[E0433]: failed to resolve: use of undeclared crate or module `string` --> LicensePlates2.rs:16:34 | 16 | } else if find(digits,which) != string::npos { | ^^^^^^ | | | use of undeclared crate or module `string` | help: a struct with a similar name exists (notice the capitalization): `String` error[E0425]: cannot find function `substr` in this scope --> LicensePlates2.rs:24:35 | 24 | let choices:String = getChoices(&substr(pattern,0,1)); | ^^^^^^ not found in this scope error[E0425]: cannot find function `right_tail` in this scope --> LicensePlates2.rs:25:32 | 25 | let remainingPattern:String = right_tail(pattern,1); | ^^^^^^^^^^ not found in this scope error[E0308]: mismatched types --> LicensePlates2.rs:28:49 | 28 | let newPrefix:String = String::from(prefix) + c; | ^ expected `&str`, found `char` error: aborting due to 13 previous errors Some errors have detailed explanations: E0308, E0425, E0433. For more information about an error, try `rustc --explain E0308`. $ rustc LicensePlates2.rs error: unknown format trait `s` --> LicensePlates2.rs:43:38 | 43 | println!("{}", format!("Syntax: {0:s} pattern", utils::program_name().expect("program name should not be empty!"))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error[E0425]: cannot find value `Utils` in this scope --> LicensePlates2.rs:26:20 | 26 | let isLast:bool = Utils.isEmpty(remainingPattern); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> LicensePlates2.rs:40:5 | 40 | if args.len() == 2 { | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find value `args` in this scope --> LicensePlates2.rs:41:15 | 41 | pattern = &(args[1]); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find function `exit` in this scope --> LicensePlates2.rs:44:3 | 44 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::process::exit; | error[E0425]: cannot find function `find` in this scope --> LicensePlates2.rs:14:5 | 14 | if find(letters,which) != string::npos { | ^^^^ not found in this scope | help: use the `.` operator to call the method `find` on `&str` | 14 - if find(letters,which) != string::npos { 14 + if letters.find(which) != string::npos { | error[E0433]: failed to resolve: use of undeclared crate or module `string` --> LicensePlates2.rs:14:28 | 14 | if find(letters,which) != string::npos { | ^^^^^^ | | | use of undeclared crate or module `string` | help: a struct with a similar name exists (notice the capitalization): `String` error[E0308]: mismatched types --> LicensePlates2.rs:15:10 | 13 | fn getChoices(which:&str) -> String { | ------ expected `String` because of return type 14 | if find(letters,which) != string::npos { 15 | return letters; | ^^^^^^^- help: try using a conversion method: `.to_string()` | | | expected `String`, found `&str` error[E0425]: cannot find function `find` in this scope --> LicensePlates2.rs:16:12 | 16 | } else if find(digits,which) != string::npos { | ^^^^ not found in this scope | help: use the `.` operator to call the method `find` on `&str` | 16 - } else if find(digits,which) != string::npos { 16 + } else if digits.find(which) != string::npos { | error[E0433]: failed to resolve: use of undeclared crate or module `string` --> LicensePlates2.rs:16:34 | 16 | } else if find(digits,which) != string::npos { | ^^^^^^ | | | use of undeclared crate or module `string` | help: a struct with a similar name exists (notice the capitalization): `String` error[E0425]: cannot find function `substr` in this scope --> LicensePlates2.rs:24:35 | 24 | let choices:String = getChoices(&substr(pattern,0,1)); | ^^^^^^ not found in this scope error[E0425]: cannot find function `right_tail` in this scope --> LicensePlates2.rs:25:32 | 25 | let remainingPattern:String = right_tail(pattern,1); | ^^^^^^^^^^ not found in this scope error[E0308]: mismatched types --> LicensePlates2.rs:28:49 | 28 | let newPrefix:String = String::from(prefix) + c; | ^ expected `&str`, found `char` error: aborting due to 13 previous errors Some errors have detailed explanations: E0308, E0425, E0433. For more information about an error, try `rustc --explain E0308`. $ rustc LicensePlates2.rs error: unknown format trait `s` --> LicensePlates2.rs:43:38 | 43 | println!("{}", format!("Syntax: {0:s} pattern", utils::program_name().expect("program name should not be empty!"))); | ^ | = note: the only appropriate formatting traits are: - ``, which uses the `Display` trait - `?`, which uses the `Debug` trait - `e`, which uses the `LowerExp` trait - `E`, which uses the `UpperExp` trait - `o`, which uses the `Octal` trait - `p`, which uses the `Pointer` trait - `b`, which uses the `Binary` trait - `x`, which uses the `LowerHex` trait - `X`, which uses the `UpperHex` trait error[E0425]: cannot find value `Utils` in this scope --> LicensePlates2.rs:26:20 | 26 | let isLast:bool = Utils.isEmpty(remainingPattern); | ^^^^^ not found in this scope error[E0425]: cannot find value `args` in this scope --> LicensePlates2.rs:40:5 | 40 | if args.len() == 2 { | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find value `args` in this scope --> LicensePlates2.rs:41:15 | 41 | pattern = &(args[1]); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::env::args; | error[E0425]: cannot find function `exit` in this scope --> LicensePlates2.rs:44:3 | 44 | exit(1); | ^^^^ not found in this scope | help: consider importing this function | 7 + use std::process::exit; | error[E0425]: cannot find function `find` in this scope --> LicensePlates2.rs:14:5 | 14 | if find(letters,which) != string::npos { | ^^^^ not found in this scope | help: use the `.` operator to call the method `find` on `&str` | 14 - if find(letters,which) != string::npos { 14 + if letters.find(which) != string::npos { | error[E0433]: failed to resolve: use of undeclared crate or module `string` --> LicensePlates2.rs:14:28 | 14 | if find(letters,which) != string::npos { | ^^^^^^ | | | use of undeclared crate or module `string` | help: a struct with a similar name exists (notice the capitalization): `String` error[E0308]: mismatched types --> LicensePlates2.rs:15:10 | 13 | fn getChoices(which:&str) -> String { | ------ expected `String` because of return type 14 | if find(letters,which) != string::npos { 15 | return letters; | ^^^^^^^- help: try using a conversion method: `.to_string()` | | | expected `String`, found `&str` error[E0425]: cannot find function `find` in this scope --> LicensePlates2.rs:16:12 | 16 | } else if find(digits,which) != string::npos { | ^^^^ not found in this scope | help: use the `.` operator to call the method `find` on `&str` | 16 - } else if find(digits,which) != string::npos { 16 + } else if digits.find(which) != string::npos { | error[E0433]: failed to resolve: use of undeclared crate or module `string` --> LicensePlates2.rs:16:34 | 16 | } else if find(digits,which) != string::npos { | ^^^^^^ | | | use of undeclared crate or module `string` | help: a struct with a similar name exists (notice the capitalization): `String` error[E0425]: cannot find function `substr` in this scope --> LicensePlates2.rs:24:35 | 24 | let choices:String = getChoices(&substr(pattern,0,1)); | ^^^^^^ not found in this scope error[E0425]: cannot find function `right_tail` in this scope --> LicensePlates2.rs:25:32 | 25 | let remainingPattern:String = right_tail(pattern,1); | ^^^^^^^^^^ not found in this scope error[E0308]: mismatched types --> LicensePlates2.rs:28:49 | 28 | let newPrefix:String = String::from(prefix) + c; | ^ expected `&str`, found `char` error: aborting due to 13 previous errors Some errors have detailed explanations: E0308, E0425, E0433. For more information about an error, try `rustc --explain E0308`.

Solution