This is not the worst program I've ever written, but it's pretty bad.
I recently participated in the ICPC (International Collegiate Programming Contest) at my school. To get everyone used to the judging system and the idea of a programming contest, it starts with a 45 minute long practice contest with one problem, which is "input a number and output the sum of the numbers from 1 to that number."
Of course, I could have written a program to do that in 5 minutes. But a guy on the team that eventually got first place said, "Theodore, I expect you to do this in the most insane and inefficient way possible." So I wrote this (as best as I can remember):
When you compile this, the C compiler will, after about 30 seconds, generate a lookup table with the answer for any input value up to 1,048,575. This isn't the absolute maximum number you could input though, so as a failsafe, it first calculates the answer at runtime, and then checks if the input is in the lookup table. If it is, then it uses the value from the lookup table instead.
When I came back from the practice contest, I told the other team about what I'd done, and they said "whoa that's the perfect way to do it." They'd written a Python program to generate a C program with the lookup table. They also showed me a screenshot from a judge's machine saying:
This is not the worst program I've ever written, but it's pretty bad.
I recently participated in the ICPC (International Collegiate Programming Contest) at my school. To get everyone used to the judging system and the idea of a programming contest, it starts with a 45 minute long practice contest with one problem, which is "input a number and output the sum of the numbers from 1 to that number."
Of course, I could have written a program to do that in 5 minutes. But a guy on the team that eventually got first place said, "Theodore, I expect you to do this in the most insane and inefficient way possible." So I wrote this (as best as I can remember):
When you compile this, the C compiler will, after about 30 seconds, generate a lookup table with the answer for any input value up to 1,048,575. This isn't the absolute maximum number you could input though, so as a failsafe, it first calculates the answer at runtime, and then checks if the input is in the lookup table. If it is, then it uses the value from the lookup table instead.
When I came back from the practice contest, I told the other team about what I'd done, and they said "whoa that's the perfect way to do it." They'd written a Python program to generate a C program with the lookup table. They also showed me a screenshot from a judge's machine saying:
haha nice!