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 20:21

Looping means goto, which means the solution is to unroll the loop.
(macrolet ((code () `(progn ,@(loop for i from 1 to 1000 collect `(print ,i))))) (code))

What this code does is generate the code: (progn (print 1) ... (print 1000))
Looping isn't used in any of the code that runs, hence it should fulfill your requirement (it is however used in the generation code. There is no way to avoid this without writing it by hand, and only an idiot would do that. I could of course, post the macroexpansion without posting the generation code, but it turns out it's too long to fit in a post).

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