[FATAL] failed to allocate memory


#1

I am constantly getting the “[FATAL] failed to allocate memory” error
message when I run the following code:
“$world=[]
$world+=((0…256).to_a+(0…256).to_a+(0…256).to_a).combination(3).to_a”
I know that there is not enough memory for the array. But is there any
other way to store this array?


#2

Regis d’Aubarede wrote in post #1153671:

Octavian Chiliment wrote in post #1153661:

“$world=[]
$world+=((0…256).to_a+(0…256).to_a+(0…256).to_a).combination(3).to_a”
But is there any other way to store this array?

Or, store in a string

============================
l=(0…255).to_a
res,sep="",""

(l*3).combination(3).each {|a|
res << sep
sep=";"
res << a.map {|a| a.chr }.join("")
}

res.size 300MB…


#3

Octavian Chiliment wrote in post #1153661:

“$world=[]
$world+=((0…256).to_a+(0…256).to_a+(0…256).to_a).combination(3).to_a”
But is there any other way to store this array?

Store in file :

open(“e.txt”,“w”) do |f|
l=(0…256).to_a
(l*3).combination(3).each {|a| f.puts a.inspect }
end


#4

Regis d’Aubarede wrote in post #1153674:

Regis d’Aubarede wrote in post #1153671:

Octavian Chiliment wrote in post #1153661:

“$world=[]
$world+=((0…256).to_a+(0…256).to_a+(0…256).to_a).combination(3).to_a”
But is there any other way to store this array?

Or, store in a list of bignum :

============================
MAX=255
MAX1=MAX+1
l=(0…MAX).to_a ; l=(l*3)

res=l.combination(3).map { |a|
a.inject(0) {|cpt,a| (cpt*MAX1+a) }
}

def decode(l,i)
v = l[i]
(1…3).map { r=(v%MAX1);v=v/MAX1;r }.reverse
end

============================