-
Notifications
You must be signed in to change notification settings - Fork 4
/
functions.py
147 lines (110 loc) · 3.24 KB
/
functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from helper import *
from context import Context
from element_helpers import *
from helper import Rational
g = "Hello, World!"
w = "Hello World"
b = "0123456789"
o = "123456789"
a = "abcdefghijklmnopqrstuvwxyz"
u = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
c = 10
d = 16
e = 256
f = -1
h = 65536
i = 2048
j = 4906
k = 1024
l = 128
n = -1
p0 = 10
p1 = 16
p2 = 256
p3 = 32768
p4 = 65536
p5 = 2048
p6 = 4096
p7 = 1024
p8 = 128
ctx = Context() # Set ctx to Context() at first (and as a default)
# when nothing is given
def Add(a, b, ctx=ctx):
"""Addition/Concatenation"""
if typecheck(args=[a, b], types=[Rational, Rational]):
return add(a, b)
elif typecheck(args=[a, b], types=[str, str]):
return concat(a, b)
elif typecheck(args=[a, b], types=[str, Rational]):
return concat(a, b)
elif typecheck(args=[a, b], types=[Rational, str]):
return addascii(a, b)
def Sub(a, b, ctx=ctx):
"""Subtraction"""
if typecheck(args=[a, b], types=[Rational, Rational]):
return subtract(a, b)
elif typecheck(args=[a, b], types=[str, str]):
return removechars(a, b)
def Mul(a, b, ctx=ctx):
"""Multiplication"""
if typecheck(args=[a, b], types=[Rational, Rational]):
return multiply(a, b)
elif typecheck(args=[a, b], types=[str, str]):
return joinab(a, b)
elif typecheck(args=[a, b], types=[str, int]):
return repeat(a, b)
def TrueDiv(a, b, ctx=ctx):
"""Division"""
if typecheck(args=[a, b], types=[Rational, Rational]):
return divide(a, b)
def Print(a, ctx=ctx):
"""Print with newline"""
ctx.print += print_with_newline(a)
ctx.printed = True
return a
def Power(a, b, ctx=None):
"""Exponentiation"""
if typecheck(args=[a, b], types=[Rational, Rational]):
return power(a, b)
elif typecheck(args=[a, b], types=[str, str]):
return interleave(a, b)
def SumDigits(a, ctx=None):
if typecheck(args=[a], types=[int]):
return sumdigits(a)
elif typecheck(args=[a], types=[str]):
return sumascii(a)
def GeneralInput(ctx=None):
return general_input()
def Mod(a, b, ctx=None):
if typecheck(args=[a, b], types=[int, int]):
return mod(a, b)
def ExclamationMark(a, ctx=None):
if typecheck(args=[a], types=[str]):
return uppercase(a)
elif typecheck(args=[a], types=[Rational]):
return add(a, 1)
def InversExclamation(a, ctx=None):
if typecheck(args=[a], types=[str]):
return lowercase(a)
elif typecheck(args=[a], types=[Rational]):
return subtract(a, 1)
def HollowSquare(a, ctx=None):
if typecheck(args=[a], types=[str]):
return swapcase(a)
elif typecheck(args=[a], types=[Rational]):
return negate(a)
def Index(a, b, ctx=None):
return index(safe_cast(a, str), safe_cast(b, int))
def Slice(a, b, c, ctx=None):
return slice(safe_cast(a, str),
safe_cast(b, int),
safe_cast(c, int))
def Head(a, b, ctx=None):
return head(safe_cast(a, str), safe_cast(b, int))
def Tail(a, b, ctx=None):
return tail(safe_cast(a, str), safe_cast(b, int))
def Halve(a, ctx=None):
if typecheck(args=[a], types=[int]):
return divide(a, 2)
elif typecheck(args=[a], types=[str]):
return halvestr(a)