# Sleep for 1000 years

Some sleep commands implement a delay of an integer number of seconds. However, 232 seconds is only about 100 years. Bug! What if you need a larger delay?

Make a program or a function which waits for 1000 years, with an error of less than ±10%. Because it's too time-consuming to test, please explain how/why your solution works! (unless it's somehow obvious)

You don't need to worry about wasting CPU power - it can be a busy-loop. Assume that nothing special happens while your program waits - no hardware errors or power failures, and the computer's clock magically continues running (even when it's on battery power).

What the solution should do after the sleep is finished:

• If it's a program: terminate (with or without error) or do something observable by user (e.g. display a message or play a sound)

# C# (Visual C# Interactive Compiler), 38 37 bytes

this waits 1 + 2 + 3.. +77e5-1 + 77e5ms.

I got this 77e5 magic number using the formula (x+1)/2*x=3e13 where x results in approximately 7.745.967 which I shortened to 77e5.

To check if it still falls in the allowed range I did 1000*365.25*24*3600*1000/((77e5+1)/2*77e5) which is 1.064 aka 6.45% of target

update : 8e6 results in 0.98 more precise and less bytes.

for(var i=0;i++<8e6;)Thread.Sleep(i);


Try it online!

# Matlab, 12 bytes

pause(3e+10)


This will sleep for 951 years which is within 10% of 1000 years. Note that Matlab can sleep for a floating number of seconds.

This is my first ever answer on CodeGolf :)

# Rust, 55 bytes

||std::thread::sleep(std::time::Duration::new(2<<34,0))


Try it online! (or not, it will take ~1089 years to do anything interesting)

Rust's thread::sleep takes a Duration as an input, and those conveniently store the count of seconds as a u64.

# Red, 9 bytes

wait 3e10


Try it online!

# Tcl, 23 bytes

after 30000000000000000


Try it online!

# MSX-BASIC, 47 characters

1FORK=1TO31557600000:TIME=0
2IFTIME<50GOTO2
3NEXT


TIME is a MSX-BASIC system variable holding a 50Hz counter that can be initialized to any value at will. There are 31557600000 seconds in 1000 years (assuming one leap year every 4 years) so there you go.

## Zsh/Bash/Sh, 23,19,14,10 bytes

sleep 8e6h


-4 bytes thanks to @Grimmy

## Explanation

Linux sleep command can take a suffix of either s (seconds), m (minutes), h (hours), or d (days).

365250 days is equivalent to 1000 years

• sleep 3e10, sleep 8e6h, sleep 5e8m are all 10 bytes and within the 10% tolerance. – Grimmy Dec 16 '19 at 12:51
• @Grimmy Thank you! – smac89 Dec 16 '19 at 18:38

# RPL, 8 bytes

3E10WAIT


shall wait 3e10 seconds on, say, your hp48sx. Good the OP excluded hardware issues, so we can ignore the reboot at the end of Dec. 31st, 2088 (the date is reinitialized to Jan. 1st, 1989.)

For RPL/2, add one byte as a space is needed before WAIT.

I am surprised such commands are accepted anyhow…

Btw a challenge about 2763 years would allow us to use the factorial as in 14!WAIT.

# SmileBASIC, 19 bytes

@L
WAIT 12e7GOSUB@L


Waits 120 000 000 frames (around 21.2 days), and loops until the GOSUB stack overflows (after 16383 iterations)
This lasts 1038.32 years

• Implicit outer loop - this is a great idea! – anatolyg Dec 17 '19 at 11:13

# MathGolf, 15 bytes

{tï╜Ä_⌐_¬Wó+<}▲


Just like my top 05AB1E answer, it's ~8.879% too large.

Try it online with debugging argument -d to see what's going on.

Explanation:

There were a few difficulties to tackle here:

1. Apparently there is no way in MathGolf to access a value outside of the scope of a while-loop. I therefore had to push the initial timestamp inside the loop, and by using some duplicates and stack-rotates access it to check against the current timestamp.
2. After that I initially had {t_⌐_¬Wó+<}▲ (12 bytes) to overcome the issue mentioned at point 1. Unfortunately there are some bugs in MathGolf, so this required a leading 1, otherwise the do-while didn't work: 1{t_⌐_¬Wó+<}▲.
3. MathGold is built in Python, and since Python's List size is limited to 536,870,912 items, I therefore had to remove unused garbage from the stack instead of letting it grow by one additional item every iteration. (Since it executes roughly 5-10 iterations per ms on TIO, the stack size grows way too fast to last even close to 1000 years.) I did this by adding an if-statement in front of that initial duplicate, so I only duplicate it in the very first iteration. For some reason I could now also remove that 1 which was used as a bug-workaround..

Putting it all together gave me the 15-byter you see here, with the following code explanation:

{            }▲  # Do-while true with pop:
t               #  Push the current timestamp
ï              #  Push the current 0-based loop-index
╜             #  If it's falsey (so it's the first iteration):
Ä            #   Execute the following single command:
_           #    Duplicate this initial timestamp
⌐          #  Rotate the stack, so the bottom item is at the top
_         #  Duplicate it
¬        #  And rotate the stack back, so its both at the top and bottom now
Wó      #  Push 35, and then pop and push 2**35: 34359738368
+     #  Add it to the timestamp of the first iteration
<    #  And check whether it's still lower than the current timestamp


# Python 3, all platforms, 91 bytes

from datetime import *;z=datetime.now()+timedelta(days=365242)
while z>datetime.now(): pass


The rules say simple termination is fine, which happens after the while loop is done. I couldn't put it all on one line, because the while loop has to start on its own line for the interpreter to recognize it. I also didn't want to use sleep since the challenge specifically calls that out as the problem.

• The spaces before * and after : are not necessary. Instead of pass you can use a simple value, the shortest would be a single digit number. – manatwork Jan 6 at 9:53

# CJam, 15 14 bytes

-1 byte because I forgot that e[numeric literal] existed.

es3e13+{_es>}g


Please don't try it online, it won't work!

This waits in a while loop until the current Unix timestamp is equal to the timestamp at the beginning of execution plus 3*10^13 milliseconds (or ~951.3 years).

# at, 19 bytes

at now + 1000 years

• @JoKing I think it's linux command at – Pierre Cathé Dec 13 '19 at 13:03
• You don't need the plural on "years" for the date parsing here, nor the spaces actually: at now+1000year is 15 bytes and does the same work. – Caleb Dec 15 '19 at 5:59
• @ceving @Caleb I'm not familiar with this language, but why not use at now+999year? An error of less than ±10% is allowed. – qarz Oct 16 at 19:57

# Scratch (scratchblocks3 syntax), 30 bytes

It's the obvious solution but it's surprisingly short for a Scratch program. Sleeps for exactly 951.3 years + a few milliseconds.

when gf clicked
wait(3e10)secs


# VBA, 27 bytes

This program adds an approximation of 1000 years, in days, to the current time, and instructs the program to wait until that time is encountered.

Application.Wait 365242+Now


For for a more accurate result, the below may be used at a cost of 41 bytes.

Application.Wait DateAdd("yyyy",1000,Now)