How to resolve the algorithm 9 billion names of God the integer step by step in the uBasic/4tH programming language
How to resolve the algorithm 9 billion names of God the integer step by step in the uBasic/4tH programming language
Table of Contents
Problem Statement
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”:
Display the first 25 rows of a number triangle which begins: 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)}
.
If your environment is able, plot
P ( n )
{\displaystyle P(n)}
against
n
{\displaystyle n}
for
n
1 … 999
{\displaystyle n=1\ldots 999}
.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm 9 billion names of God the integer step by step in the uBasic/4tH programming language
Source code in the ubasic/4th programming language
Proc _NineBillionNames(15)
End
_NineBillionNames
Param (1)
Local (3)
@(1*a@ + 1) = 1
For b@ = 2 To a@
For c@ = 1 To b@
@(b@*a@ + c@) = @((b@ - 1)*a@ + (c@ - 1)) + @((b@ - c@)*a@ + c@)
Next
Next
For b@ = 1 To a@
d@ = a@ * 2 - 2 * b@ - 2
For c@ = 1 To b@
Print Tab(d@ + c@ * 4 + (1 - Len(Str(@(b@*a@ + c@))))); @(b@*a@ + c@);
Next
Next
Print
Return
You may also check:How to resolve the algorithm Rosetta Code/Count examples step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Rep-string step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Price fraction step by step in the Quackery programming language
You may also check:How to resolve the algorithm Singly-linked list/Element insertion step by step in the Raku programming language
You may also check:How to resolve the algorithm Bézier curves/Intersections step by step in the Modula-2 programming language