# Golf an InterpretMe interpreter

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

• I don't really understand. Isn't this 0 bytes in pretty much every language? Aug 5 '16 at 11:56
• no, because you have to take input as many times as there are "*"s in a program, then reiterate the same with each input Aug 5 '16 at 11:59
• Can you give an example of a non-termination program?
– Neil
Aug 5 '16 at 12:00
• Wait a second? What? Aug 5 '16 at 12:07
• This 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. Aug 5 '16 at 19:04

# 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

## Python 3, 39 38 bytes

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


Saved 1 byte thanks to @atlasologist

• 35 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) Aug 5 '16 at 12:57
• I think you'd save a byte by going with a regular function (def f() instead of the f=lambda). Aug 5 '16 at 13:48

# 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).

## JavaScript, 5345 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.

# 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

• if(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. ;) Aug 5 '16 at 13:59
• This answer made my day :D for(int b:a) saves an additional byte, so less than a 100 bytes for doing nothing :D Aug 5 '16 at 21:59
• Thanks! @Frozn (these characters help the comment according to ppcg) Aug 6 '16 at 1:03

# Mathematica, 38 bytes

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


# 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)


# 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?.

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