Skip to content

Instantly share code, notes, and snippets.

@fcamel
Created November 30, 2013 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fcamel/7722778 to your computer and use it in GitHub Desktop.
Save fcamel/7722778 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <set>
enum Type {
A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z
};
bool isOkayBySwitch(Type type) {
switch (type) {
case A:
case C:
case D:
case E:
case G:
case I:
case K:
case L:
case Y:
return false;
default:
;
}
return true;
}
bool isOkayByIf(Type type) {
if (type == A
|| type == C
|| type == D
|| type == E
|| type == G
|| type == I
|| type == K
|| type == L
|| type == Y) {
return false;
}
return true;
}
bool isOkayByAlotOfIf(Type type) {
if (type == A) {
return false;
} else if (type == C) {
return false;
} else if (type == D) {
return false;
} else if (type == E) {
return false;
} else if (type == G) {
return false;
} else if (type == I) {
return false;
} else if (type == K) {
return false;
} else if (type == L) {
return false;
} else if (type == Y) {
return false;
}
return true;
}
struct Record
{
Record()
{
m_blacklist.insert(A);
m_blacklist.insert(C);
m_blacklist.insert(D);
m_blacklist.insert(E);
m_blacklist.insert(G);
m_blacklist.insert(I);
m_blacklist.insert(K);
m_blacklist.insert(L);
m_blacklist.insert(Y);
}
bool isOkayBySet(Type type)
{
return m_blacklist.count(type) == 0;
}
std::set<Type> m_blacklist;
};
Record s_record;
int main(void) {
int s = 0;
for (int i = 0; i < 100000000; i++) {
for (int j = 0; j < 26; j++) {
#if defined(SWITCH)
s += isOkayBySwitch(static_cast<Type>(j));
#elif defined(ALOTIF)
s += isOkayByAlotOfIf(static_cast<Type>(j));
#elif defined(IF)
s += isOkayByIf(static_cast<Type>(j));
#else
s += s_record.isOkayBySet(static_cast<Type>(j));
#endif
}
}
std::cout << s << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment