On 1/30/2010 3:47 PM, Paul Herring wrote:
> On Sat, Jan 30, 2010 at 8:27 PM, ibraheem Tasneem<[email protected]>  
> wrote:
>    
>> 11
>> 134
>> 1359
>> 135716
>> 1359
>> 134
>> 11
>>      
> Probably me being a bit thick, but that looks like a Mensa question to
> which the answer relies on the output of 'pom'.
>
> I can see no mathematical pattern there from which you could derive a
> two-loop program.
>    

Sure there is. Just look past single digits.

1 - 1
1 - 3 - 4
1 - 3 - 5 - 9
1 - 3 - 5 - 7 - 16

...and then it iterates in reverse.

Using one-based loops, it does the following:

1. Prints the first n positive odd integers. There are algorithms in the 
OP's textbook to do this.

2. Prints n^2.

I wish my job had problems as interesting as this homework...

-- 
John Gaughan
http://www.jtgprogramming.org/

Reply via email to