Anonymous user
9 billion names of God the integer: Difference between revisions
9 billion names of God the integer (view source)
Revision as of 06:38, 24 December 2021
, 2 years agoslightly faster red implementation
mNo edit summary |
m (slightly faster red implementation) |
||
Line 3,688:
=={{header|Red}}==
<lang Rebol>Red [Purpose: "9 billion names of god with cache"]
cache: [ ;[rem start val]
[1 1 1] [2 1 1] [2 2 1]
]
reset: [cache: [[1 1 1] [2 1 1] [2 2 1]]]
name-finder: function [max /every] [
repeat row max [
case [
row = 1 [if every [print "1"] continue]
row = 2 [if every [prin "1 1"] continue]
every [print ""]
]
row-cache: make block! row - 1
repeat col row [
if (not every) and (row = max) [print val + sum row-cache]
]
not col = 1 [
rem: row - col
start: min rem col
val: cache-search rem start
]
true val: 1
]
mem: reduce [row col val]
append/only cache mem
append row-cache val
if every [prin [val ""]]
]]]
cache-search: function [rem start] [
val: 0
colvals: reduce []
if (mem/1 = rem) and (mem/2 <= start) [
append colvals mem/3
]
]
return val
]
print "rows:"
print name-
reduce reset
print {
sum:}
name-finder 23
</lang>
|