|
#include <iostream> |
|
#include <random> |
|
#include <sstream> |
|
|
|
using namespace std; |
|
|
|
using Players = vector<string>; |
|
|
|
int main() { |
|
Players players{"@0xced", "@GuickPa", "@HerveCaumont", "@LakaLe_", "@MarcioK", |
|
"@Neilkachu", "@VijayTholpadi", "@a_schacherbauer", "@agisilaosts", |
|
"@apouche", "@azouts", "@dmytrolisitsyn", "@draufunddran1", "@ge_hn", |
|
"@guiiipontes", "@igorescobar", "@ikarius", "@jadekin", |
|
"@janiskirsteins", "@jolyAlexandre", "@kedarv", "@kyegeorge", |
|
"@leakywellington", "@lipec", "@m_sgr_bot", "@marius_const", |
|
"@onmyway133", "@ooswald", "@paulrikmans", "@pbendersky", |
|
"@relausen", "@rpresedo", "@rshankra", "@sandeepCool77", "@sconig", |
|
"@whakkee", "@xmonodev", "@xrb", "@yostane", "@zen_prog"}; |
|
|
|
auto shuffle = [](Players &p) -> void { |
|
auto seed = chrono::system_clock::now().time_since_epoch().count(); |
|
std::shuffle(p.begin(), p.end(), default_random_engine(seed)); |
|
}; |
|
|
|
auto stats = [](Players &p) -> string { |
|
|
|
auto join = [p](string separator) -> string { |
|
ostringstream stream; |
|
auto iterator = ostream_iterator<string>(stream, separator.c_str()); |
|
copy(p.begin(), p.end(), iterator); |
|
auto str = stream.str(); |
|
str.erase(str.length() - separator.size()); |
|
return str; |
|
}; |
|
|
|
stringstream stream; |
|
stream << p.size() << " players: " << join(", "); |
|
return stream.str(); |
|
}; |
|
|
|
auto congrats = [](string &winner, uint32_t number) -> string { |
|
string medal{"\U0001F3C5"}; |
|
string cup{"\U0001F3C6"}; |
|
string gift{"\U0001F381"}; |
|
string thumbsup{"\U0001F44D"}; |
|
stringstream stream; |
|
stream << "And the winner is… " << medal << " " << cup |
|
<< " ~~ " << winner << " ~~ " |
|
<< gift << " " << thumbsup << " (number " << number << ")"; |
|
return stream.str(); |
|
}; |
|
|
|
auto draw = [shuffle](Players &p) { |
|
auto times = arc4random_uniform(1000); |
|
uint32_t lottery; |
|
string winner; |
|
for (int i = 0; i < times; ++i) { |
|
shuffle(p); |
|
lottery = arc4random_uniform(p.size()); |
|
winner = p[lottery]; |
|
} |
|
return make_pair(lottery, winner); |
|
}; |
|
|
|
auto result = draw(players); |
|
auto lottery = result.first; |
|
auto winner = result.second; |
|
|
|
cout << stats(players) << endl; |
|
cout << endl; |
|
cout << congrats(winner, lottery) << endl; |
|
cout << endl; |
|
return 0; |
|
} |