Golf an InterpretMe interpreter

8

This is a very simple challenge.

The joke language InterpretMe consists of one command; *, which causes the program to take input of an InterpretMe program and execute it.

An InterpretMe program will interpret as many InterpretMe programs as there are * in input.


Your goal is to create a program that interprets InterpretMe in as few bytes as possible.


Input

Input will consist of one line ASCII strings, unicode utf-8 strings if you really want, or any character encoding that your language uses, if you want it that much. These strings can either be inputted at the start, or at the start of every run of InterpretMe interpreter. If they are all inputted at the start, the program must output every program line as it begins it.

Output

In this challenge, there will be no output unless the option of one input is chosen, otherwise only termination and non-termination


Test cases consist not of input and output, but input and termination. A newline denotes a new input to be interpreted as InterpretMe.

If using one input at the start, this could be considered what is outputted when these programs are inputted, followed by inactive (do nothing) lines.

1. *   (executes input as an interpret me program, finishes)
2. *   (^same)
3. **  (executes input as an interpret me program, then does this again after the first program is done, finishes)
4. hi  (nothing, first star of previous line finishes)
5. **  (same as the other two star line)
6. hi  (nothing, first star of previous line finishes)
7. hi  (nothing, second star of line 5 finishes, so second star of line 3 finishes, so line 2 finishes, so line one finishes)
[termination] (not outputted)

hi  (does nothing and finishes)
[termination]

*hi  (executes inputted program, finishes)
*yo  (executes inputted program, finishes)
hey  (nothing)
[termination]

Again, this is , so fewer bytes is better

Destructible Lemon

Posted 2016-08-05T11:55:15.350

Reputation: 5 908

1I don't really understand. Isn't this 0 bytes in pretty much every language? – James – 2016-08-05T11:56:52.390

1no, because you have to take input as many times as there are "*"s in a program, then reiterate the same with each input – Destructible Lemon – 2016-08-05T11:59:16.980

Can you give an example of a non-termination program? – Neil – 2016-08-05T12:00:16.387

they always terminate, there is one command "*" – Destructible Lemon – 2016-08-05T12:04:58.570

17Wait a second? What? – Rohan Jhunjhunwala – 2016-08-05T12:07:06.950

3This doesn't seem like a well-defined challenge, since there doesn't seem to be a clear criterion for whether or not a program "actually interpreted" its input. – user2357112 supports Monica – 2016-08-05T19:04:55.907

Well, the criterion is whether it terminates at the right time, or, for a one input program, outputs the right amount of lines – Destructible Lemon – 2016-08-05T23:12:04.580

So basically, if (currentline >= cumulativestarcount) terminate? – Deusovi – 2016-08-05T23:57:35.363

that's one way to express it, yes – Destructible Lemon – 2016-08-06T00:00:36.387

Cool, someone made a challenge with my language :) – Esolanging Fruit – 2016-11-09T04:20:15.773

Answers

2

05AB1E, 11 bytes

Code:

[¬'*QiIJ}¦Ž

Explanation:

[            # Enter an infinite loop
 ¬           # Get the first character of the input string (leaves the input on the stack)
  '*Qi  }    # If equal to an asterisk...
      I      # Request another line of input and
       J     # Join it to the string that was left on the stack
         ¦   # Remove the first character
          Ž  # If everything is processed, terminate

Uses the CP-1252 encoding. Try it online?.

Adnan

Posted 2016-08-05T11:55:15.350

Reputation: 41 965

10

Python 3, 35 bytes

i=1
while i:i+=input().count('*')-1

sets i to one, adds the amount of '*' -1 to i

I think I can reduce this with ~ trickery I couldn't

Destructible Lemon

Posted 2016-08-05T11:55:15.350

Reputation: 5 908

9

Python 3, 39 38 bytes

def f():[f()for c in input()if c=="*"]

Saved 1 byte thanks to @atlasologist

TuxCrafting

Posted 2016-08-05T11:55:15.350

Reputation: 4 547

235 bytes in CoffeeScript f=->f()for c in prompt()when c=='*' (I don't want to make another answer since it is a direct copy of yours) – Bojidar Marinov – 2016-08-05T12:57:04.793

2I think you'd save a byte by going with a regular function (def f() instead of the f=lambda). – atlasologist – 2016-08-05T13:48:04.323

8

Ruby, 29 bytes

i=1
i+=gets.count ?*while$.<i

Ruby's magical variable $. keeps track of the number of lines read from stdin. Keep reading input while this number is lower than the count of asterisks (plus the initial 1).

daniero

Posted 2016-08-05T11:55:15.350

Reputation: 17 193

6

Java only 45 60 101 100 99 bytes

Reverse code-golf :D. I noticed that I missread the specs (twice), but now it should work. Seems simple enough, perhaps there is a better way of writing this as a lamda expression.

void a(char[]a){for(char b:a)if(b==42)a(new java.util.Scanner(System.in).nextLine().toCharArray());}

Slightly sleazy cheating for only 17 bytes!

void a(char[]a){}

This version will take input via really fast typing

Rohan Jhunjhunwala

Posted 2016-08-05T11:55:15.350

Reputation: 2 569

2if(b=='*') can be golfed to if(b==42) for -1 byte. And new Java.util.Scanner( should be with a lowercase j. +1 for the reverse code-golfing part. ;) – Kevin Cruijssen – 2016-08-05T13:59:00.510

1This answer made my day :D for(int b:a) saves an additional byte, so less than a 100 bytes for doing nothing :D – Frozn – 2016-08-05T21:59:41.700

Thanks! @Frozn (these characters help the comment according to ppcg) – Rohan Jhunjhunwala – 2016-08-06T01:03:40.497

6

JavaScript, 53 45 44 bytes

f=_=>{for(i in prompt().match(/\*/g))f()}f()

This program is rather annoying to use due to JavaScript's lack of good I/O.

Asks for a program, then asks for another program for every * in the input program.

Business Cat

Posted 2016-08-05T11:55:15.350

Reputation: 8 927

4

Mathematica, 38 bytes

f:=StringCases[InputString[],"*":>f];f

alephalpha

Posted 2016-08-05T11:55:15.350

Reputation: 23 988

4

APL, 15 bytes

{⍵='*':∇¨⍞⋄⍬}¨⍞

Test:

      {⍵='*':∇¨⍞⋄⍬}¨⍞
*
*
**
hi
**
hi
hi
⍝ termination

Explanation:

              ⍞  read a line from the keyboard
{           }¨   for each character:
 ⍵='*':          if it is *:
         ⍞         read another line from the keyboard
       ∇¨          do the same for each character
          ⋄⍬     otherwise, return empty list (which displays as nothing)

marinus

Posted 2016-08-05T11:55:15.350

Reputation: 30 224

2

Perl, 33 bytes

for(my$c;$c+=()=<>=~/\*/g;$c--){}

Counts the number of times that * occurs in the input and adds that to the number of times it loops. I feel like there should be a way to do the decrementing in the same step as incrementing but I couldn't figure it out.

theLambGoat

Posted 2016-08-05T11:55:15.350

Reputation: 119