Here comes a little code-tag (in C++) for you all to use, it's to count the numbers of cards in a card-house when you are given a specified height in floors.

for(int step = height; step>=1; step--)
number = number + (step * 3 - 1);

where the height variable is the number of floor in the house.
Posted on 2002-03-21 14:41:49 by Nordbon
I just converted it crudely, so no gaurantee this is a perfect translation:

mov ecx, height

cmp ecx, 1
jb @f
mov eax, ecx
mov ebx, eax
add eax, ebx
add eax, ebx
dec eax
mov edx, number
add edx, eax
mov number, edx
dec ecx
jmp @b
Posted on 2002-03-21 15:46:40 by stryker
height EQU <TheHeight>

step EQU <edx>
number EQU <eax>

mov number, 0
mov step, height
lea ecx, [step + step*2 - 1]
dec step
lea number, [ecx + number]
jne @B
Result in EAX.

Or without the loop: (3x^2 + x)/2
    mov eax, height

lea eax, [eax + eax*2 + 1]
mul height
shr eax, 1 ; bit 0 is always 0 :)
Posted on 2002-03-21 17:10:52 by bitRAKE
Yay now I can finally finish my card-house program?

Posted on 2002-03-21 17:36:51 by iblis
Bravo, bitRake! Math rules forever!

A liitle bit shorter size:
mov ecx,height
lea eax,
mul ecx
shr eax,1
Posted on 2002-03-22 04:31:14 by The Svin