-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvariable_name.rs
More file actions
29 lines (25 loc) · 931 Bytes
/
variable_name.rs
File metadata and controls
29 lines (25 loc) · 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
fn solution(name: String) -> bool {
let acceptable_characters: String = String::from("_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
// Check if the variable starts with a number
for c in acceptable_characters[acceptable_characters.len()-10..=acceptable_characters.len()-1].chars() {
if name.starts_with(c) {
return false;
}
}
// Search for any unacceptable characters
for c in name.chars() {
if !acceptable_characters.contains(c) {
return false;
}
}
true
}
fn main() {
let acceptable_characters: String = String::from("_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
let mut name = String::from("var_1__Int");
println!("{:?}", solution(name));
name = String::from("qq-q");
println!("{:?}", solution(name));
name = String::from("2w2");
println!("{:?}", solution(name));
}