This task is a variation of the short story by Arthur C. Clarke.

(Solvers should be aware of the consequences of completing this task.)

In detail, to specify what is meant by a   “name”:

The integer 1 has 1 name     “1”.
The integer 2 has 2 names   “1+1”,   and   “2”.
The integer 3 has 3 names   “1+1+1”,   “2+1”,   and   “3”.
The integer 4 has 5 names   “1+1+1+1”,   “2+1+1”,   “2+2”,   “3+1”,   “4”.
The integer 5 has 7 names   “1+1+1+1+1”,   “2+1+1+1”,   “2+2+1”,   “3+1+1”,   “3+2”,   “4+1”,   “5”.


Task
Display the first 25 rows of a number triangle which begins:

                                      1
                                    1   1
                                  1   1   1 
                                1   2   1   1
                              1   2   2   1   1
                            1   3   3   2   1   1

Where row   



n


{\displaystyle n}

   corresponds to integer   



n


{\displaystyle n}

,   and each column   



C


{\displaystyle C}

   in row   



m


{\displaystyle m}

   from left to right corresponds to the number of names beginning with   



C


{\displaystyle C}

.

A function   



G
(
n
)


{\displaystyle G(n)}

   should return the sum of the   



n


{\displaystyle n}

-th   row.

Demonstrate this function by displaying:   



G
(
23
)


{\displaystyle G(23)}

,   



G
(
123
)


{\displaystyle G(123)}

,   



G
(
1234
)


{\displaystyle G(1234)}

,   and   



G
(
12345
)


{\displaystyle G(12345)}

.

Optionally note that the sum of the   



n


{\displaystyle n}

-th   row   



P
(
n
)


{\displaystyle P(n)}

   is the     integer partition function.

Demonstrate this is equivalent to   



G
(
n
)


{\displaystyle G(n)}

   by displaying:   



P
(
23
)


{\displaystyle P(23)}

,   



P
(
123
)


{\displaystyle P(123)}

,   



P
(
1234
)


{\displaystyle P(1234)}

,   and   



P
(
12345
)


{\displaystyle P(12345)}

.



Extra credit
If your environment is able, plot   



P
(
n
)


{\displaystyle P(n)}

   against   



n


{\displaystyle n}

   for   



n
=
1
…
999


{\displaystyle n=1\ldots 999}

.

Related tasks
 Partition function P


 
Define nMax.i=25, n.i, k.i
Dim pfx.s(1)
 
Procedure.s Sigma(sx.s, sums.s)
  Define i.i, v1.i, v2.i, r.i
  Define s.s, sa.s
  sums=ReverseString(sums) : s=ReverseString(sx)
  For i=1 To Len(s)*Bool(Len(s)>Len(sums))+Len(sums)*Bool(Len(sums)>=Len(s))
    v1=Val(Mid(s,i,1))
    v2=Val(Mid(sums,i,1))
    r+v1+v2    
    sa+Str(r%10)
    r/10
  Next i  
  If r : sa+Str(r%10) : EndIf
  ProcedureReturn ReverseString(sa)
EndProcedure
 
Procedure.i Adr(row.i,col.i)
  ProcedureReturn ((row-1)*row/2+col)*Bool(row>0 And col>0)
EndProcedure
 
Procedure Triangle(row.i,Array pfx.s(1))
  Define n.i,k.i
  Define zs.s
  nMax=row
  ReDim pfx(Adr(nMax,nMax))
  For n=1 To nMax
    For k=1 To n    
      If k>n    : pfx(Adr(n,k))="0"    : Continue : EndIf
      If n=k    : pfx(Adr(n,k))="1"    : Continue : EndIf    
      If k<=n/2
        zs=""
        zs=Sigma(pfx(Adr(n-k,k)),zs)
        zs=Sigma(pfx(Adr(n-1,k-1)),zs)
        pfx(Adr(n,k))=zs
      Else
        pfx(Adr(n,k))=pfx(Adr(n-1,k-1))
      EndIf
    Next k
  Next n
EndProcedure
 
Procedure.s sum(row.i, Array pfx.s(1))
  Define s.s
  Triangle(row, pfx())
  For n=1 To row
    s=Sigma(pfx(Adr(row,n)),s)
  Next n
  ProcedureReturn RSet(Str(row),5,Chr(32))+" : "+s
EndProcedure
 
OpenConsole()
 
Triangle(nMax, pfx())
For n=1 To nMax
  Print(Space(((nMax*4-1)-(n*4-1))/2))
  For k=1 To n    
    Print(RSet(pfx(Adr(n,k)),3,Chr(32))+Space(1))
  Next k
  PrintN("")
Next n
PrintN("")
PrintN(sum(23,pfx()))
PrintN(sum(123,pfx()))
PrintN(sum(1234,pfx()))
PrintN(sum(12345,pfx()))
Input()
 