Appended Numbers Game Appended Numbers Game

Write a function/program that takes 2 integer parameters integer parameters or integer variables, a start number, and a max iterations count. The code should perform the following game example to construct a new number, and repeat until the number is a single digit left. eg.

3 7 2 = (3 + 7) &amp; (7 + 2) = 10 9
1 0 9 = (1 + 0) &amp; (0 + 9) = 1 9
1 9 = (1 + 9) = 10
1 0 = (1 + 0) = 1


Basically, taking each individual digit and adding it to its neighbour, then appending the result of the next addition as well.

Max iteration count is to safeguard infinite loops, and when the max is hit, code should dump the last 5 number steps. The same output should occur when finishing by reaching a single digit. If less than 5 steps occurred, only output the valid numbers.

Output should appear like (Step: Number) including the last 5 steps of the finished or terminated steps:

func(3541, 50) would produce this exact output format:

6: 1411
7: 552
8: 107
9: 17
10: 8


func(3541, 5) would produce:

1: 895
2: 1714
3: 885
4: 1613
5: 774


The entire calculation being:

1: 895
2: 1714
3: 885
4: 1613
5: 774
6: 1411
7: 552
8: 107
9: 17
10: 8


If there are less than 5 steps, just print those steps taken.

Only use built-in libs, parameters can be from anywhere (whatever's easiest for your language of choice). No limit on maximum integer size, and if there are overflows, let it crash.

Given this isn't too difficult from a puzzle point of view, I will give until Sunday 25th, 8PM (UTC+8) for submissions to be considered for the accepted answer, at which point the shortest of any language will be the winner.

EDIT:

Congratulations to Howard, winning with a 48 GolfScript answer.

Special mention to 2nd place marinus with a 66 APL answer.

My personal favourite (being biased towards JavaScript) was core1024's answer.
APL (66)

{↑¯5↑{(⍕⍵),': ',⍺}/∆,⍪⍳⍴∆←⍺{(1&lt;⍴⍵)∧⍺&gt;0:∆,(⍺-1)∇⊃∆←,/⍕¨2+/⍎¨⍵⋄⍬}⍕⍵}


The left argument is the maximum iteration count and the right argument is the start number.

Explanation:


∆←⍺{...}⍕⍵: pass the left argument as a number and the right argument as a string to the function that calculates the list of numbers, and store it in ∆:

(1&lt;⍴⍵)∧⍺&gt;0:: if the amount of digits is more than 1 and the amount of iterations left is more than 0:

⍎¨⍵: evaluate each digit
2+/: sum each pair
⍕¨: format each number as a string
∆←,/: concatenate the strings and store in ∆
∆,(⍺-1)∇⊃∆: return ∆, followed by the result of applying this function to ∆ with one less iteration allowed

⋄⍬: if not, return the empty list

∆,⍪⍳⍴∆: pair each element of ∆ with its index in ∆ 
{...}/: for each pair:

(⍕⍵),': ',⍺: return a string with the index, followed by :, followed by the number

↑¯5↑: turn the list of strings into a matrix so they display on separate lines, and take the last 5 items


Test:

      5{↑¯5↑{(⍕⍵),': ',⍺}/∆,⍪⍳⍴∆←⍺{(1&lt;⍴⍵)∧⍺&gt;0:∆,(⍺-1)∇⊃∆←,/⍕¨2+/⍎¨⍵⋄⍬}⍕⍵}3541
1: 895 
2: 1714
3: 885 
4: 1613
5: 774 
      50{↑¯5↑{(⍕⍵),': ',⍺}/∆,⍪⍳⍴∆←⍺{(1&lt;⍴⍵)∧⍺&gt;0:∆,(⍺-1)∇⊃∆←,/⍕¨2+/⍎¨⍵⋄⍬}⍕⍵}3541
6: 1411
7: 552 
8: 107 
9: 17  
10: 8