How to resolve the algorithm 9 billion names of God the integer step by step in the Lasso programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm 9 billion names of God the integer step by step in the Lasso 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 Lasso programming language

Source code in the lasso programming language

define cumu(n::integer) => {
	loop(-from=$cache->size,-to=#n+1) => {
		local(r = array(0), l = loop_count)
		loop(loop_count) => {
			protect => { #r->insert(#r->last + $cache->get(#l - loop_count)->get(math_min(loop_count+1, #l - loop_count))) }
		}
		#r->size > 1 ? $cache->insert(#r)
	}
	return $cache->get(#n)
}
define row(n::integer) => {
	// cache gets reset & rebuilt for each row, slower but more accurate
	var(cache = array(array(1))) 
	local(r = cumu(#n+1))
	local(o = array)
	loop(#n) => {
		protect => { #o->insert(#r->get(loop_count+1) - #r->get(loop_count)) }
	}	
	return #o
}
'rows:\r'
loop(25) => {^
	loop_count + ': '+ row(loop_count)->join(' ') + '\r'
^}

'sums:\r'
with x in array(23, 123, 1234) do => {^
	var(cache = array(array(1))) 
	cumu(#x+1)->last
	'\r'
^}


  

You may also check:How to resolve the algorithm Quickselect algorithm step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Successive prime differences step by step in the Scala programming language
You may also check:How to resolve the algorithm Copy a string step by step in the AppleScript programming language
You may also check:How to resolve the algorithm Factors of an integer step by step in the BQN programming language
You may also check:How to resolve the algorithm Smith numbers step by step in the RPL programming language