Ceylon, 55 54 35 bytes
shared void r(){variable Object x=0;while(0<1){x=[x];}}
This is a simple while loop, which creates a one-element tuple containing the previous value, i.e. an ever-growing linked list.
I get an OutOfMemoryError (with the default JVM settings on my computer) after:
real 5m42.727s
user 21m31.200s
sys 0m3.472s
5m42s (using 21 minutes of processor time, says time
).
Even shorter is the "functional" approach (which in effect does exactly the same):
shared void r(){loop<Object>(0)((x)=>[x]).each(noop);}
Unfortunately I need the type parameter here, otherwise Ceylon assumes Integer
(which is the type of 0
) and complains that [0]
is not an Integer.
The second version is much slower (I've let it run overnight):
real 197m26.677s
user 770m9.300s
sys 1m23.744s
A different approach is just filling a really big sequence of integers:
shared void r(){max((1:9^9)*.not);}
1:9^9
is a Measure<Integer>
(an Iterable containing 9^9 elements, starting with 1), by itself not having lots of memory (just the two numbers). But the *.not
attribute spread creates a big ArraySequence with the value of i.not
for each element of the Iterable. We need to do something with the result (otherwise the compiler complains that this is not a statement), therefore the max(...)
. The max
function is never called here, because this gives an OutOfMemoryError (with "GC overhead limit exceeded") after 6 minutes while trying to build and fill the array:
real 6m23.948s
user 23m46.956s
sys 0m5.200s
(reduce conj [] (range))
(Clojure) gets up to 737mb, then just stops growing. Idk how it's not continually going up. It "thinks" I want to print the entire list at the end, so it shouldn't be throwing anything away. Very frustrating. \$\endgroup\$