@_Nobody_/

ugl-1-0-0

Python

No description

fork
loading
Files
  • main.py
  • docs.txt
main.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
import itertools as it
import functools as ft
g = lambda f,n,x: ft.reduce(lambda a,f: f(a), n*[f], x)
repeat = lambda fun, count: (lambda arg: g(fun, count, arg))
curlies = "{}"
cur_inp = ""
def isnum(a):
    return isinstance(a,(int,float))

def islist(a):
    return isinstance(a,list)

def isstr(a):
    return isinstance(a,str)

def islst(a):
    return islist(a) or isstr(a)

def isfunc(a):
    return not(isnum(a) or islst(a))
##################################

def plus(a,b):
    # (num,num)
    if isnum(a) and isnum(b):
        return a + b
    # (list, list)
    if islist(a) and islist(b):
        return a + b
    # (num,list) (str,list)
    if (not islist(a)) and islist(b):
        return [a] + b
    # (str, str)
    if isstr(a) and isstr(b):
        return a + b
    # (num,str)
    if isnum(a) and isstr(b):
        return str(a) + b
    # (str,num)
    if isstr(a) and isnum(b):
        return a + str(b)
    # (list, num) (list,str)
    if islist(a) and not islist(b):
        return a + [b]

def listify(s):
    return [s]

def minus(a,b):
    # (num,num)
    if isnum(a) and isnum(b):
        return a - b
    # (list, num) (list, str)
    if islist(a) and (not islist(b)):
        return [x for x in a if x != b]
    # (list,list)
    if islist(a) and islist(b):
        return [x for x in a if x not in b]
    # (str, str)
    if isstr(a) and isstr(b):
        return "".join([x for x in a if x not in b])
    # (str, num)
    if isstr(a) and isnum(b):
        return a[:-b]
    # (num,list) (str,list)
    if (not islist(a)) and islist(b):
        return int(a not in b)

def star(a,b):
    # (num a, num b)
    if isnum(a) and isnum(b):
        return a * b
    # (num a,str b) (num a, list b)
    if isnum(a) and islst(b):
        return a*b
    # (list a,list b) (list a,str b)
    if islist(a) and islst(b):
        return it.product(a,b)
    # (str a, list b)
    if isstr(a) and islist(b):
        return it.product(a,b)
    # (list a, num b)
    if islist(a) and isnum(b):
        return b * a
    # (str a,num b)
    if isstr(a) and isnum(b):
        return b*a
    # (str a, str b)
    if isstr(a) and isstr(b):
        return list(map(lambda x:"".join(x),it.product(a,b)))
    if isfunc(a) and isnum(b):
        return repeat(a,b)
    if isnum(a) and isfunc(b):
        return repeat(b,a)

def Uapply(f,a):
    if isfunc(f) and isnum(a):
        return f(a)

def divide(a,b):
    if isnum(a) and isnum(b):
        return a/b
    if isfunc(a) and islist(b):
        return list(filter(a,b))

def modulo(a,b):
    if isnum(a) and isnum(b):
        return a%b

def compose(a,b):
    if isfunc(a) and isfunc(b):
        return lambda x: a(b(x))
    if isnum(a) and isnum(b):
        return list(range(a,b))
    if isfunc(a) and islist(b):
        return list(map(a,b))

def Upartial(a,b):
    if isfunc(a):
        return ft.partial(a,b)
    if isnum(a) and isnum(b):
        return list(range(a,b+1))

def switch(a):
    if islist(a):
        return [t[1] for t in a if t[0]][0]
    if isnum(a):
        return list(range(0,a+1))
    if isstr(a):
        global cur_inp
        cur_inp = input(a)
        return cur_inp
        

def flip(a):
    if isfunc(a):
        return lambda x,y: a(y,x)
    if isnum(a):
        return list(range(1,a+1))

def tokenize(s, sstate, numstate, cur_str, cur_num):
    #print(s,sstate,numstate,cur_str,cur_num)
    if len(s)==0:
        return [cur_str or cur_num]
    if s[0] == '"':
        if sstate:
            return ['"'+cur_str+'"'] + tokenize(s[1:],False,False,"","")
        else:
            return tokenize(s[1:],True,False,"","")
    if sstate:
        return tokenize(s[1:],True,False,cur_str+s[0],"")
    if numstate:
        if s[0] in "0123456789":
            return tokenize(s[1:],False,True,"",cur_num+s[0])
        else:
            return [int(cur_num)] + tokenize(s,False,False,"","")
    else:
        if s[0] in "0123456789":
            return tokenize(s[1:],False,True,"",cur_num+s[0])
        else:
            return [s[0]] + tokenize(s[1:],False,False,"","")

def fold(f,z,xs):
    if isfunc(f) and islist(xs):
        return ft.reduce(f,xs,z)
    if isnum(f) and isnum(z) and isnum(xs):
        return list(range(f,z,xs))

def Uslice(xs,start,end,step):
    if islst(xs) and all(map(lambda a: isnum(a) or a==None,[start,end,step])):
        return xs[start:end:step]

def L(xs):
    if islst(xs):
        return len(xs)
    if isnum(xs):
        return list(range(xs))

def input_wo_prompt():
    global cur_inp
    cur_inp = input()
    return cur_inp

def smaller(a,b):
    if isnum(a) and isnum(b):
        return int(a<b)

def equal(a,b):
    return int(a==b)

def greater(a,b):
    if isnum(a) and isnum(b):
        return int(a>b)

def logical_not(a):
    return int(not a)

def strify(a):
    return str(a)

def intify(a):
    return int(a)

def sjoin(a,b):
    if isstr(a) and islst(b):
        return a.join(b)

def get_item(a,b):
    if islst(a) and isnum(b):
        return a[b]
    if islst(a) and islst(b):
        return zip(a,b)

def apply2(a,b,c):
    if isfunc(a):
        return a(b,c)
    if islst(a) and isnum(b) and isnum(c):
        return a[b:c]

def apply3(a,b,c,d):
    if isfunc(a):
        return a(b,c,d)

def zipwith(f,a,b):
    if isfunc(f) and islst(a) and islst(b):
        return map(f,a,b)

d = {
    "+": "plus({},{})",
    "ƿ": "plus",
    "-": "minus({},{})",
    "Ɯ": "minus",
    "l": "listify({})",
    "ł": "listify",
    "*": "star({},{})",
    "ß": "star",
    "a": "Uapply({},{})",
    "ä": "Uapply",
    "/": "divide({},{})",
    "Ð": "divide",
    "%": "modulo({},{})",
    "Ϻ": "modulo",
    "S": "switch({})",
    "Ş": "switch",
    "Ç": "curlies",
    "P": "Upartial({},{})",
    "Ҏ": "Upartial",
    "C": "compose({},{})",
    "Č": "compose",
    "F": "flip({})",
    "ƒ": "flip",
    "f": "fold({},{},{})",
    "Ƒ": "fold",
    ":": "Uslice({},{},{},{})",
    ";": "Uslice",
    "L": "L({})",
    "Ł": "L",
    "i": "cur_inp",
    "I": "input_wo_prompt()",
    "<": "smaller({},{})",
    "Ŝ": "smaller",
    ">": "greater({},{})",
    "Ğ": "greater",
    "=": "equal({},{})",
    "ë": "equal",
    "T": "logical_not({})",
    "Þ": "logical_not",
    "s": "strify({})",
    "ş": "strify",
    "N": "intify({})",
    "Ñ": "intify",
    "j": "sjoin({},{})",
    "Ĵ": "sjoin",
    "n": "None",
    "Q": "lambda _: {}",
    "R": "lambda _,W: {}",
    "Y": "lambda _,W,u: {}",
    "W": "W",
    "u": "u",
    "_": "_",
    "g": "get_item({},{})",
    "ģ": "get_item",
    "O": "apply2({},{},{})",
    "Ö": "apply2",
    "U": "apply3({},{},{},{})",
    "Ü": "apply3",
    "Z": "zipwith({},{},{})",
    "Ż": "zipwith"
}

gen = "print({})"
a=input()
for q in [t for t in tokenize(a,False,False,"","") if t != " " ]:
    if q in d:
        gen = gen.replace("{}",d[q],1)
    else:
        gen = gen.replace("{}",str(q),1)
    #print(gen)


exec(gen)