Skip to content

Instantly share code, notes, and snippets.

@regexident
Last active August 29, 2015 14:21
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 regexident/c79f61e6b0187eecccf5 to your computer and use it in GitHub Desktop.
Save regexident/c79f61e6b0187eecccf5 to your computer and use it in GitHub Desktop.
Obfuscated fizzbuzz
#include <iostream>
template <int N>
struct n { static const int v = N; };
template <typename...Ts>
struct l { };
template <typename T, typename TL> struct c;
template <typename T, typename...Ts>
struct c<T, l<Ts...>> { using t = l<T, Ts...>; };
template <int F, int L, template <int> class T>
struct g { using t = typename c<T<F>, typename g<F + 1, L, T>::t>::t; };
template <int N, template <int> class T>
struct g<N, N, T> { using t = l<>; };
template <template <typename> class F, typename TL>
struct m;
template <template <typename> class F, typename...Ts>
struct m<F, l<Ts...>> { using t = l<typename F<Ts>::t...>; };
template <int I>
struct a { static const uint64_t v = ~((-8825495485607995751LL >> (I * (1 << 3))) & ((1 << 8) - 1)); };
template <typename N, bool F = !(N::v%~-4), bool B = !(N::v%~-6)>
struct fb { using t = N; };
template <int N>
struct fb<n<N>, true, true> { using t = typename g<0, 8, a>::t; };
template <int N>
struct fb<n<N>, true, false> { using t = typename g<0, 4, a>::t; };
template <int N>
struct fb<n<N>, false, true> { using t = typename g<4, 8, a>::t; };
template <typename N> using f = fb<N>;
template <typename T>
struct p;
template <int V>
struct p<n<V>> { static void pp() { std::cout << V << uint8_t(1 << 5); } };
template <int V>
struct p<a<V>> { static void pp() { std::cout << (uint8_t)a<V>::v; } };
template <typename T, typename...Ts>
struct p<l<T, Ts...>> { static void pp() { p<T>::pp(); p<l<Ts...>>::pp(); } };
template <>
struct p<l<>> { static void pp() { std::cout << uint8_t(1 << 5); } };
int main() {
p<typename m<f, typename g<1, 256, n>::t>::t>::pp();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment