tvl-depot/users/tazjin/dt/dt.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

80 lines
1.8 KiB
C++
Raw Normal View History

2020-05-08 19:55:00 +02:00
#include <iostream>
#include <vector>
2020-05-08 19:55:00 +02:00
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
#include "absl/hash/hash.h"
#include "absl/strings/str_cat.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "absl/types/optional.h"
2020-05-08 19:55:00 +02:00
#include "farmhash.h"
2020-05-11 04:31:19 +02:00
ABSL_FLAG(std::vector<std::string>, words, {}, "words to use");
2020-05-08 19:55:00 +02:00
struct Result {
std::string a;
2020-05-11 04:31:19 +02:00
int ec;
absl::optional<std::string> p;
};
std::string which(const std::vector<std::string>& words) {
uint64_t fp;
std::string word;
for (const auto& w : words) {
auto nfp = util::Fingerprint64(w);
if (nfp > fp) {
fp = nfp;
word = w;
}
2020-05-08 19:55:00 +02:00
}
return word;
2020-05-08 19:55:00 +02:00
}
Result decide(const std::vector<std::string>& words) {
auto input = absl::FormatTime("%Y%m%d", absl::Now(), absl::UTCTimeZone());
for (const auto& w : words) {
input += w;
}
2020-05-11 04:31:19 +02:00
auto base = util::Fingerprint64(input);
Result result = { "nope" };
2020-05-08 19:55:00 +02:00
if (base % 10 == 0) {
result.a = "ca";
2020-05-11 04:31:19 +02:00
} else if (base % 8 == 0) {
result.a = "c1";
result.p = which(words);
2020-05-11 04:31:19 +02:00
} else if (base % 6 == 0) {
result.a = "skip";
} else if (base % 3 == 0) {
result.a = "e1";
2020-05-11 04:31:19 +02:00
result.ec = base % 10;
result.p = which(words);
2020-05-11 04:31:19 +02:00
} else if (base % 2 == 0) {
result.a = "ea";
result.ec = base % 10;
2020-05-08 19:55:00 +02:00
}
return result;
2020-05-08 19:55:00 +02:00
}
int main(int argc, char *argv[]) {
absl::ParseCommandLine(argc, argv);
2020-05-11 04:31:19 +02:00
auto words = absl::GetFlag(FLAGS_words);
if (words.size() < 2) {
std::cerr << "needs at least two!" << std::endl;
2020-05-08 19:55:00 +02:00
return 1;
}
auto result = decide(words);
std::cout << result.a
<< (result.p.has_value() ? absl::StrCat(" ", "(", result.p.value(), ")")
: "")
2020-05-11 04:31:19 +02:00
<< (result.ec > 0 ? absl::StrCat(": ", result.ec) : "")
<< std::endl;
2020-05-08 19:55:00 +02:00
}