Minipy

From Esolang
Jump to navigation Jump to search

Minipy is a golfing "language" created by Challenger5. It is Python, but with the following statements prepended to every program:

import sys as y
av = y.argv
if len(av) > 1:
    v1 = av[1]
    try:
        v2 = eval(v1)
    except SyntaxError: pass
import os
import re
import functools as ft
import string as st
import copy as cp
import random as rd
import math as m
ri = rd.randint
rt = lambda seq: seq[ri(0, len(seq)-1)]
N = None
_i = __import__
_b = __builtins__
_B = dir(_b)
ab = abs
al = all
an = any
bn = bin
c = chr
cx = complex
d = dict
dr = dir
em = enumerate
e = eval
x = exec
b = lambda x: lambda y: eval(x)
fm = lambda x,y: map(b(x),y)
ff = lambda x,y: filter(b(x),y)
fr = ft.reduce
fl = float
gtat = getattr
hsat = hasattr
dlat = delattr
stat = setattr
hx = hex
i = input
n = lambda *args: eval(input(*args))
sr = ""
t = int
l = len
ls = list
ot = oct
o = open
f = lambda s: o(s).read()
p = print
r = range
rp = repr
rvr = reversed
rnd = round
srt = sorted
s = str
sm = sum
v = vars
z = zip
def rf(s): # regex finder
    index = s.index("!")
    regex = re.compile(s[:index])
    search = s[index + 1 :]
    if search[0] == "!":
        return regex.findall(search[1:])
    else:
        return regex.findall(eval(search))
q = chr(34)
k = "\n"

def e(s):
    raise RuntimeError(s)

This shortens the names of functions, automatically imports modules, and creates some useful functions.

Interpreter

Here is a (minimized) Python interpreter for Minipy. It assumes that the above statements are loaded into the file minipy.py stored in the current directory. It executes a file given as a command line argument.

from minipy import*;x(f(v1))

Examples

Hello, World! program:

p("Hello, World!")

Quicksort:

def q(k):
 if l(k)<2:return k
 p=rt(k);return q(ff("y>p",k))+q(ff("y<=p",k))

Factorial:

p(m.factorial(v2))