your submission will be given two strings. you must determine whether those two strings are anagrams of each other, ignoring case and the space character
. you can assume that your string will contain only lowercase and uppercase ascii letters, and the space character.
written by quintopia
guesses
- LyricLy (by lyxal)
- citrons (by razetime)
- quintopia (by Olivia)
- quintopia (by ubq323)
- quintopia (by LyricLy)
- quintopia (by Palaiologos)
- quintopia (by Kaylynn)
- ubq323 (by IFcoltransG)
comments 0
c8.py ASCII text, with very long lines (833)
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363 | #! /usr/bin/env python
"""
Linguine programming language interpreter
Copyright (c) 2005 by Jeffry Johnston
Ported to Python 3 by ????????????? 2021
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation. See the file LICENSE
for more details.
Version History:
1.00 November 24, 2005 Initial version
1.10 November 25, 2005 Added jump dereferencing
1.20 November 26, 2005 Added `>' instruction
1.21 November 26, 2005 Fix negative y on `>' bug
1.22 November 26, 2005 Fix >> big number bug
1.30 November 27, 2005 Added `^' instruction
1.31 January 24, 2006 Fix input on EOF bug
1.40 March 17, 2021 Port to Python 3, make more module friendly
"""
import sys
import time
from optparse import OptionParser
VERSION = "1.40"
glo_memory = {}
def read(filename):
"""
Reads and parses the program, checking for errors.
Returns:
(firstline, program)
firstline = line number of first program line
program = {linenum: (command_list, goto, deref_goto), ...}
linenum = line number
command_list = [(instr, x, deref_x, y, deref_y, ifjump, deref_if), ...]
instr = instruction, one of: =, +, -, |, ?, $, #, <, ~
x = x value
deref_x = number of times x value should be deref'd, or 0
y = y value
deref_y = number of times y value should be deref'd, or 0
ifjump = ifjump line number
deref_if = number of times ifjump value should be deref'd, or 0
goto = jump line number
deref_goto = number of times goto value should be deref'd, or 0
"""
fileline = 0
program = {}
firstline = None
goto_list = []
try:
infile = open(filename)
while True:
# read line
line = infile.readline()
fileline += 1
if line == "":
break
# strip comments
i = line.find("'")
if i >= 0:
line = line[0:i]
line = line.strip()
# ignore blank lines
if len(line) < 1:
continue
# get line number
i = line.find("[")
if i < 0:
print("Error [line " + str(fileline) + "]: missing `['",file=sys.stderr)
sys.exit(1)
try:
linenum = int(line[0:i].strip())
linenum = int(linenum)
if linenum == 0:
raise ValueError
if firstline == None or linenum < firstline:
firstline = linenum
except ValueError:
print("Error [line " + str(fileline) + "]: bad or missing line number `" + str(linenum) + "'",sys.stderr)
sys.exit(1)
# get command
line = line[i:]
i = line.find("]")
if i < 0:
print("Error [line " + str(fileline) + "]: missing `]'",file=sys.stderr)
sys.exit(1)
command = line[1:i].strip()
if len(command) < 2:
print(sys.stderr, "Error [line " + str(fileline) + "]: missing or invalid command",file=sys.stderr)
sys.exit(1)
goto = line[i + 1:].strip()
# parse commands
command_list = []
commands = command.split(",")
for command in commands:
command = command.strip()
# get x deref
deref_x = 0
while len(command) > 0 and command[0] == "*":
deref_x += 1
command = command[1:].strip()
# find instruction
for c in "=+|>?^#$<~-`":
i = command.find(c, 1)
if i >= 0:
instr = c
break
else:
print("Error [line " + str(fileline) + "]: unrecognized command `" + command + "'",file=sys.stderr)
sys.exit(1)
# get x
x = command[0:i].strip()
command = command[i + 1:].strip()
try:
x = int(x)
except ValueError:
print("Error [line " + str(fileline) + "]: bad x value `" + str(x) + "'",file=sys.stderr)
sys.exit(1)
# get y deref
deref_y = 0
while len(command) > 0 and command[0] == "*":
deref_y += 1
command = command[1:].strip()
# get if jump
deref_if = 0
if instr[0] == "<" or instr[0] == "~":
i = command.find(":")
if i < 0:
print("Error [line " + str(fileline) + "]: missing if jump line number",file=sys.stderr)
sys.exit(1)
ifjump = command[i + 1:].strip()
# get ifjump deref
while len(ifjump) > 0 and ifjump[0] == "*":
deref_if += 1
ifjump = ifjump[1:].strip()
command = command[0:i].strip()
try:
ifjump = int(ifjump)
except ValueError:
print("Error [line " + str(fileline) + "]: bad if jump line number `" + str(ifjump) + "'",file=sys.stderr)
sys.exit(1)
if deref_if == 0:
goto_list += [(ifjump, fileline)]
else:
ifjump = None
# get y
if instr[0] not in "?^#$`":
y = command.strip()
try:
y = int(y)
except ValueError:
print("Error [line " + str(fileline) + "]: bad y value `" + str(y) + "'",file=sys.stderr)
sys.exit(1)
else:
y = None
if deref_y:
print("Error [line " + str(fileline) + "]: bad dereference",file=sys.stderr)
sys.exit(1)
# add command to command list
command_list += [(instr, x, deref_x, y, deref_y, ifjump, deref_if)]
# get goto line number
deref_goto = 0
while len(goto) > 0 and goto[0] == "*":
deref_goto += 1
goto = goto[1:].strip()
if len(goto) < 1:
print("Error [line " + str(fileline) + "]: missing jump line number",file=sys.stderr)
sys.exit(1)
try:
goto = int(goto)
except ValueError:
print("Error [line " + str(fileline) + "]: bad jump line number `" + str(goto) + "'",file=sys.stderr)
sys.exit(1)
if deref_goto == 0:
goto_list += [(goto, fileline)]
# add line to program dictionary
try:
program[linenum]
print("Error [line " + str(fileline) + "]: duplicate line number `" + str(linenum) + "'",file=sys.stderr)
sys.exit(1)
except KeyError:
program[linenum] = (command_list, goto, deref_goto)
infile.close()
except IOError as e:
print("Error reading program: " + str(e),file=sys.stderr)
sys.exit(1)
# check that there was at least one program line
if firstline == None:
print("Error: Program must have at least one command",file=sys.stderr)
sys.exit(1)
# check that all jumps are to valid line numbers
for goto, fileline in goto_list:
if goto != 0 and goto not in program:
print("Error [line " + str(fileline) + "]: jump to undefined line number `" + str(goto) + "'",file=sys.stderr)
sys.exit(1)
goto_list = None
return (firstline, program)
def get_cell(index):
"""
Returns the cell value at the specified index, or 0 if the cell is
unused.
"""
if index in glo_memory:
return glo_memory[index]
else:
return 0
def set_cell(index, value):
"""
Sets the value of the cell at the specified index.
"""
glo_memory[index] = value
def interpret(firstline, program, inputstream):
"""
Interprets the given Linguine program
"""
global glo_memory
line = firstline
index = 0
glo_memory = {}
while line > 0:
# get the current command
commands = program[line][0]
command = commands[index]
instr = command[0]
x = command[1]
for i in range(command[2]):
x = get_cell(x)
y = command[3]
for i in range(command[4]):
y = get_cell(y)
ifjump = command[5]
for i in range(command[6]):
ifjump = get_cell(ifjump)
if ifjump != None and ifjump != 0 and ifjump not in program:
print("Runtime error [line number " + str(line) + "]: bad ifjump line number `" + str(ifjump) + "'",file=sys.stderr)
sys.exit(1)
if index + 1 >= len(commands):
goto = program[line][1]
for i in range(program[line][2]):
goto = get_cell(goto)
if goto != 0 and goto not in program:
print("Runtime error [line number " + str(line) + "]: bad jump line number `" + str(goto) + "'",file=sys.stderr)
sys.exit(1)
line = goto
index = 0
else:
index += 1
# execute instruction
if instr == "=":
set_cell(x, y)
elif instr == "+":
set_cell(x, get_cell(x) + y)
elif instr == "-":
set_cell(x, get_cell(x) - y)
elif instr == "|":
set_cell(x, ~(get_cell(x) & y))
elif instr == ">":
if y < 0:
set_cell(x, get_cell(x) * (2**(-y)))
else:
set_cell(x, get_cell(x) >> y)
elif instr == "?":
try:
ch = inputstream.read(1)
except IOError:
ch = ""
if len(ch) < 1:
ch = -1
else:
ch = ord(ch)
set_cell(x, ch)
elif instr == "^":
set_cell(x, int(time.time()))
elif instr == "$":
sys.stdout.write(chr(get_cell(x) & 255))
sys.stdout.flush()
elif instr == "#":
sys.stdout.write(str(get_cell(x)))
sys.stdout.flush()
elif instr == "<" and get_cell(x) < y:
line = ifjump
index = 0
elif instr == "~" and get_cell(x) == y:
line = ifjump
index = 0
elif instr == "`":
print(line,glo_memory)
def main():
"""
Processes the command line, reads the program, and starts the Linguine
interpreter.
"""
(options, args) = OptionParser(usage="linguine.py [options] program", \
version=VERSION, \
description="Interprets the specified Linguine program.").parse_args()
if len(args) < 1:
print >> sys.stderr, "Missing program filename."
sys.exit(1)
elif len(args) > 1:
print >> sys.stderr, "Too many filenames given."
sys.exit(1)
interpret(*read(args[0]),sys.stdin)
def entry(s1,s2):
"""
Delete this function if you just want a mediocre Linguine interpreter
"""
from contextlib import redirect_stdout
import io
inbuf = io.StringIO(s1+"\n"+s2+"\n")
f = io.StringIO()
with redirect_stdout(f):
interpret(1,{1:([('=',3,0,6,0,None,0),('=',2,0,26,0,None,0)],2,0),2:([('?',0,0,None,0,None,0),('~',0,0,10,0,3,0),('=',1,0,0,1,None,0),('-',1,0,64,0,None,0),('<',1,0,0,0,2,0),('=',3,1,0,1,None,0),('+',3,0,1,0,None,0),('<',2,0,1,1,2,0),('-',3,0,1,0,None,0),('+',3,1,32,0,None,0),('+',3,0,1,0,None,0)],2,0),3:([('<',5,0,4,1,4,0),('=',4,0,3,1,None,0),('+',3,0,1,0,None,0)],2,0),4:([('=',5,0,3,1,None,0),('=',3,0,6,0,None,0)],5,0),5:([('=',0,0,4,1,None,0),('+',0,0,1,0,None,0),('~',4,0,3,1,9,0)],6,0),6:([('~',0,0,5,1,8,0),('~',0,1,3,2,7,0),('+',0,0,1,0,None,0)],6,0),7:([('=',3,1,0,0,None,0),('=',0,1,0,0,None,0),('+',3,0,1,0,None,0)],5,0),8:([('=',0,0,48,0,None,0),('$',0,0,None,0,None,0)],0,0),9:([('~',0,0,5,1,10,0),('<',-1,0,0,2,8,0),('+',0,0,1,0,None,0)],9,0),10:([('=',0,0,49,0,None,0),('$',0,0,None,0,None,0)],0,0)},inbuf)
s = f.getvalue()
return (s=="1")
if __name__ == "__main__":
main()
|
written by Olivia
guesses
- IFcoltransG (by quintopia)
- IFcoltransG (by ubq323)
- Kaylynn (by IFcoltransG)
- Kaylynn (by LyricLy)
- Kaylynn (by Palaiologos)
- LyricLy (by Kaylynn)
- Olivia (by lyxal)
comments 0
c10.py ASCII text
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 | import re, inspect, sys
# f . f f @ x x >> f
class __Compose:
def __init__(self, *__fs):
self.__fs = __fs
def __getattr__(self, __f):
return type(self)(*self.__fs, eval(__f, globals(), inspect.currentframe().f_back.f_locals))
def __matmul__(self, __x):
return self(__x)
__rrshift__ = __matmul__
def __call__(self, *__xs):
__fs = list(self.__fs)
__x = __fs.pop()(*__xs)
while len(__fs) != 0:
__x = __fs.pop()(__x)
return __x
# Macron
def __macro(__code):
for _ in range(1000):
__code = re.sub(r"\(([^\(]*?)\) -> (.*)", r"__Compose(lambda \1: \2)", __code)
return __code
# Do
def __runner(__code):
sys.setrecursionlimit(100000)
exec(__macro(__code), globals())
# Codes
__runner("""
id = (x) -> x
part = (f, *xs) -> (x) -> f (*xs, x)
use0 = (f) -> (*xs) -> f ()
wuse0 = (x) -> (*xs) -> x
use1 = (f) -> (x, *xs) -> f (x)
nuple = (*xs) -> xs
dewrapply = (f, xs) -> f(*xs)
nil = () -> []
cons = (x, xs) -> [x] + xs
head = (xs) -> xs[0]
tail = (xs) -> xs[1:]
n = (xs) -> len (xs)
consnil = (x) -> cons (x, nil ())
eq = (x, y) -> x == y
z = () -> 0
s = (x) -> x + 1
thirtytwo = () -> 32
pre = (x) -> sub (x, s . z ())
eqz = (xs) -> eq (z (), xs)
eqzn = (xs) -> eqz . n @ xs
eq1 = (xs) -> eq (s . z (), xs)
eq1n = (xs) -> eq1 . n @ xs
capply = (cf, tf, ff) -> (*xs) -> tf (*xs) if cf (*xs) else ff (*xs)
fdeconsapply = (f, hf, tf, xs) -> f (hf . head @ xs, tf . tail @ xs)
consapply = (hf, tf, xs) -> fdeconsapply (cons, hf, tf, xs)
fold = (f, xs) -> xs >> capply (eq1n, head, part (fdeconsapply, f, id, part (fold, f)))
applyn = (f, xs) -> xs >> capply (eq1n, consnil . f . head, part (consapply, f, part (applyn, f)))
headapplyn = (f, xs) -> applyn (part (f, head @ xs), tail @ xs)
ziphead2 = (xs, ys) -> nuple (head @ xs, head @ ys)
tails2 = (xs, ys) -> nuple (tail @ xs, tail @ ys)
zip2tails = (xs, ys) -> dewrapply (zip2, tails2 (xs, ys))
zip2 = (xs, ys) -> cons (ziphead2 (xs, ys), capply (use1 @ eq1n, use0 @ nil, zip2tails) (xs, ys))
add = (x, y) -> x + y
vadd = (xs, ys) -> applyn (part (dewrapply, add), zip2 (xs, ys))
vsum = (xss) -> fold (vadd, xss)
neg = (x) -> -x
sub = (x, y) -> add(x, neg @ y)
vsub = (xs, ys) -> applyn (part (dewrapply, sub), zip2 (xs, ys))
vheadsubn = (xss) -> headapplyn (vsub, xss)
binand = (x, y) -> x and y
all = (xs) -> fold (binand, xs)
transeqn = (xs) -> all . headapplyn (eq, xs)
dontails = (x, f, y) -> don (pre @ x, f, f @ y)
don = (x, f, y) -> capply (eqz . head . nuple, head . tail . tail . nuple, dontails) (x, f, y)
mul = (x, y) -> don (x, part (cons, y), nil ())
s2 = (xs, ys) -> cons (head @ xs, sum (tail @ xs, ys))
sum = (xs, ys) -> capply (eqzn . head . nuple, head . tail . nuple, s2) (xs, ys)
concat = (xss) -> fold (sum, xss)
first = (f, xs) -> xs >> capply (eqzn, use0 @ nil, capply, f . head, head, part (first, f) . tail)
map = (x, yzs) -> head . tail . first (part (eq, x) . head, yzs)
un = (x) -> x >> capply (eqz, wuse0 . s . z (), wuse0 . z ())
binor = (x, y) -> un . binand (un @ x, un @ y)
lthan = (x, y) -> x < y
gtheq = (x, y) -> un . lthan (x, y)
gthan = (x, y) -> binand (gtheq (x, y), un . eq (x, y))
ltheq = (x, y) -> un . gthan (x, y)
between = (x, y) -> (w) -> binand (gtheq (w, x), ltheq (w, y))
cpoint = (x) -> ord (x)
upa = () -> cpoint ("A")
lowa = () -> cpoint ("a")
cpbtw = (x, y) -> (w) -> w >> between (cpoint @ x, cpoint @ y) . cpoint
asciilow = (x) -> cpbtw ("a", "z") @ x
asciiup = (x) -> cpbtw ("A", "Z") @ x
asciial = (x) -> binor (asciilow @ x, asciiup @ x)
cpoff = (x, y) -> sub (cpoint @ y, x)
asciioff = (x) -> x >> capply (asciiup, part (cpoff, upa ()), part (cpoff, lowa ()))
zvec = (x) -> mul (x, z ())
zvec32 = () -> mul (thirtytwo (), z ())
basisvec = (x, y) -> concat . nuple (zvec @ y, consnil . s . z (), zvec . pre . sub (x, y))
basis32 = (x) -> basisvec (thirtytwo (), x)
asciivec = (x) -> basis32 . asciioff @ x
anyvec = (x) -> x >> capply (asciial, asciivec, use0 @ zvec32)
entry = (*xs) -> transeqn . cons (zvec32 (), vheadsubn . applyn (part (vsum . applyn, anyvec), xs))
""")
|
post a comment