Commodore BASIC (Commodore C64/128, C16/+4, VIC-20, CBM/PET), 92 Tokenised BASIC bytes
A thousand years in the Gregorian Calendar at least 365,240 days, plus two or three days depending on the 400 year rule, whereby each start of a new century is a leap year but only once every 400 years, with the year 2000 being a leap year, but 1900 and 2100 are not leap years. As the next leap year at the start of a century will be 2400 I will assume that you want to sleep for 365,242 days. How do we do this with Commodore BASIC?
A day according to a Commodore BASIC interpreter is 5,184,001 jiffies (or 1/60 of a second), which is actually one 60th too many, so over 365,242 days, we are out by the same number of jiffies, which is about 101 minutes, so we will be sleeping for about 1000 years + 101 minutes based on our assumptions above. You can see an explanation of the Commodore TI and TI$ functions on the 8-BIT Show and Tell YouTube channel here.
Firstly, we need to take a copy of the current system time, which one can set in HHMMSS
in a 24 hour format like TI$="123000"
- we then need a busy loop to wait a second so that the copy of the current time and the system timer are not the same. I am also setting the number of days to wait in the W
variable, which is 365241 as our counter D
starts at zero.
0 C$=TI$: W=365241: D=0: FOR I=0 TO 937: NEXT I
Now, we need to wait until TI$ is equal to our copy stored in C$, each time it is we know that it has been 24 hours and 1/60th of a second. When this is true, we can jump to a sub routine that will add 1 to the number of days, and return. Note that using STEP 0
in our FOR/NEXT
loop creates an endless loop with our break condition being in the subroutine on line 2.
1 FOR I=0 TO 1 STEP 0: ON -(TI$=C$) GOSUB 2: NEXT I
When we jump to the subroutine at line 2, TI$ and C$ may still contain the same values, so we need a busy loop until TI$ is one second ahead again of C$. Then we can add 1 to our day counter, and if the counter has fewer days than our W
variable set above, we will return from our sub-routine which will wait again until another 24 hours and 1 jiffy has passed.
2 ON -(TI$=C$) GOTO 2: D=D+1: IF D<W THEN RETURN
The full crunched listing (with removed whitespaces) would look like this:
0C$=TI$:W=365241:D=.:FORI=.TO1E3:NEXT
1FORI=.TO1STEP.:ON-(TI$=C$)GOSUB2:NEXT
2ON-(TI$=C$)GOTO2:D=D+1:IFD<WTHENRETURN
fortune
CLI app) \$\endgroup\$Because it's too time-consuming to test,
: If your implementation is based on polling a real‑time clock (RTC), you may simply adjust the RTC to a date/time about 1 kiloyears in the future. In UNIX‑like environments like Linux or FreeBSD you can invoke thedate
command‑line utility to that end.What if you need a larger delay?
: Easy, employ time dilation. 😉 \$\endgroup\$