9 billion names of God the integer: Difference between revisions

Content added Content deleted
m (Added a (poorly optimized) Red answer)
Line 3,687: Line 3,687:
12345 69420357953926116819562977205209384460667673094671463620270321700806074195845953959951425306140971942519870679768681736</pre>
12345 69420357953926116819562977205209384460667673094671463620270321700806074195845953959951425306140971942519870679768681736</pre>


=={{header|Red}}==
<lang Rebol>Red [Purpose: "9 billion names of god"]
name-find: function [
max
] [
repeat row max [
repeat col row [
pos: reduce []
i: col
while [i > -1] [
append pos i
i: i - 1
]
names: 0
names: counter row col pos names
prin names prin " "
]
print ""
]
]

sum-find: function [
row
] [
sum: 0
repeat col row [
pos: reduce []
i: col
while [i > -1] [
append pos i
i: i - 1
]
names: 0
sum: sum + counter row col pos names
]
prin sum prin " "
]

counter: function [
row column
pos names
] [
sofar: column
path: reduce [] ;record of what was previously added
toadd: 1
while [not toadd > (column + 1)] [
sofar: sofar + pos/:toadd
insert path pos/:toadd
case [ ;these are the conditions
sofar = row [
names: names + 1
sofar: sofar - path/1
remove path
toadd: toadd + 1
]
sofar > row [
sofar: sofar - path/1
remove path
toadd: toadd + 1
]
(sofar < row) and (path/1 = 0) [ ;this is where toadd is subtracted from
l1i: none ;larger than 1 index in path
l1v: none ;larger than 1 value
l1pi; none ;larger than 1 index in pos
foreach x path [
if x > 1 [
l1i: index? find path x
l1pi: index? find pos x
l1v: x
break
]
]
either l1i = none [
toadd: toadd + 1
] [
repeat y l1i [
sofar: sofar - path/1
remove path
]
toadd: l1pi + 1
]]]]
names
]

print "rows:"
print name-find 25
print "sum:"
sum-find 23
</lang>

{{out}}
<pre>
rows:
1
1 1
1 1 1
1 2 1 1
1 2 2 1 1
1 3 3 2 1 1
1 3 4 3 2 1 1
1 4 5 5 3 2 1 1
1 4 7 6 5 3 2 1 1
1 5 8 9 7 5 3 2 1 1
1 5 10 11 10 7 5 3 2 1 1
1 6 12 15 13 11 7 5 3 2 1 1
1 6 14 18 18 14 11 7 5 3 2 1 1
1 7 16 23 23 20 15 11 7 5 3 2 1 1
1 7 19 27 30 26 21 15 11 7 5 3 2 1 1
1 8 21 34 37 35 28 22 15 11 7 5 3 2 1 1
1 8 24 39 47 44 38 29 22 15 11 7 5 3 2 1 1
1 9 27 47 57 58 49 40 30 22 15 11 7 5 3 2 1 1
1 9 30 54 70 71 65 52 41 30 22 15 11 7 5 3 2 1 1
1 10 33 64 84 90 82 70 54 42 30 22 15 11 7 5 3 2 1 1
1 10 37 72 101 110 105 89 73 55 42 30 22 15 11 7 5 3 2 1 1
1 11 40 84 119 136 131 116 94 75 56 42 30 22 15 11 7 5 3 2 1 1
1 11 44 94 141 163 164 146 123 97 76 56 42 30 22 15 11 7 5 3 2 1 1
1 12 48 108 164 199 201 186 157 128 99 77 56 42 30 22 15 11 7 5 3 2 1 1
1 12 52 120 192 235 248 230 201 164 131 100 77 56 42 30 22 15 11 7 5 3 2 1 1

sum:
1255
</pre>
=={{header|REXX}}==
=={{header|REXX}}==
This REXX version displays a nicely "balanced" numbers triangle as per this task's
This REXX version displays a nicely "balanced" numbers triangle as per this task's