If(j)invert()if(l)change()if(q)input()if(t)output(x);

From Esolang
Jump to navigation Jump to search

If(j)invert()if(l)change()if(q)input()if(t)output(x); is a joke language.

Specifications

If(j)invert()if(l)change()if(q)input()if(t)output(x); has 2 cells of memory and an instruction pointer. Both cells can store integers.

Instruction Action
j If the cell is 0, set it to 1. Else, set it to 0.
l Shift the pointer to the other cell.
q Accept input and overwrite it at the selected cell. Integers other than 0 and 1 are accepted.
t Output the selected cell's value.

All other characters output themselves.

Interpreters

Java

This may not be accurate to the (likely) official C interpreter.

import java.util.Scanner;
public class jlfq{
  public static String interpreter(String code){
    Scanner input=new Scanner(System.in);
    int[] mem={0,0};
    int pointer=0;
    String o="";
    for(int i=0;i<code.length();++i){
      switch(code.charAt(i)){
        case'j':
          mem[pointer]=(mem[pointer]==0)?1:0;
          break;
        case'l':
          pointer=(pointer==0)?1:0;
          break;
        case'q':
          mem[pointer]=input.nextInt();
          break;
        case't':
          System.out.print((char)mem[pointer]);
          break;
        default:
          System.out.print(code.charAt(i));
      }
    }
    return o;
  }
}

C

int[] mem = [0, 0];
int pointer = 0;
int ip = 0;
for(;;){
  char x = scanf('%s', x);
  switch(x){
    case('j'){
      if(mem[pointer] == 0){ mem[pointer] = 1;}else{ mem[pointer] = 0;}break;}
    case('l'){
      if(pointer == 0){ pointer = 1; }else{ pointer = 0;}break;}
    case('q'){
      mem[pointer] = scanf('%i', mem[pointer]);break;}
    case('t'){
      printf('%c', mem[pointer]); break;}
    default{
      printf('%c', x); break;}
  }
}

(It uses scanf, and it needs to be better)

Examples

More examples can be added if needed.

Hello World

Due to the limited nature of the commands, either 1 or 0 can be outputted by the program, restricting potential attempts past

He11o Wor1d
Hell11ojl ljWorl1d

The alternative is to ask the user to input the character l themselves, since it is the only way to have an integer in a cell other than 1 or 0.

Heqtto Wortd

Cat

Using the instructions alone, a cat is limited to finite sequence of commands. Unless a looping command is implemented, cats are impossible. Finite versions include this program,

qtqtqtqtqtqtqtqtqtqtqtqtqtqtqtqtqtqtqtqtqtqtqtqtqtqtqtqtqtqt . . .

and this program.

qlqltltlqlqltltlqlqltltlqlqltltlqlqltltlqlqltltlqlqltltlqlql . . .

The difference between both is that the latter program outputs 2 at a time while the former outputs 1 at a time.

FizzBuzz

See Quine for more details.

1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz

Quine

Any message not using the commands j, l, q, and t is already a quine, since the default command for other characters is to output them. Examples include:

7his is a 9uine
7his is a1so a 9uine

As seen above, the latter 3 commands can be impersonated using 1, 9, and 7, respectively. What j can be replicated by is open for suggestions. (Feel free to edit a substitute if you figure one out.)

Code fragment where ll can't be omitted without changing its behaviour

Amazing.

qllt