JAVA, 81 79 78 bytes
JAVA (HotSpot) 71 70 bytes
Shorter than other Java answers at the time I posted (81, later 79 bytes):
class A{public static void main(String[]a){String x="1";for(;;)x+=x.intern();}}
As suggested by @Olivier Grégoire, a further byte can be saved:
class A{public static void main(String[]a){for(String x="1";;)x+=x.intern();}}
Placing x+=x.intern()
as the for loop increment would not help anything, because a semicolon is still required to end the for statement.
As suggested by @ETHproductions, just using x+=x
works too:
class A{public static void main(String[]a){String x="1";for(;;)x+=x;}}
Which can also benefit from @Olivier Grégoire's tip:
class A{public static void main(String[]a){for(String x="1";;)x+=x;}}
My only misgivings about that is that it is not guaranteed to allocate data on the heap, as an efficient JVM can easily realize that x
never escapes the local function. Using intern()
avoids this concern because interned strings ultimately end up stored in a static field. However, HotSpot does generate an OutOfMemoryError
for that code, so I guess it's alright.
Update: @Olivier Gregoire also pointed out that the x+=x
code can run into StringIndexOutOfBoundsException
rather than OOM
when a lot of memory is available. This is because Java uses the 32-bit int
type to index arrays (and Strings are just arrays of char
). This doesn't affect the x+=x.intern()
solution as the memory required for the latter is quadratic in the length of the string, and should thus scale up to on the order of 2^62 allocated bytes.
(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\$