X-script/Examples

From Esolang
Jump to navigation Jump to search

Back to X-script

Here is some X-script example.

Hello, world!

print("Hello, world!")

By output file

print("Hello, world!", file = "test.out") # If the file doesn't exist, X-script will automatically create it.
print("", end = "", file = "CON")

Truth Machine

var bool x = bool(parseInt(input()))
if x == False:
    print(0)
else:
    forever:
        print(int(x)) # When outputting a logical value type as an integer, 0 is used for false and 1 for true.

A+B problem

var int a, b = parseInt(input()), parseInt(input())
print(a + b)

Roll dice

from random import *
var int a = parseInt(input("How many dice do you want to roll?"))
var int b = parseInt(input("Please enter the number of faces per dice:"))
var table c = []
for x in range(0, a):
    c.push_back(randint(1, b))
print(c)

99 bottles of beer

var string s = 5 / 0
print(s)

Brainfuck interpreter

import sys
function Brainfuck(code)
    s = []; matches = {}; tape = [0] * 1000000
    for i, j in enumerate(code)
        if j == '['
            s.append(i)
        end
        if j == ']'
            m = s.pop()
            matches[m] = i; matches[i] = m
        end
    end
    ip = 0; dp = 0
    while ip < code.length()
        --snip--
    end
end
Brainfuck(sys.stdin.input())