Pages

Monday, July 19, 2010

Weekend fun with Simplest Pyramid Generator!

I just get bored during this weekend and try to solve some puzzle that my friends mentioned on my email last week. It is making a sort of Pyramid but only with odd numbers. So, what we have to do is try to make a simplest pyramid generator program to generate a pyramid with a single argument given. For example:

C:\pyramid.exe 7

would generate a pyramid like this:

I know that there is some script like Python, Ruby and so on can make a single line of code to generate this pyramid. But the condition is not to use a special function or library. I just solved this puzzle within 3 hours with Visual C++ 6.0. Here it is a single long line of code:

Thus, this code still need to insert a header file <iostream.h> and <stdlib.h> for print the result and the atoi function for converting ASCII to Integer from the given argument. But this is standard for C programming. All scripting language for sure need all these stuff for the script that communicate with core engine. Coding with C++ might be various depend on your platform and compiler.