Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/prog/ Challenge 9001

Name: Anonymous 2011-05-01 19:51

The correct title of this article is /prog/ Challenge 9001. It appears incorrectly here because of technical restrictions.

The task:

Print numbers from 1 to 1000 without using any loop or conditional statements. Don't just write the printf() or cout statement 1000 times.

inb4 lipthfags and dead dogs using some obscure functionality of their obscure languages.

Name: Anonymous 2011-05-01 22:14

>>21
It uses compile-time recursion. Recursion is allowed according to the OP's rules, though.

It works by unwinding the code into this:


print_1();
print_2();
print_3();
...
print_999();
print_1000();



And the compiler likely inlines those functions so in reality it would just be unwound into this:


std::cout << 1 << std::endl;
std::cout << 2 << std::endl;
std::cout << 3 << std::endl;
...
std::cout << 999 << std::endl;
std::cout << 1000 << std::endl;

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List