|
|
@ -1,15 +1,18 @@ |
|
|
|
// https://www.reddit.com/r/dailyprogrammer/comments/8jcffg/20180514_challenge_361_easy_tally_program/
|
|
|
|
// https://www.reddit.com/r/dailyprogrammer/comments/8jcffg/20180514_challenge_361_easy_tally_program/
|
|
|
|
|
|
|
|
// this is pretty much my first rust program
|
|
|
|
|
|
|
|
|
|
|
|
fn main() { |
|
|
|
fn main() { |
|
|
|
println!("Hello, world!"); |
|
|
|
|
|
|
|
let input = "EbAAdbBEaBaaBBdAccbeebaec"; |
|
|
|
let input = "EbAAdbBEaBaaBBdAccbeebaec"; |
|
|
|
|
|
|
|
println!("Tallying {}", input); |
|
|
|
let player_list = String::from(init_player_list(input.to_string())); |
|
|
|
let player_list = String::from(init_player_list(input.to_string())); |
|
|
|
println!("{}", player_list); |
|
|
|
println!("These people are playing: {}", player_list); |
|
|
|
|
|
|
|
|
|
|
|
let tally = tally(player_list, input.to_string()); |
|
|
|
let tally = tally(player_list, input.to_string()); |
|
|
|
print!("{:?}", tally); |
|
|
|
println!("These are their scores:"); |
|
|
|
|
|
|
|
println!("{:?}", tally); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get all distinct characters
|
|
|
|
fn init_player_list(input: String) -> String{ |
|
|
|
fn init_player_list(input: String) -> String{ |
|
|
|
let mut result = String::new(); |
|
|
|
let mut result = String::new(); |
|
|
|
let ch = input.chars(); |
|
|
|
let ch = input.chars(); |
|
|
@ -23,6 +26,9 @@ fn init_player_list(input: String) -> String{ |
|
|
|
return result |
|
|
|
return result |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// tally each players scores
|
|
|
|
|
|
|
|
// lowercase => +1 point
|
|
|
|
|
|
|
|
// uppercase => -1 point
|
|
|
|
fn tally(player_list: String, tally: String) -> Vec<(char, i32)>{ |
|
|
|
fn tally(player_list: String, tally: String) -> Vec<(char, i32)>{ |
|
|
|
let mut v: Vec<(char, i32)> = Vec::new(); |
|
|
|
let mut v: Vec<(char, i32)> = Vec::new(); |
|
|
|
for (_i, player) in player_list.chars().enumerate() { |
|
|
|
for (_i, player) in player_list.chars().enumerate() { |
|
|
|