8
\$\begingroup\$

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

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

9 Answers 9

10
\$\begingroup\$

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

\$\endgroup\$
9
\$\begingroup\$

Python 3, 39 38 bytes

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

Saved 1 byte thanks to @atlasologist

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

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

\$\endgroup\$
6
\$\begingroup\$

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.

\$\endgroup\$
6
\$\begingroup\$

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

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

Mathematica, 38 bytes

f:=StringCases[InputString[],"*":>f];f
\$\endgroup\$
4
\$\begingroup\$

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)
\$\endgroup\$
2
\$\begingroup\$

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

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

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.

\$\endgroup\$

Your Answer

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

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