10
\$\begingroup\$

Introduction

Compute is a esoteric joke language.

From the esolangs entry:

Compute has no required syntax and has the power to solve any and all problems. It is smart enough to interpret any human language (English, Spanish, Latin, etc), any programming language (C++, Java, brainfuck, etc), or any kind of data you can think of. The only downfall is that there is absolutely no I/O.

Some example programs

Hello World

A basic Hello World program

What is love?

Determines was love is (baby don't hurt me).

When will we ever graduate?

Determines the exact date of this site to get out of beta.

The Challenge

Your task is to write a full Compute interpreter. This sounds pretty hard, but keep in mind that Compute has absolutly no I/O. So your interpreter will just sleep one second for every line in the input program and output \n\nDone. after this (this is the only exception to the no I/O thing).

You can find the official interpreter at the bottom of this site.
Note that the official interpreter pauses one second for every character in the given source code. To avoid long waiting times while testing your interpreter with meaningful questions we stay with lines in this challenge.

Rules

  • The input might contain multiple lines seperated by a \n. There will always be at least one line.
  • Unlike the official implementation you don't have to take a file as input. You can take the Compute program in any form of input you want.
  • The only output allowed is \n\nDone.. A trailing newline is allowed.
  • Function or full program allowed.
  • Default rules for input/output.
  • Standard loopholes apply.
  • This is , so lowest byte-count wins. Tiebreaker is earlier submission.
\$\endgroup\$
8
  • 1
    \$\begingroup\$ Inevitably reminded me of this \$\endgroup\$
    – Luis Mendo
    Commented Feb 15, 2016 at 17:33
  • 14
    \$\begingroup\$ Well, we don't need a program to tell us when we're going to graduate. We already know that it's the 26th. \$\endgroup\$
    – Doorknob
    Commented Feb 15, 2016 at 17:40
  • 7
    \$\begingroup\$ @Doorknob, of what century? \$\endgroup\$
    – msh210
    Commented Feb 15, 2016 at 17:42
  • 1
    \$\begingroup\$ @DenkerAffe I think you should make it clear that the challenge does not exactly match the language. \$\endgroup\$ Commented Feb 15, 2016 at 17:55
  • 10
    \$\begingroup\$ @msh210, no, that is the century. \$\endgroup\$ Commented Feb 15, 2016 at 19:00

14 Answers 14

5
\$\begingroup\$

05AB1E, 16 15 14 13 bytes

Code:

[Ig>#w’

D€µ.

Explanation:

[        # Starts an infinite loop
 I       # Input string
  g>     # Length + 1
    #    # If equal to 1, break out of the loop
     w   # Wait 1 second

This part is equivalent to "\n\nDone.":

      ’  # Push "\n\nDone." on top of the stack

D€µ.     # The compressed string is ended implicitly
         # Implicit, print top of the stack

Try it online!

Uses CP-1252 encoding.

\$\endgroup\$
4
\$\begingroup\$

Oration, 117 bytes

I need time!
To iterate, input().
Inhale.
Now sleep(1).
Backtracking.
Boring,
boring.
Listen!
Capture Done.
Carry on!

Let's explain this. First, this transpiles to:

import time
while input():
    time.sleep(1)
print("\n")
print("\n")
print("Done")

Still confused? Let's put it like this:

I need time!

Imports the module time.

To iterate, input().

This is a while loop whose condition is input().

Inhale.

Our program needs to breathe now, and inhale, whilst less healthy, is golfier.

Now sleep(1).

Now take the most recent module imported and appends .sleep(1) to it.

Backtracking.

Let's exit the while loop.

Boring,
boring.

Prints two newlines.

Listen!

Begins capturing a string.

Capture Done.

Adds Done. to the captured string.

Carry on!

Finishes capturing string.

\$\endgroup\$
3
  • 3
    \$\begingroup\$ Looks like a fun language. Would you add a link to an interpreter + docs? \$\endgroup\$
    – Denker
    Commented Feb 15, 2016 at 21:24
  • \$\begingroup\$ @DenkerAffe The docs and interpreter can both be found in the heading I just edited in. \$\endgroup\$ Commented Feb 15, 2016 at 21:25
  • \$\begingroup\$ @Conor Thanks, gonna have a look at it. :) \$\endgroup\$
    – Denker
    Commented Feb 15, 2016 at 21:30
4
\$\begingroup\$

Javascript ES6, 46 45 bytes

a=>setTimeout(x=>alert`

Done.`,a.length*1e3)

Thanks to ӍѲꝆΛҐӍΛПҒЦꝆ for saving one byte

Assumes an array as input.

As both ӍѲꝆΛҐӍΛПҒЦꝆ and edc65 have pointed out you can write the following, but it won't save any bytes:

a=>setTimeout("alert`\n\nDone`",a.length*1e3)
\$\endgroup\$
5
  • 1
    \$\begingroup\$ 1e3 is better than 10e2. \$\endgroup\$ Commented Feb 15, 2016 at 19:24
  • \$\begingroup\$ Also, convert the arrow function to a string. See codegolf.stackexchange.com/a/60960/41247 \$\endgroup\$ Commented Feb 15, 2016 at 19:27
  • \$\begingroup\$ @ӍѲꝆΛҐӍΛПҒЦꝆ I'm not sure that would work. Since he already has a template string, you would need to escape it \$\endgroup\$
    – Cyoce
    Commented Feb 15, 2016 at 19:47
  • \$\begingroup\$ @ӍѲꝆΛҐӍΛПҒЦꝆ 1e3 is better than 10e2 can't believe i missed that . \$\endgroup\$ Commented Feb 15, 2016 at 20:28
  • \$\begingroup\$ @edc65 You are not the first to talk about it, ӍѲꝆΛҐӍΛПҒЦꝆ also mentioned it. :-) \$\endgroup\$ Commented Feb 22, 2016 at 19:26
4
\$\begingroup\$

Bash + coreutils, 28

sleep `wc -l`
echo "

Done."

Sleeps 1 second for every line. Use wc -c instead for every byte, or wc -m instead for every character.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Shouldn't there be an extra newline? \$\endgroup\$ Commented Feb 16, 2016 at 8:35
  • \$\begingroup\$ @immibis Yes - you're right - fixed. \$\endgroup\$ Commented Feb 16, 2016 at 17:12
3
\$\begingroup\$

Pyth, 15 14 bytes

.dcl.z1b"Done.

(You can try it online, but there's really no point in doing so.)

\$\endgroup\$
7
  • \$\begingroup\$ You are missing the period after Done (which is pretty funny since you told someone the same on another answer) :P \$\endgroup\$
    – Denker
    Commented Feb 15, 2016 at 18:00
  • \$\begingroup\$ @DenkerAffe Thanks. (Byte count was correct, though.) \$\endgroup\$ Commented Feb 15, 2016 at 18:01
  • \$\begingroup\$ @muddyfish Thats what the challenge says. The official interpreter goes char-wise, but I changed it to lines to avoid waiting times. \$\endgroup\$
    – Denker
    Commented Feb 15, 2016 at 18:07
  • \$\begingroup\$ @DenkerAffe Ok now our entries our exactly the same. Whos to keep? I'm going to assume Pietu1998 because they were correct first \$\endgroup\$
    – Blue
    Commented Feb 15, 2016 at 18:08
  • \$\begingroup\$ Is b necessary? \$\endgroup\$
    – busukxuan
    Commented Feb 15, 2016 at 20:45
3
\$\begingroup\$

JavaScript Shell REPL, 38 bytes

As a function that accepts the program as a string argument and returns the result:

s=>sleep(s.split`
`.length)||`

Done.`

29 bytes if the function can accept its input in the form of an array of lines, or if it should sleep 1 second per character:

s=>sleep(s.length)||`

Done.`

34 bytes if it should also be more like a program and explicitly print Done:

s=>sleep(s.length)||print`

Done.`

This works for me in the standalone Spidermonkey interpreter.

\$\endgroup\$
2
\$\begingroup\$

Perl, 21 + 1 = 22 bytes

sleep 1}{$_="\n\nDone."

Requires the -p flag:

$ perl -pe'sleep 1}{$_="\n\nDone."' <<< $'a\nb\nc'


Done.              
\$\endgroup\$
2
\$\begingroup\$

Python 3, 58 bytes

import time
while input():time.sleep(1)
print("\n\nDone.")
\$\endgroup\$
2
  • \$\begingroup\$ Just wanna point this out, it would be 2 Bytes shorter in python 2, print"\n\nDone" \$\endgroup\$
    – Random Guy
    Commented Feb 15, 2016 at 23:44
  • \$\begingroup\$ Oh yeah, I forgot... Sorry. \$\endgroup\$
    – Random Guy
    Commented Feb 15, 2016 at 23:46
2
\$\begingroup\$

MATL, 17 bytes

10c'Done.'`jt?1Y.

A trailing empty line (followed by newline) is used to mark end of input. This is needed in MATL because input is interactive and each input ends with a newline.

Try it online!

10c           % push newline character
'Done.'       % push string
`             % do...while
  j           % input string
  t           % duplicate
  ?           % if non-empty
    1Y.       % pause for 1 second
              % loop condition is the current string. If non-empty: next iteration
              % If empty: exit loop and print stack contents. There are two strings
              % and a newline is printed after each, so the desired output is obtained
\$\endgroup\$
2
  • \$\begingroup\$ Are you missing the period after Done? \$\endgroup\$ Commented Feb 15, 2016 at 17:52
  • \$\begingroup\$ @Pietu1998 Whoops. Corrected. Thanks! \$\endgroup\$
    – Luis Mendo
    Commented Feb 15, 2016 at 17:54
2
\$\begingroup\$

QBasic, 54 bytes

LINE INPUT x$
IF x$=""GOTO 1
SLEEP 1
RUN
1?
?
?"Done."

Takes the program line by line from user input, terminated by a blank line. Abides by the letter of the law, though possibly not the spirit, by pausing 1 second after reading each line. (The specification doesn't technically say that the pauses all have to come after the input is completed.) If this is considered too shady, here's a 64-byte version that pauses after the whole program has been input:

DO
LINE INPUT x$
IF x$=""GOTO 1
t=t+1
LOOP
1SLEEP t
?
?
?"Done."

Bonus version with file I/O (87 bytes):

INPUT f$
OPEN f$FOR INPUT AS 1
1LINE INPUT #1,x$
SLEEP 1
IF 0=EOF(1)GOTO 1
?
?
?"Done."
\$\endgroup\$
1
\$\begingroup\$

Ruby, 32 bytes

$<.map{sleep 1}
puts"\n\nDone."

Reads from stdin.

\$\endgroup\$
1
\$\begingroup\$

OCaml, 61 bytes

fun a->List.iter(fun _->Unix.sleep 1)a;print_string"\n\nDone"

Assumes the input is a list.

\$\endgroup\$
0
\$\begingroup\$

awk, 34 bytes

END{print"\nDone."|"cat;sleep "NR}

As there is no I/O and the final outcome is inevitable, the Done. part is outputed right in the beginning.

$ awk 'END{print"\nDone."|"cat;sleep "NR}' file

Only way to sleep in awk is to use system sleep. Shortest way to invocate it is to print|"sleep "NR and we might as well abuse that useless print.

\$\endgroup\$
0
\$\begingroup\$

Jelly, 12 bytes

ỴLœS@⁷⁷“ẋḲp»

Try it online!

Note: Please do not suggest putting the ⁷⁷ in the compressed string, it will make it longer (“¡OÑL[Ṁ»).

Explanation:

ỴLœS@⁷⁷“ẋḲp» Main link. Arguments: z.
ỴL           The number of lines in z. (x)
     ⁷       Newline ("\n") (y)
  œS@        After sleeping for x seconds, return y.
      ⁷      Newline ("\n")
       “ẋḲp» Compressed string ("Done.")
\$\endgroup\$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.