Golf a Compute interpreter

9

1

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.

Denker

Posted 2016-02-15T17:31:32.003

Reputation: 6 639

1

Inevitably reminded me of this

– Luis Mendo – 2016-02-15T17:33:40.600

@LuisMendo This is glorious! I almost lost it. – Denker – 2016-02-15T17:36:31.827

14Well, we don't need a program to tell us when we're going to graduate. We already know that it's the 26th. – Doorknob – 2016-02-15T17:40:13.207

I think the interpreter sleeps a second for each character in source code. – PurkkaKoodari – 2016-02-15T17:42:29.037

7@Doorknob, of what century? – msh210 – 2016-02-15T17:42:31.297

1@DenkerAffe I think you should make it clear that the challenge does not exactly match the language. – PurkkaKoodari – 2016-02-15T17:55:54.683

@DenkerAffe Pietu1998 means the chars/lines thing. – Lynn – 2016-02-15T18:56:52.203

9@msh210, no, that is the century. – Peter Taylor – 2016-02-15T19:00:30.630

Answers

5

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.

Adnan

Posted 2016-02-15T17:31:32.003

Reputation: 41 965

4

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.

Neil

Posted 2016-02-15T17:31:32.003

Reputation: 95 035

4

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)

andlrc

Posted 2016-02-15T17:31:32.003

Reputation: 1 613

11e3 is better than 10e2. – Mama Fun Roll – 2016-02-15T19:24:25.297

Also, convert the arrow function to a string. See http://codegolf.stackexchange.com/a/60960/41247

– Mama Fun Roll – 2016-02-15T19:27:42.390

@ӍѲꝆΛҐӍΛПҒЦꝆ I'm not sure that would work. Since he already has a template string, you would need to escape it – Cyoce – 2016-02-15T19:47:41.917

@ӍѲꝆΛҐӍΛПҒЦꝆ 1e3 is better than 10e2 can't believe i missed that . – andlrc – 2016-02-15T20:28:25.593

@edc65 You are not the first to talk about it, ӍѲꝆΛҐӍΛПҒЦꝆ also mentioned it. :-) – andlrc – 2016-02-22T19:26:44.267

4

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.

Digital Trauma

Posted 2016-02-15T17:31:32.003

Reputation: 64 644

1Shouldn't there be an extra newline? – user253751 – 2016-02-16T08:35:40.063

@immibis Yes - you're right - fixed. – Digital Trauma – 2016-02-16T17:12:10.183

4

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.

Conor O'Brien

Posted 2016-02-15T17:31:32.003

Reputation: 36 228

3Looks like a fun language. Would you add a link to an interpreter + docs? – Denker – 2016-02-15T21:24:34.797

@DenkerAffe The docs and interpreter can both be found in the heading I just edited in. – Conor O'Brien – 2016-02-15T21:25:27.527

@Conor Thanks, gonna have a look at it. :) – Denker – 2016-02-15T21:30:56.677

3

Pyth, 15 14 bytes

.dcl.z1b"Done.

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

PurkkaKoodari

Posted 2016-02-15T17:31:32.003

Reputation: 16 699

You are missing the period after Done (which is pretty funny since you told someone the same on another answer) :P – Denker – 2016-02-15T18:00:51.997

@DenkerAffe Thanks. (Byte count was correct, though.) – PurkkaKoodari – 2016-02-15T18:01:44.247

@muddyfish Thats what the challenge says. The official interpreter goes char-wise, but I changed it to lines to avoid waiting times. – Denker – 2016-02-15T18:07:22.973

@DenkerAffe Ok now our entries our exactly the same. Whos to keep? I'm going to assume Pietu1998 because they were correct first – Blue – 2016-02-15T18:08:30.070

Is b necessary? – busukxuan – 2016-02-15T20:45:50.317

@busukxuan Yes, to print the newlines. – PurkkaKoodari – 2016-02-15T20:56:08.710

I think everyone hates Pyth by now.... – theonlygusti – 2016-02-15T21:44:03.330

2

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."

DLosc

Posted 2016-02-15T17:31:32.003

Reputation: 21 213

2

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

Luis Mendo

Posted 2016-02-15T17:31:32.003

Reputation: 87 464

Are you missing the period after Done? – PurkkaKoodari – 2016-02-15T17:52:51.683

@Pietu1998 Whoops. Corrected. Thanks! – Luis Mendo – 2016-02-15T17:54:00.433

2

Perl, 21 + 1 = 22 bytes

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

Requires the -p flag:

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


Done.              

andlrc

Posted 2016-02-15T17:31:32.003

Reputation: 1 613

2

Python 3, 58 bytes

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

Blue

Posted 2016-02-15T17:31:32.003

Reputation: 26 661

Just wanna point this out, it would be 2 Bytes shorter in python 2, print"\n\nDone" – Random Guy – 2016-02-15T23:44:25.250

Oh yeah, I forgot... Sorry. – Random Guy – 2016-02-15T23:46:40.950

1

OCaml, 61 bytes

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

Assumes the input is a list.

shooqie

Posted 2016-02-15T17:31:32.003

Reputation: 5 032

1

Ruby, 32 bytes

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

Reads from stdin.

bogl

Posted 2016-02-15T17:31:32.003

Reputation: 151

0

Jelly, 12 bytes (non-competing)

Ỵ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.")

Erik the Outgolfer

Posted 2016-02-15T17:31:32.003

Reputation: 38 134

This is non-competing because of œS. – Erik the Outgolfer – 2016-12-27T10:36:21.590

0

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.

James Brown

Posted 2016-02-15T17:31:32.003

Reputation: 663