Print strings from "a" to "zzzzz" without using any loop or conditional statements. Don't just write all 1000 permutations out by hand. The output should look like this: a
b
c
...
aa
ab
ac
...
zzzzx
zzzzy
zzzzz
inb4 lipthfags and dead dogs using some obscure functionality of their obscure languages.
Name:
Anonymous2011-05-03 1:22
Pretty sure this uses absolutely no loops or conditionals... But it requires a huge stack to run without crashing. I haven't run it to the end so I'm not even sure if a stack size of 100,000,000 is big enough.
#pragma comment(linker, "/stack:100000000")
#include <iostream>
#include <cstdlib>
template<typename T>
struct true_define
{
typedef T (*is_true)(T);
};
template<typename T>
T is_true1(T x)
{
return x;
}
template<typename T>
T is_true2(T x)
{
return 1;
}
template<typename T, int I>
struct check_bits
{
static T check(T x, T cur, typename true_define<T>::is_true tests[2])
{
cur = tests[cur]((x >> I) & 1);
return check_bits<T, I-1>::check(x, cur, tests);
}
};
template<typename T>
struct check_bits<T, 0>
{
static T check(T x, T cur, typename true_define<T>::is_true tests[2])
{
cur = tests[cur](x & 1);
return cur;
}
};