Last active
September 23, 2020 14:53
-
-
Save outfrost/cbfd51cdcee3f9136b260befdf7730a0 to your computer and use it in GitHub Desktop.
Ludum Dare Theme Slaughter: theme ideas you've kept so far
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::{collections::HashMap, env, fs}; | |
use serde::{Deserialize, Serialize}; | |
use serde_json; | |
#[derive(Deserialize, Serialize)] | |
struct Ideas { | |
pub status: u16, | |
pub caller_id: u64, | |
pub ideas: HashMap<String, String>, | |
} | |
#[derive(Deserialize, Serialize)] | |
struct Votes { | |
pub status: u16, | |
pub caller_id: u64, | |
pub votes: HashMap<String, i32>, | |
} | |
// Args: file_with_themes_json file_with_votes_json | |
fn main() { | |
let args: Vec<String> = env::args().collect(); | |
let theme_ideas_json = fs::read_to_string(&args[1]).unwrap(); | |
let theme_votes_json = fs::read_to_string(&args[2]).unwrap(); | |
let theme_ideas: Ideas = serde_json::from_str(&theme_ideas_json).unwrap(); | |
let theme_votes: Votes = serde_json::from_str(&theme_votes_json).unwrap(); | |
let accepted_themes = theme_ideas.ideas.iter() | |
.filter_map(|(key, name)| { | |
match theme_votes.votes.get(key) { | |
Some(1) => Some(name.as_str()), | |
_ => None, | |
} | |
}); | |
for name in accepted_themes { | |
println!("{}", name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment