*

From Esolang
Jump to navigation Jump to search

* is a very simple esoteric programming language, where the only commands consist of *, space, and + (if you can even count that one).

  • [SPACE]*[SPACE] ([SPACE] is the space character) prints a random number between 0 and 1 multiplied by an extremely big number. (In the Java interpreter, it's the biggest number possible in Java, 2,147,483,647.)
  • *+* runs forever.

Examples

Hello World

*

Random Number Generator between 0 and 2,147,483,647

[Space]*[Space]

Infinite loop

*+*

Interpreters

Java

import java.util.Scanner;

public class Asterisk{
  
  public static void main(String[] args){
  
    Scanner in = new Scanner(System.in);
    System.out.println();
    String ast = in.nextLine();
    
    if(ast == "*") System.out.println("Hello World");
    else if(ast == " * ") System.out.println(Math.random() * Integer.MAX_VALUE);
    else if(ast == "*+*") recur();
  }
  public static void recur(){ recur(); }
}

JavaScript

var code=prompt();
code === "*"?console.log("Hello World");
code === " * "?console.log(Math.random() * Number.MAX_VALUE);
code === "*+*"?while(true){}

User:Nomad was here. I made an improved version for browser:

const code = prompt();
while (code === '*+*' ? 1 : console.log(code === '*' ? "Hello World" : code === ' * ' ? Math.random() * Number.MAX_VALUE : '') || 0) {};

JavaScript (Node.js)

User:Nomad was here. I made a one-liner for Node.js:

// Save in a file, and call with    'node <filename> <code>'
while (process.argv[2] === '*+*' ? 1 : console.log(process.argv[2] === '*' ? "Hello World" : process.argv[2] === ' * ' ? Math.random() * Number.MAX_VALUE : '') || 0) {};

Python 3

from random import random
def ast():
    while True:
        cmd = input('*> ')
        if cmd == '*': print('Hello World')
        elif cmd == ' * ': print(random() * 2147483647)
        elif cmd == '*+*':
            while True: pass

C++

~User:Earthrulerr GitHub Repo

// Author == earthrulerr
// A C++ implementation of *.
#include <iostream>
#include <string>
using namespace std;
int main() {
  string input;
  int loop2 = 0;
  int loop = 1;
  int random = rand();
  while (loop == 1) {
    getline(cin, input);
    if (input == "*") {
      cout << "Hello World";
    } else if (input == " * ") {
      cout << random;
    } else if (input == "*+*") {
      loop2 = 1;
      while (loop2 == 1) {}
    }
  }
}