Code Golf Asked on November 21, 2021
You are Desmond Hume. For the last 3 years, you and your partner, Kelvin, have been slave to a computer that requires a very specific sequence to be entered into it every 108 minutes to save the world.
4 8 15 16 23 42
Your partner died 40 days ago (due to an unfortunate accident involving Kelvin’s head and a big rock), and you have no one to talk to. No one to enter the numbers for you. No one to break the monotony. At first it wasn’t too bad, but you can’t handle the silence anymore. And if you have to listen to “Make Your Own Kind Of Music” one more time, you’re going to scream.
You decide that You need to get out. To escape. You decide that you will build a raft and sail off the island. But then you realize the bad news: you’re stuck here. You need to keep saving the world.
But then you realize the good news: You are a programmer! You can automate saving the world! Excited, you run over to the computer, and, using your trusty python skills, you whip up a quick script to enter the numbers for you.
import time
while True:
print "4 8 15 16 23 42"
time.sleep(60 * 107)
Quick, simple, reliable, short, and easy. Everything that a good python script should be. But then, when you try to test it, you get an error.
Bad command or file name.
Huh, strange. Oh well, let’s try c++.
#include <iostream>
#include <unistd.h>
int main()
{
while (true)
{
std::cout << "4 8 15 16 23 42" << std::endl;
sleep(60 * 107);
}
}
No! C++ isn’t found either. You try every language you can think of. Javascript, Ruby, Perl, PHP, C#. Nothing. This computer was made before all of the popular languages of the day.
You must write a program that will:
1) Print exactly this: “4 8 15 16 23 42” (without quotes)
2) Wait some time between 104 and 108 minutes. (According to The Lost Wiki)
3) Repeat forever. (Or until you realize that this is all an elaborate scam, and that you’re stuck in a weird limbo due to lazy writing, and asking questions that you don’t have answers for. Thanks JJ Abrams!)
However there is a catch: You MUST use a language that the computer in the swan station would actually be capable of running. Assuming that
A) The computer was up to date at the time of construction,
B) There have been no updates to the computers software, and
C) There is no internet connection available (Meaning you can’t download Golfscript…),
and making our best guess for the construction date of The Swan Station, (Again, The Lost Wiki.)
This means you have to use a language that was first released on or before Dec 31, 1977.
A few rule clarifications:
Including libraries is OK, but the same rule applies (libraries must be pre-1977).
You do not have to worry about OS compatibility.
If you use system
, or your languages equivalent, you must prove that any system commands you use would have been available before 1978. A wikipedia article is probably the best way to prove this.
It doesn’t matter when you start the program, just as long as it ends up in a pattern of alternating printing and sleeping. (print-sleep-print-sleep… and sleep-print-sleep-print… are both acceptable.)
This is Code-Golf, so shortest answer in bytes wins.
ABC: The Python in 1975!
WHILE 1=1:
PUT now IN(a,b,c,d,e,f)
PUT a*518400+b*43200+c*1440+d*60+e IN x
WRITE "4 8 15 16 23 42"/
PUT x IN y
WHILE y-x<104:
PUT now IN(a,b,c,d,e,f)
PUT a*518400+b*43200+c*1440+d*60+e IN y
Answered by user92069 on November 21, 2021
Yes, the leading whitespace is significant. Compile and run like cobc -x save.cob; ./save
. (The -x
option produces an executable as opposed to a shared lib and thus I don't think it needs to be counted.)
IDENTIFICATION DIVISION.
PROGRAM-ID.S.
PROCEDURE DIVISION.
PERFORM UNTIL 1<>1
DISPLAY"4 8 15 16 23 42"
CALL"C$SLEEP"USING BY CONTENT 6402
END-PERFORM.
GOBACK.
If we want to be boring, we can add the --free
compilation option for free-format code, then 158 + 6 = 164 bytes but this would be unlikely to work back in '77.
IDENTIFICATION DIVISION.
PROGRAM-ID.S.
PROCEDURE DIVISION.
PERFORM UNTIL 1<>1
DISPLAY"4 8 15 16 23 42"
CALL"C$SLEEP"USING BY CONTENT 6402
END-PERFORM.
GOBACK.
Answered by cat on November 21, 2021
Shorter than the other C solution, and thus not a duplicate. I actually wrote this before I noticed Digital Trauma's (nearly) identical comment on the other C solution.
main(){for(;;sleep(6240))puts("4 8 15 16 23 42");}
Answered by cat on November 21, 2021
Run this full program with a68g save.a68
, using algol68g
.
ALGOL doesn't have a builtin way to sleep but we can run essentially /bin/sleep
:
DO print("4 8 15 16 23 42");system("sleep 6380")OD
Old answer:
ALGOL doesn't have a sleep builtin, so we can abuse
ping
which is surely on a Unix of the time (idea from here) for7469 bytes.DO print("4 8 15 16 23 42");system("ping 1.0 -c1 -w6240>/dev/null")OD
Answered by cat on November 21, 2021
This worked in STSC's APL*PLUS and in IPSA's SharpAPL in 1977, and while modern APLs have a ton of new features, this happens to still work on all major APLs today:
+4 4 7 1 7 19
→×⎕DL 6360
The first line prints the cumulative sum of the shown numbers, which are the required numbers. The second line delays 6360 seconds (106 minutes), then takes the signum of that (1, obviously), and goes to that line (i.e. the previous, number-printing one).
However, APL360 (the APL for IBM System/360) from 1966 actually beats it by one byte (tested on the free IBM/370 emulator):
+4 4 7 1 7 19
5⌶19E5
→1
The sleep I-beam ("IBM" – get it?) takes the wait-time in jiffies of 1⁄300th of a second, so we wait 19×105 jiffies = 105 minutes and 331⁄3 second.
Answered by Adám on November 21, 2021
Though FORTH-79 is the earliest standardized version, the language was in development starting in 1968, and was usable on the IBM 1130. It was used on other systems as well before 1977 came around. I may do a bit more research to ensure these words were all available, but I'm fairly certain this is basic enough to have existed by then. These were all available by FORTH-79, for sure.
Loops forever, waiting 6420000 milliseconds between string printing. No newline is printed.
: F 0 1 DO 6420000 MS ." 4 8 15 16 23 42" LOOP ; F
Answered by mbomb007 on November 21, 2021
43 bytes
: x
echo 4 8 15 16 23 42
sleep 6480
goto x
Since the Bourne shell, though it existed in 1977, wasn't in a released version of Unix until v7 in 1979. The original Unix shell didn't have any fancy loop control commands. (If you wanted to end a loop, you could use the if
command to skip the goto.)
Answered by Random832 on November 21, 2021
My first attempt at code golf, here we go!
f w "4 8 15 16 23 42" h 6420
MUMPS is still a popular language for EHR software, created by Massachusetts General Hospital in Boston. Most known implementation is Epic Systems in Verona, WI.
Answered by Andrew Robinson on November 21, 2021
Talking about the 70s, it's mandatory to honor Unix and the hardware where it all started!
s:mov $1,r0
sys write;m;18
mov $6240.,r0
sys 43
br s
m:<4 8 15 16 23 42;>
You can easily run it here (but first you have to rediscover the joys of using ed
to insert the text - in my specific case, I even had to discover how to actually edit text in it :)
).
Assembled it becomes 108 bytes.
# cat mini.as
s:mov $1,r0
sys write;m;18
mov $6240.,r0
sys 43
br s
m:<4 8 15 16 23 42;>
# as mini.as
# ls -l a.out mini.as
-rwxrwxrwx 1 root 108 Oct 10 12:36 a.out
-rw-rw-rw- 1 root 74 Oct 10 12:36 mini.as
# od -h a.out
0000000 0107 0022 0000 0000 0018 0000 0000 0000
0000020 15c0 0001 8904 0012 0010 15c0 0004 8923
0000040 01f7 2034 2038 3531 3120 2036 3332 3420
0000060 3b32 0000 0000 0000 0002 0000 0000 0000
0000100 0000
0000120 0000 0000 0073 0000 0000 0000 0002 0000
0000140 006d 0000 0000 0000 0002 0012
0000154
# ./a.out
4 8 15 16 23 42;
Answered by Matteo Italia on November 21, 2021
1?"4 8 15 16 23 42":fOa=1to185^3:nE:rU
CBM BASIC 1.0 was introduced with the Commodore PET in October 1977. Commands would normally be shown in uppercase and CBM graphics characters, but I've listed them here in lowercase + uppercase for the sake of ease (both mine and yours! :-)). Note also that the ^ would actually be displayed as ↑. Detokenized, after listing this with LIST
this would result in:
1 PRINT "4 8 15 16 23 42":FOR A=1 TO 185^3:NEXT:RUN
The PET's 6502 ran at 1MHz, so this should take around 105 minutes or so to complete.
Edit: Realized that nested loops weren't really necessary and I'd miscomputed my tokens. Still not enough to win (and too late, to boot), but at least it's better.
Answered by Mark on November 21, 2021
For sure, Desmond and Kelvin would have had an Altair 8800 (or an emulator) just for fun. Altair Basic (from some guy named Bill Gates, of some little two-man start-up called Micro-Soft) squeaks in with a 1975 release.
Desmond would need to fine tune a bit to ensure the inner FOR
loop lasts one minute. Back then, everybody knew busy loops were wrong, but everybody used them!
1 REM ADJUST "D" AS REQUIRED
2 LET D = 1000
3 PRINT "4 8 15 16 23 42"
4 FOR A = 0 TO 105 * 60
5 REM THIS LOOP SHOULD LAST ONE MINUTE +/- 0.05 SECONDS
6 FOR B = 0 TO D
7 LET C = ATN(0.25)
8 NEXT
9 NEXT
10 GOTO 3
As an alternative, Desmond could install the 88-RTC board (assembled from components!: http://www.classiccmp.org/altair32/pdf/88-virtc.pdf) and get access through interrupts to a real time clock running off the power line or internal crystal.
He would need to write an interrupt routine to handle the clock input, which in turn could update a port, say every 59 seconds bring to ground for a second, then raise high.
Altair Basic had a WAIT
function, so the code would be simplified to something like the following (I couldn't find a port listing, so I just chose 125 in the hopes it would be unused.):
1 PRINT "4 8 15 16 23 42"
2 FOR A = 0 TO 105 * 60
3 WAIT 125,0
4 WAIT 125,255
5 NEXT
6 GOTO 1
This was actually a fun little question, going back into some really rudimentary computers. The patience those old-timers (including me) must have had!
Answered by user15259 on November 21, 2021
Unfortunately, I haven't managed to find an online copy of The LOGO System: Preliminary Manual (1967) by BBN, or any references by the MIT Logo Group (1960s+). Apple Logo by LCSI is a bit too recent (~1980). However, based on online books, some variation of the following probably worked at the time. Note that WAIT 60 waits for 1 second, not 60.
TO a
LABEL "l
PRINT [4 8 15 16 23 42]
WAIT 381600
GO "l
END
a
We can do a bit better with tail call optimization, though this was probably not available at the time.
TO a
PRINT [4 8 15 16 23 42]
WAIT 381600
a
END
a
Answered by Uri Granta on November 21, 2021
PROGRAM S;USES CRT;BEGIN WHILE TRUE DO BEGIN WRITELN('4 8 15 16 23 42');DELAY(6300000);END;END.
Ungolfed version:
PROGRAM S;
USES CRT;
BEGIN
WHILE TRUE DO
BEGIN
WRITELN('4 8 15 16 23 42');
DELAY(6300000); { 105 minutes * 60 seconds * 1000 milisseconds }
END;
END.
Answered by Rodolfo Dias on November 21, 2021
(do()(())(print"4 8 15 16 23 42")(sleep 6360))
All constructions taken from 1974 reference manual (PDF). Not tested though as I don't have a MacLisp interpreter.
Answered by Uri Granta on November 21, 2021
PROGRAM D
2 WRITE (*,*) '4 8 15 16 23 42'
CALL SLEEP(6420)
GOTO 2
END
It is certain that the computer in question had the FORTRAN compiler, as it dominated scientific and engineering fields in the era. I was born 18 years after the eponymous year, but during my math program in university we learned FORTRAN. One fun lecture we learned how to program on punching cards. It's not that easy to format it correctly here, there should be 6 blankspaces before each command and I could only find a reference to the Sleep-function for Fortran 77 but it should have existed already in Fortran IV and 66.
PS: We could scrap off one Byte by using label 1 instead of label 42.
PPS: If the computer in question uses punching-cards for program input you're all out of luck and the bytes don't matter anymore :D .
Answered by Bersaelor on November 21, 2021
data;
file stdout;
a:;
put "4 8 15 16 23 42";
a=sleep(6300,1);
goto a;
run;
Not a typical golfing language, but I think it qualifies for this challenge, assuming that file stdout
was valid in 1977-era SAS.
Improvements:
data _null_;
--> data;
saves 7 characters (and now produces an empty dataset as well as printing to stdout).Answered by user3490 on November 21, 2021
Been around since 1972
|i|[i:=0.[i<5] whileTrue: [(Delay forSeconds: 6480) wait.Transcript show: '4 8 15 16 23 42'.]]fork
No experience with this one, saw it on wikipedia :P
Looked it up online how to loop and delay, syntax should be correct but couldn't find a way to run it.
It should print the sequence every 108 minutes, but it doesn't state that it has to be 108 minutes.
This could make the code shorter
|i|[i:=0.[i<5] whileTrue: [Transcript show: '4 8 15 16 23 42'.]]fork
Code will print the sequence with no interval, so its guaranteed that it will print after 108 mins too.
Answered by Teun Pronk on November 21, 2021
TECO (Text [previously Tape] Editor and Corrector) is a text editor originating in 1962. It can also be used to run standalone programs. It's the state-of-the-art editor for PDPs, VAXen, etc.
According to the TECO manual, the ^H
command gives the time of day. Make sure to check your operating system and power supply, as the unit of time may vary according to your machine:
OS/8: ^H = 0
RT-11: ^H = (seconds since midnight)/2
RSTS/E: ^H = minutes until midnight
RSX-11: ^H = (seconds since midnight)/2
VAX/VMS: ^H = (seconds since midnight)/2
TOPS-10: ^H = 60ths of a second since midnight
(or 50ths of a second where 50 Hz power is used)
The following program works on systems where time of day is measured in seconds/2:
I4 8 15 16 23 42
$<HT^HUA<^H-QAUDQD"L43200%D'QD-3180;>>
Note that ^H
and $
should be entered by striking, respectively, CONTROL-H and ESCAPE.
The numbers in the program can be adjusted for the following machines:
(number) 43200 3180
RSTS/E 1440 106
TOPS-10 60 Hz 5184000 381600
TOPS-10 50 Hz 4320000 318000
OS/8 goodbye, world...
Answered by feersum on November 21, 2021
while echo 4 8 15 16 23 42;do sleep 6420;done
Answered by Doorknob on November 21, 2021
main(){while(1)puts("4 8 15 16 23 42"),sleep(6360);}
Answered by Jeff Stevens on November 21, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP