#esoteric-python

1 messages · Page 18 of 1

long fulcrum
#

?

meager zinc
#

that's how it's encoded in hex

long fulcrum
#

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

meager zinc
#

That's because it has to be in chunks of 16

#

(two 8-bytes)

meager zinc
#

to change encodings

long fulcrum
#

oh right

meager zinc
#

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),
  )
)
versed eagle
#

yep
windows doesn't have libc, so you have to use the microsoft c runtime

meager zinc
#

Microsoft Visual C Runtime is the equivalent

versed eagle
#

the v also stands for something but i forgot since i dont use windows

versed eagle
#

thats it

meager zinc
#

visual c# actually maybe

#

lemme google it

#

no

#

just

#

Microsoft Visual C Run Time

#

idk why it has "Visual"

#

kinda random

eager ore
#

that's why you count in bytes

meager zinc
#

I think mac also has libc

#

but I'm not very familiar with mac anyways

meager zinc
#

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?

gleaming linden
#
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
long fulcrum
#

jesus

meager zinc
#

we've nearly cut it in half

long fulcrum
#

when I started earlier it was 1300

#

like way before I posted it here

meager zinc
#

oh we've def cut it in half

#

!e print(236 / 1300)

night quarryBOT
#

@meager zinc :white_check_mark: Your 3.11 eval job has completed with return code 0.

0.18153846153846154
meager zinc
#

it's 18% of original size

gleaming linden
#
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)
meager zinc
#

Best compression algorithm?

long fulcrum
gleaming linden
#

range(1,len(A)-1) and range(1,W-1)

long fulcrum
#

it can be range(1,len(A))

gleaming linden
#

can it?

long fulcrum
#

yep

gleaming linden
#

wtf

#

why does that work

#

ah I see

#

it just errors and exits

#

does that count though

long fulcrum
#

yep

gleaming linden
#

I mean

#

we can just ignore stderr

#

and just look at stdout

#

ig that works

long fulcrum
#

ok im having some issues ungolfing droidcry

#

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

eager ore
#

you should write a clean version first

#

then golf it

long fulcrum
#

I did but ive lost it

eager ore
#

you could use git

#

in the future

gleaming linden
#

or at least numpy arrays

long fulcrum
#

i have no idea what any of those are

#

id just like to get my own version working

gleaming linden
#

instead of dealing with edge checks

#

but this isn't esoteric anymore

long fulcrum
#

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

long fulcrum
quartz wave
#

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)))

sick hound
#

!e```py
exec(bytes('牰湩⡴漢湯漊湯漠湯漠湯漠湯漠湯漠湯漠੮湯漠湯漠湯漠湯漠湯漠湯漠湯漊湯漠湯漠湯漠湯漠湯漠湯漠੮湯漠湯漠湯漠湯漠湯漠湯漠湯漊湯漠湯漠湯漠湯漠湯漠湯漠੮湯漠湯漠湯漠湯漠湯漠湯漠湯漊湯漠湯漠湯漠湯漠湯漠湯漠੮湯漠湯漠湯漠湯漠湯漠湯漠湯漊湯漠湯漠湯漠湯漠湯漠湯漠੮湯漠湯漠湯漠湯漠湯漠湯漠湯漊湯⤢','u16')[2:])

night quarryBOT
#

@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)
gleaming linden
#

@quartz wave test input

quartz wave
#

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)))

dense nova
#

what does this do

#

lmao

#

is it a really complicated adder

quartz wave
dense nova
#

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)))
quartz wave
dense nova
#

dont think so

quartz wave
#

output failed paste-and-compare test

dense nova
#

!e

for i in range(10000):
  for j in range(10000):
    if j + i + j != i+j*2:
      print(f"oopsie? {i} {j}")
      break
night quarryBOT
#

@dense nova :warning: Your 3.11 eval job timed out or ran out of memory.

[No output]
quartz wave
dense nova
#

oh

quartz wave
#

‫we're talking about strings where addition is not associative or commutative

dense nova
#

i see

#

did not know strings were allowed lmao

sick hound
#

@quartz wave what's the challenge now?

quartz wave
quartz wave
#

i literally don't know what the coding problem is

#

i just golf golfed solutions

sick hound
#

ill try to golf ypurs

gleaming linden
quartz wave
#

oh

sick hound
#
exec(bytes('浩潰瑲猠獹刊爽湡敧儊ⴽⰱⰰ਱ⱅ㵇㵓⸧✣䄊嬽⭅⭩⁅潦⁲⁩湩猠獹愮杲孶ㄭ⹝灳楬⡴尧❮崩圊氽湥䄨せ⥝䄊䔽圪⨬ⱁ⩅੗潦⁲⁙湩删ㄨ氬湥䄨⴩⤱瀺楲瑮:sparkles:⸧潪湩匨㉛⠭孁嵙塛㵝䜽㰩畳⡭㵇䄽奛礫孝⭘嵸潦⁲⁹湩儠映牯砠椠⁑晩礠硼㰩崴潦⁲⁘湩删ㄨ圬ㄭ⤩
','u16')[2:])```
dense nova
#

why

sick hound
#

cos it's shorter

versed eagle
quartz wave
versed eagle
#

oh

#

sorry

quartz wave
#

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)))

gleaming linden
#

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)))

finite blaze
#

D=-1,0,1

#

What's going on here?

long fulcrum
finite blaze
#

oh interesting

#

cool stuff

gleaming linden
finite blaze
#

i didnt know you can declare ranges like that

#

i need to remember it

gleaming linden
#

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

arctic skiff
#

7800 chars

placid fractal
#

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

versed eagle
#

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

rugged sparrow
night quarryBOT
#

@rugged sparrow :white_check_mark: Your 3.11 eval job has completed with return code 0.

001 | 1 [2, 3]
002 | [1] [1]
rugged sparrow
#

like that?

placid fractal
#

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

twin reef
#

Not technically a one-liner, and not quite equivalent, but the shortest so far

x, *y = value
y = y or x
placid fractal
#

value is an int or a tuple of ints

#

so it would be

x, *y = tuple(value)
y = y or x
rugged sparrow
#

!e py tuple(1) this raises an exception

night quarryBOT
#

@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
rugged sparrow
placid fractal
#

i just realized that

twin reef
#

(*value, )?

#

or even [*value]

rugged sparrow
twin reef
#

oh right...

placid fractal
#

sry its such a random question

earnest wing
#

wait, that doesn't work either

#

can't unpack at any point

placid fractal
#

that fails cuz *value wont work lol

earnest wing
#

wait, then why is the initial prompt "if len(value) == 1, how can I ..."

placid fractal
#

thats my fault

#

i like blanked and did that lmao

#

ig it should be len(list(val))

earnest wing
#

also doesn't work

placid fractal
#

so basically then id have to do
isinstance(val, int)

twin reef
#

or type(val)==int

placid fractal
#

right

placid fractal
#

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

echo viper
#

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

echo viper
echo viper
versed eagle
#

!ot

night quarryBOT
versed eagle
echo viper
long fulcrum
#

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))```
versed eagle
#
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

long fulcrum
#

prints a spiral from 0-99

long fulcrum
#

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))```
night quarryBOT
#

@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
versed eagle
#

should be fixed now

long fulcrum
#

somethings wrong with the brackets

versed eagle
#

fixed

long fulcrum
#

needs another bracket after the m+t in 3rd line as well

#

oh lines 2 and 3 can be combined now

versed eagle
#

fixed

long fulcrum
#

oh 2-4 actually

versed eagle
#

does it need to be a list?

#

why do you call list

long fulcrum
long fulcrum
versed eagle
#

ah yeah it does

long fulcrum
#
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))```
glass stone
#

!paste

#

it is not windows friendly if you run it

fluid canyon
#

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.

versed eagle
fluid canyon
#

thanks

versed eagle
#

in this channel, the type of help you will receive is not the type of help you want

glass stone
#

lol. come back later

versed eagle
#

why

fluid canyon
#

herald your a man you solved my problem

versed eagle
#

im not a man, but im glad i could help regardless.

glass stone
#

it's esoteric, you probably wou;ldn't understand

#

ya I will help you out in the help channel if you @ me

fluid canyon
#

no im good now but thanks

versed eagle
glass stone
#

😄 Awesome! It took long time to make

placid fractal
#

use the greek version of ;

glass stone
#

Herald I know that now, like I said it was written quite some time ago

versed eagle
#

ah

#

i see

#

i remember when i first found out about from thing import whatever statements

placid fractal
#

is it possible to do something along the lines of
(this is in C)

define True 0

define False 1

glass stone
#

I thought I was on to something with that too.

versed eagle
low lynx
#

@placid fractal

glass stone
#

from this import *

placid fractal
#

yeah that ^

placid fractal
#

i didnt see that lmao

low lynx
#

thank ionite

placid fractal
#

now we can make cursed code even more cursed

versed eagle
#

ah

versed eagle
#

(which also can be done)

placid fractal
versed eagle
#

ah

placid fractal
#

macros are much easier to make no?

versed eagle
#

not really

#

ionite did the bool thing in less than 10 lines

placid fractal
#

thats just insanely awesome

versed eagle
#

macros are relatively much harder to make (in python)

placid fractal
#

macropy maybe?

#

ah

versed eagle
#

AnonymousDapper has a macro project going iirc

#

and RocketRace has a project that does something similar as well

#

Cereal has a macro thingy also

placid fractal
#

interesting ok

versed eagle
#

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

placid fractal
#

I see

#

that makes sense tbh

#

basically a struct of macros really

versed eagle
#

yeah

#

well

#

sort of

#

really it depends how in depth you're willing to go

placid fractal
#

makes sense, tys tho

dry mirage
night quarryBOT
#

@dry mirage :white_check_mark: Your 3.11 eval job has completed with return code 0.

0 1
placid fractal
#

o dayum ok

dry mirage
#

!e or even

from einspect import view

view(False) << ("hi",)

for x in False:
    print(x)
night quarryBOT
#

@dry mirage :white_check_mark: Your 3.11 eval job has completed with return code 0.

hi
placid fractal
#

interesting

#

i feel like a noob rn, but ive never heard of einspect

versed eagle
#

its a really cool module made by ionite

placid fractal
#

i finally found the documentation

#

i love this

#

thank you ionite

low lynx
quartz wave
low lynx
#

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))
sonic birch
#

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

versed eagle
#

if its related to the esoteric python then sure

sonic birch
#

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

GitHub

Making crazy and, in general, useless stuff by abusing Python features - CrazyPython/typespace at main · LubomyrIvanitskiy/CrazyPython

GitHub

Making crazy and, in general, useless stuff by abusing Python features - CrazyPython/alt_imports at main · LubomyrIvanitskiy/CrazyPython

GitHub

Making crazy and, in general, useless stuff by abusing Python features - GitHub - LubomyrIvanitskiy/CrazyPython: Making crazy and, in general, useless stuff by abusing Python features

versed eagle
#

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

sonic birch
versed eagle
#

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?

old socket
#

Yea the decorator runs @ runtime so how does it work

#

well decorators should at least

versed eagle
#

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

sonic birch
#

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!

sonic birch
dry mirage
# low lynx i thought that would error because it was unsafe

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)
night quarryBOT
#

@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.
low lynx
#

offset in negative memory?

dry mirage
low lynx
#

ah I see

quartz wave
dry mirage
quartz wave
#

and it's aligned by 16?

dry mirage
#

like list().__sizeof__ includes the array for some reason

night quarryBOT
#

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```
night quarryBOT
#

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```
quartz wave
#

branchless ```py
ALIGNMENT_SHIFT = 3 + (sizeof(c_void_p) > 4)
ALIGNMENT = 1 << ALIGNMENT_SHIFT

dry mirage
#

trying to be same as cpython source tho 😔

quartz wave
#

fair

dry mirage
# quartz wave 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())
night quarryBOT
#

@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>)
sonic birch
#

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?

versed eagle
#

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

sonic birch
#

should I copy paste the function body in order to create the new function? Or what do you mean?

versed eagle
#

create a new function instance

sonic birch
#

Ah, you mean dynamically? Sounds reasonable, will try. Thanks

versed eagle
rugged sparrow
night quarryBOT
#

@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
rugged sparrow
#

^ 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
sonic birch
rugged sparrow
#

that would not modify the module globals, it only changes what foo thinks the module globals is

sonic birch
#

!e Global_Value

night quarryBOT
#

@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
rugged sparrow
#

yea, the line where I rebuild foo adds Global_Value to the dictionary

sonic birch
rugged sparrow
#

!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

night quarryBOT
#

@rugged sparrow :white_check_mark: Your 3.11 eval job has completed with return code 0.

injected
sonic birch
night quarryBOT
#

src/einspect/views/view_function.py lines 16 to 17

class FunctionView(View[FunctionType, None, None]):
    _pyobject: PyFunctionObject```
dry mirage
#

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
versed eagle
subtle solar
#

!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 = }")

night quarryBOT
#

@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
versed eagle
versed eagle
#

alr
was asking cause if you weren't planning on doing it, i was gonna offer to do it

dry mirage
versed eagle
#

alr! will do that

dry mirage
#

just need to define this as a new structs/py_code.py or something

versed eagle
#

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

dry mirage
#

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]
versed eagle
#

ah
that's nice

dry mirage
#

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]
sonic birch
gleaming linden
#

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

sonic birch
# gleaming linden that's a decotator

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

old socket
#

!e ```py
@type.call
class foo:
...

print(foo)

night quarryBOT
#

@old socket :white_check_mark: Your 3.11 eval job has completed with return code 0.

<__main__.foo object at 0x7f078da5ffd0>
old socket
#

You can imagine it like this as well

#

!e ```py
@lambda _: _()
class foo:
...

print(foo)

night quarryBOT
#

@old socket :white_check_mark: Your 3.11 eval job has completed with return code 0.

<__main__.foo object at 0x7f7e75bf4190>
sonic birch
rugged owl
sonic birch
old socket
#

ChaptGPT to prototype fast then bug fix afterwards for 8 hrs

rugged owl
#
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

versed eagle
#

wdym "snowflake id generation"

gleaming linden
#

^

versed eagle
#

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?

gleaming linden
#
import time
g=lambda:int(time.time()*1e3)<<22|8<<9
```-1c
sonic birch
# dry mirage in https://github.com/ionite34/einspect/releases/tag/v0.5.3

!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'])
night quarryBOT
#

@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'
rugged sparrow
#

!e ```py
a = {'a': 1}
b = a
b |= {'b':2}
print(a, b)
print(a is b)

night quarryBOT
#

@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
rugged sparrow
#

!e just like += for lists ```py
l1 = [1]
l2 = l1
l2 += [2]
print(l1, l2)

night quarryBOT
#

@rugged sparrow :white_check_mark: Your 3.11 eval job has completed with return code 0.

[1, 2] [1, 2]
sonic birch
#

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

rugged sparrow
#

!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)

night quarryBOT
#

@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],)
versed eagle
#

i dont think thats intended behaviour

rugged sparrow
#

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]))

versed eagle
#

huh

#

i didnt know it'd call setitem

rugged sparrow
#

!e import dis;dis.dis('x[0] += y')

night quarryBOT
#

@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
rugged sparrow
#

3.10 bytecode is more concise, but same concept

#

you can see that it calls the STORE_SUBSCR opcode

versed eagle
#

i would think that it would call tuple.__getitem__(([1], ), 0).__iadd__([2])

versed eagle
rugged sparrow
#
  • not all objects define __iadd__
versed eagle
#

hm

#

true

rugged sparrow
#

for example, strings

#

!e py x = list(['a']) x[0] += 'b' print(x)

night quarryBOT
#

@rugged sparrow :white_check_mark: Your 3.11 eval job has completed with return code 0.

['ab']
rugged sparrow
#

(also integers, floats and tuples)

versed eagle
#

right

#

but we're talking specifically about lists

#

which do

rugged sparrow
#

but the bytecode can't know that its working with a list

versed eagle
meager zinc
#

yes

rugged sparrow
#

INPLACE_ADD either does return stack[0].__iadd__(stack[1]) or if stack[0] doesnt have __iadd__ it does return stack[0] + stack[1]

versed eagle
#

alr

#

so it already handles the case where __iadd__ isnt defined

#

on the object

meager zinc
rugged sparrow
rugged sparrow
meager zinc
#

yes, I know

#

also have an assignment call afterwards

rugged sparrow
#

the assignment call always happens, regardless of the existence of __iadd__

quartz wave
rugged sparrow
#

yea, but INPLACE_ADD reads better lol

quartz wave
#

i wonder why they didn't just separate INPLACE_* from BINARY_*

rugged sparrow
#

because it is still a BINARY_OP

rugged owl
#

!e

from einspect import view

_ = view("true")
__ = view("false")

with _.unsafe() as un_:
  un_ <<= True

with __.unsafe() as un__:
  un__ <<= False

print("true", "false")
night quarryBOT
#

@rugged owl :white_check_mark: Your 3.11 eval job has completed with return code 0.

False False
rugged owl
#

What is happening here

quartz wave
#

in the end

#

!e ```py
from einspect import view

_ = view("true")

with .unsafe() as un:
un_ <<= True

print("true")

night quarryBOT
#

@quartz wave :white_check_mark: Your 3.11 eval job has completed with return code 0.

False
rugged sparrow
#

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'

night quarryBOT
#

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);
}```
dry mirage
night quarryBOT
#

@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
languid hare
#

!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")
night quarryBOT
#

@languid hare :white_check_mark: Your 3.11 eval job has completed with return code 0.

001 | True False
002 | True
languid hare
#

neat

low lynx
#

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')
night quarryBOT
#

@low lynx :white_check_mark: Your 3.11 eval job has completed with return code 0.

11
low lynx
#

eh

#

!e

from einspect import view

view(str)['__add__'] = lambda n, m: 3

with view('1').unsafe() as un1:
    un1 <<= 1

print('1' + '1')
night quarryBOT
#

@low lynx :white_check_mark: Your 3.11 eval job has completed with return code 0.

11
low lynx
#

what

dry mirage
low lynx
#

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)
night quarryBOT
#

@low lynx :white_check_mark: Your 3.11 eval job has completed with return code 0.

2
low lynx
#

what

dry mirage
#

well it's not str add since you moved it to an int

low lynx
#

!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)
night quarryBOT
#

@low lynx :white_check_mark: Your 3.11 eval job has completed with return code 0.

11
low lynx
#

int add isn't it either

dry mirage
#

so I think you overriding int add like that broke the offset calculation for the move afterwards

low lynx
#

ah

dry mirage
#

!e

from einspect import view

view('1') << 1

view(int)['__add__'] = lambda n, m: 3

x = '1'
print(x + '1')
night quarryBOT
#

@dry mirage :white_check_mark: Your 3.11 eval job has completed with return code 0.

3
low lynx
#

what

#

ohh so the offset was why i had to do unsafe()

#

that kinda makes sense

dry mirage
#

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)
night quarryBOT
#

@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.
dry mirage
#

3 bytes into allocated space of 0 bytes

yeah 🥴 completely brok

low lynx
#

wow something is being stored in 0 bytes?

#

we just broke information theory

dry mirage
#

!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)
night quarryBOT
#

@dry mirage :white_check_mark: Your 3.11 eval job has completed with return code 0.

[1, <NULL>, 3]
low lynx
#

does that make the int 2 into NULL or just the list item?

gleaming linden
#

just the item I think

dry mirage
#

!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])
night quarryBOT
#

@dry mirage :warning: Your 3.11 eval job has completed with return code 139 (SIGSEGV).

[No output]
low lynx
#

huh

#

wait so why are you using view().item instead of __setitem)__ or []

quartz wave
#

!e ```py
from einspect import view, NULL

t = [1, 2, 3]
view(t).item[1] = NULL

print(repr(t[1]))

night quarryBOT
#

@quartz wave :warning: Your 3.11 eval job has completed with return code 139 (SIGSEGV).

[No output]
quartz wave
#

aw

dry mirage
#

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])
night quarryBOT
#

@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>
dry mirage
#

otherwise it literally sets that PyObject pointer as an object

low lynx
#

ah

cedar isle
#

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

night quarryBOT
#

8. Do not help with ongoing exams. When helping with homework, help people learn how to do the assignment without doing it for them.

cedar isle
#

Was this directed at me? ^

#

if so, not been a student in a few decades lol

#

this is evil of my own concoction

versed eagle
#

my guess is that someone else sent a message

#

and they deleted it after the rule was brought up

cedar isle
#

oh lol, derp

#

Pipe | (PipeGen | range(10) | (lambda x: (i ** 2 for i in x))) | list | print

#

its evil lol

cedar isle
sonic birch
cedar isle
#

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

sonic birch
#

Few months ago I tried to implement similar library. Not finished so far)

cedar isle
#

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

sonic birch
#

Any links? Sounds interesting

night quarryBOT
cedar isle
cedar isle
cedar isle
#

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
sonic birch
#

Why do you want to have it on Python. Why do not use the pure EBNF? Just for fun?

versed eagle
#

it'd be closer to the ebnf syntax then

old socket
#

Wasn't there a way to compile multiple lines in together

#

I forgot a lot about regex stuff

#

By lines I mean regular exprs

versed eagle
#

you mean where it would have to match all of the ones passed to succeed?

old socket
#

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

versed eagle
#

that's possible

#

regex can match multiple exprs

old socket
#

Oh yea possible, just use groups as meta data

#

So when you match, check group name to determine token kind

eager ore
#

@old socket

sick hound
#

Hello, does anyone know how to create a perceptron in python? help me please

old socket
#

@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

old socket
#

Oh I had to add an incrementaldecoder

sick hound
#

no idea honestly, I just tell people to copy manually lol

old socket
#

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

sick hound
#

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

old socket
#

Did you do ```toml
[tools.poetry]
build = ...

sick hound
#

you will still have old bytecode if you change only the encoder, and not update the script using it and try importing it

old socket
#

How do I update the cache?

#

I was planning on taking in the bytes, turning it into a string then lexing & parsing

sick hound
#

if you delete __pycache__ it'll get regenerated

old socket
#

then after parsing use a visitor to spit out a huge ast.Module

#

then ast.unparse

sick hound
#

depends on what you want to do

old socket
sick hound
old socket
#

So If I made any updates to the compiler it'll use old bytecode unless pycache is deleted

sick hound
#

wait no that doesnt use codecs yet

old socket
#

And as long as I add each of the ast nodes it'll be interop

sick hound
#

there's only like 20 lines of code doing parsing

old socket
#

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

sick hound
#

you just return valid code from your codec

old socket
#

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

sick hound
#

return len(input)

#

not data

old socket
#

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?

sick hound
#

it's the amount of bytes consumed from input (if it's less than input's length the function will be called again)

sick hound
old socket
#

Oh, so you just get the length on the input since you can assume all the bytes had been read

#

I see

sick hound
#

somehow there's even wrong stubs for this

old socket
#

I guess you can also do BytesIO and read line by line

#

then use .tell

sick hound
#

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

old socket
#

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
old socket
#

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

quartz wave
sick hound
quartz wave
#

because in mine it's an objective to keep it as-is

sick hound
#

with lispy it doesn't matter cuz it build's it's own thing and executes it

#

pypp though.. lol

#

the input for that

old socket
#

Is input of decode for codec only memoryview when an error happens?

meager zinc
#

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)

languid hare
#

macro hell

meager zinc
#

The implementation details are pretty smart

#

it uses ##encoding pypp and preprocesses it by manipulating the encoding

sick hound
#

Hi I’m back

old socket
#

I'll need to make a node visitor class then check column and line numbers to manually indent

dry mirage
#

sort of equivalent to a python to C transpiler calling the python subprocess from C

meager zinc
dry mirage
#

it only needs to be functionally equivalent, not implementation details though?

meager zinc
#

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

dry mirage
#

why would you have a floating point error with python floats pithink

meager zinc
#

No, in C you can have a floating point error (underflow/overflow)

#

and then catch it

#

lemme find an example

dry mirage
#

right, but surely you can do the same functional thing without messing with float errors?

meager zinc
#

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)

dry mirage
night quarryBOT
#

@dry mirage :white_check_mark: Your 3.11 eval job has completed with return code 0.

001 | 1e-40
002 | 1e-40
dry mirage
#

this all just works without errors

meager zinc
#

Which is also technically a problem

meager zinc
dry mirage
#

an implementation that relies on float errors can be refactored to not

meager zinc
#

true

dry mirage
#

like functionally you want to calculate Fibonacci sequences, it doesn't matter how you get there

meager zinc
#

but refactoring on a scale like that is not typically possible in a transpiler

sinful stirrup
#

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]
past plank
#

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]
languid hare
#
[[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

versed eagle
#

for p in [m] feels wrong

languid hare
#

yea i wasnt too sure what that was for either

versed eagle
low lynx
#

range(n-1) is shorter as [0]*~-n I think

meager zinc
#

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]
languid hare
low lynx
#

does this even work

meager zinc
#

Good question

versed eagle
#

i don't even know what is supposed to do

#

in the first place

low lynx
#

!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)
night quarryBOT
#

@low lynx :white_check_mark: Your 3.11 eval job has completed with return code 0.

[[1597, 987], [987, 610]]
low lynx
#

no it doesn't

languid hare
#

ive no idea if that is right

meager zinc
#

!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(R
C for R,C in zip(r,c))for c in zip(m)]for r in m]for _ in[0]~-n][-1])

night quarryBOT
#

@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]]
meager zinc
#

Nope, they are functionally equivalent

versed eagle
#

(what is it supposed to be doing here)

low lynx
#

did the original even work

meager zinc
#

Matrix power

meager zinc
languid hare
#

mm

versed eagle
languid hare
#

is it updating m in place or having that expression be the power, with m modified along the way

sharp moon
meager zinc
#

!e ```py
import numpy as np
x = np.arange(1, 10, 1).reshape(3,3)
y = np.matrix(x)

a = y**3
print(a)

versed eagle
night quarryBOT
#

@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]]
low lynx
#

!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])
night quarryBOT
#

@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]]
low lynx
#

wait wtf

#

numpy?

meager zinc
languid hare
#

uhh

#

lmao

#

oh

versed eagle
languid hare
#

m got updated

meager zinc
low lynx
#

ah

versed eagle
languid hare
#

!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)
night quarryBOT
#

@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]]
versed eagle
#

you can't multiply lists

meager zinc
#

Heh

sharp moon
low lynx
#

!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])
night quarryBOT
#

@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]]
low lynx
#

...

meager zinc
#

Interesting

languid hare
#

oh piss

low lynx
#

am I bad at numpy

languid hare
#

** is elementwise

meager zinc
#

the original didn't even work

low lynx
#

ahhh

#

ofc

languid hare
#

!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

#

..

night quarryBOT
#

@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]]
languid hare
#

there

meager zinc
#
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]
languid hare
#

fyi original broke for n = 0 and 1

meager zinc
versed eagle
#

the goal is to function the same as the original, no?

languid hare
#

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 :)

meager zinc
#

I would suppose so

versed eagle
#

doesn't matter if the original is flawed, as long as ours has the same flaw

meager zinc
#

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]
languid hare
simple sphinx
#

I made a thing I think people here would like, here is a kata about minimalist python:
https://www.codewars.com/kata/63d4b700bce90f0024a9ca19

Codewars

Background
After being inspired by Marie Kondo's teachings on minimalism, you've decided to apply her principles to your computer science work. You've noticed that your keyboard has 104 keys and ...

versed eagle
#

exciting

versed eagle
#

!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))
night quarryBOT
#

@versed eagle :white_check_mark: Your 3.11 eval job has completed with return code 0.

3 1
versed eagle
versed eagle
#

<@&831776746206265384> unrelated to channel topic, and sending the same message in multiple channels rapidly

#

also, is a scam

simple sphinx
#

heck yea I love crypto bots 😄

versed eagle
simple sphinx
#

lol

sinful stirrup
#

!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))
night quarryBOT
#

@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]]
sinful stirrup
#

🤔

#

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)

sinful stirrup
low lynx
#

!e

from numpy.linalg import matrix_power
arr = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print(matrix_power(arr, 8))
night quarryBOT
#

@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]]
low lynx
#

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))
night quarryBOT
#

@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]]
low lynx
#

oh nvm

sinful stirrup
earnest wing
#

numpy doesn't repr with commas

#

they're a lot of noise when you have multidimensional arrays

low lynx
#

numpy also uses ellipses when it gets big

#

!e

import numpy as np
print(np.ones((100, 100)))
night quarryBOT
#

@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.]]
old socket
#

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

proper vault
#

they are needed for consistency with 3d arrays afaik

vernal pivot
#

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))
night quarryBOT
#

@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.]
vernal pivot
#

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

quartz wave
old socket
low lynx
#

you also need them for higher dims

#

!e

import numpy as np
print(np.zeros((3, 3, 3, 3, 3)))
night quarryBOT
#

@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

earnest wing
night quarryBOT
#

@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

earnest wing
#

well looks like that was already answered above

dry mirage
versed eagle
#

cool

low lynx
#

ooh nice

#

!e

from einspect import view

view(True).swap(False)
print(True, False)

while True:
    pass
else:
    if False:
         print('cursed')
night quarryBOT
#

@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'
low lynx
#

aww

rugged owl
meager zinc
low lynx
#

I figured it might

#

wonder if putting it in a function would change things

versed eagle
#

since it'd still get const folded

#

it should work with bool() though

#

since that's not a constant

topaz haven
#

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

lavish dirge
#
pure dew
lavish dirge
#

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.

pure dew
#

oh damn ok

lavish dirge
#

Sorry should have said that first

pure dew
#

why python as a base tho?

#

why not a simpler custom parser?

lavish dirge
#

Able to disable character length limiter.

versed eagle
#

since each word would be continually defined by more words

#

which are also defined by words

#

and so on

lavish dirge
#

Evolutionary algorithm base in more better terms

#

Infinite addition of words yes.

pure dew
lavish dirge
#

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

versed eagle
#

how is the definition compilation not infinitely recursive

pure dew
#

but why python syntax? wouldn't it have been easier to build your own parser that processes the input into a super simple tree?

versed eagle
#

unless you have some words which are given "constant" definitions, with no other words in them (i.e. stopping points for the recursion)

pure dew
#

i really wanna see the code

versed eagle
#

im quite curious as well lmao

lavish dirge
#

Add me on discord. What time zone you both in

versed eagle
#

why?

lavish dirge
#

I'm in eastern

#

Respect to time difference

versed eagle
#

ah

lavish dirge
#

12am here

versed eagle
#

its fine for you to message me whenever
i turn notifications off for when i sleep so it wont wake me up or anything

pure dew
#

wdym add you? friends?

lavish dirge
#

Yeah I don't mind

pure dew
#

i'm eastern but DND is a lifesaver

lavish dirge
#

I'm eastern time too

versed eagle
lavish dirge
#

By the way if used in cmd it is recursive

#

But not python. Do you know why

versed eagle
lavish dirge
#

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.

versed eagle
#

hm

lavish dirge
#

Python will not compile the definition unless the words within the definitions are defined as well

versed eagle
#

so then how do you compile the first word definition

lavish dirge
#

To compile the first word I had to define power

versed eagle
#

if it wont compile until all the words in it are defined

lavish dirge
#

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

pure dew
versed eagle
#

alr

pure dew
#

honestly man I'm having trouble understanding your explanations

#

is there a paper on this?

lavish dirge
#

Yes as a matter of fact and there is a new method other than binary for it to run

pure dew
#

i would love to hear more, but this might not be the channel for extended discussion

#

mm no threads either

lavish dirge
#

We could both start a group chat if that helps.

rough moat
#
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
#

!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)])))
night quarryBOT
#

@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

low lynx
#

...

rough moat
#

teehee

#

owo in one line of code

low lynx
#

I shall golf once my internet returns

olive aspen
#

i was looking through the discord randomly n see that pop up instantly

#

quite the treat

rough moat
#

its not necessarily as short as possible, i just wrote it while bored

low lynx
#

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)))
versed eagle
#
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

quartz wave
#

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)))

low lynx
#

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)))
quartz wave
#

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)))

low lynx
#

anything possible with switching to mod stuff and cutting out the second for loop?

gleaming linden
#

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)))

low lynx
#

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)))
quartz wave
gleaming linden
#

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)))

quartz wave
#

aw

gleaming linden
#

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)))

low lynx
#

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

low lynx
#

from the original

#

it doesn't matter ig

#

an OwO is an OwO

quartz wave
#

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)))

low lynx
#

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))
tough willow
#

exec(bytes('潦⁲⁹湩爨㴺慲杮⡥〶⤩瀺楲瑮✨⸧潪湩✨袖嬧㰵扡⡳⭸樱礪ㄭ樰ㄭⴰ⭸╸〳㰩漷⵲㰷⵹㘱〼⠼⁸湩㉻ⰰ〳潽⡲⭸⵹⤳㠥㈼砼ㄭ㰸漷⡲⵸⥹㠥㐾砼㈭㰰〱崩潦⁲⁸湩爠⤩','u16')[2:]) 100 characters if you dont count bytes

burnt pasture
flint hollow
#

x.__class__ is the same as type(x) at least

rugged sparrow
night quarryBOT
#

@rugged sparrow :white_check_mark: Your 3.11 eval job has completed with return code 0.

__init__
rugged sparrow
#

combined with getattr and setattr you can bypass underscores being blacklisted

versed eagle
rugged sparrow
#

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

versed eagle
#

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

rugged sparrow
versed eagle
#

wdym "allow a limited subset"

rugged sparrow
#

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

versed eagle
#

the primary tool would be recursion

#

any time a code object is constructed, recurse onto it to check the bytecode

rugged sparrow
#

that doesnt take into account other methods of code exec

versed eagle
#

and then do the same for other such events that allow things that you don't want to allow

rugged sparrow
#

at the assembly level

#

memory corruption -> code exec

versed eagle
#

how would you achieve memory corruption then?

rugged sparrow
#

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

versed eagle
#

can you provide an example

rugged sparrow
#

!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)

night quarryBOT
#

@rugged sparrow :white_check_mark: Your 3.11 eval job has completed with return code 0.

<memory at 0x7fda32538a00> 9223372036854775807
rugged sparrow
#

@versed eagle ^ that one exploits property

#

so no imports, and no code objects

#

and nothing that looks inherently malicious

versed eagle
#

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?

rugged sparrow
#

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

versed eagle
rugged sparrow
#

how do you validate that

#

what determines whether a memoryview should have access to a given range

rugged sparrow
versed eagle
#

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

rugged sparrow
#

in that example, I construct the bytearray manually, with fully controlled arguments. I control ptr and size_of_object

versed eagle
#

even if you can control size_of_object, how would you control ptr?

rugged sparrow
#
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

versed eagle
#

so, disallow interpreting a user modified memoryview as a PyObject*

#

char* only

rugged sparrow
#

how could you do that? I never modified the memoryview directly

burnt pasture
#

@rugged sparrow sorry, i missed all this. in the blog post, getattr is removed because __builtins__ is empty.

rugged sparrow
#

so you would fully disable memoryview's in your "sandboxed" python?

versed eagle
#

no
you can build memoryviews, read from them, etc

#

just not write to them

versed eagle
rugged sparrow
rugged sparrow
#

i just did it for ease of coding

versed eagle
#

this is more like shooting python in the leg and then chaining it down

#

rather than sandboxing

rugged sparrow
#

i could have done it with bytearrays

#

or bytes

#

or strings

versed eagle
#

strings aren't meant to be mutable anyway

rugged sparrow
#

i don't have to write into the object at all

#

i would just construct it inplace

versed eagle
#

can you provide an example of that please?

rugged sparrow
#

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'),
  ...
])```
versed eagle
#

and then you would construct a memoryview of that to get access to the process memory?

rugged sparrow
#

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
versed eagle
#

so, disallow any addresses where the first 8 bytes = 1

rugged sparrow
#

lol

#

thats all PyObjects with a refcount of one

versed eagle
#

that seems simple to fix

versed eagle
rugged sparrow
#

so now you never free memory

versed eagle
#

garbage collect when refcount = 1

#

instead of 0

rugged sparrow
#

if you add that hook, then now the bug triggers fine with address where the first 8 bytes equal 2

versed eagle
#

disallow self reference in __del__

rugged sparrow
#

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

versed eagle
rugged sparrow
#

how can you check if a type is real

versed eagle
#

check if it's valid

rugged sparrow
#

what defines valid

versed eagle
#

no arbitrary code exec

rugged sparrow
#

(fyi, you are not gonna win this one lmao)

versed eagle
rugged sparrow
#

it could be a valid type, but the instance is fake and holds a pointer that is freed by the types tp_free

versed eagle
#

i think that its theoretically possible

#

given infinite time and computing power

rugged sparrow
#

oh well with that small caveat

versed eagle
rugged sparrow
#

if you were to build this system, you would have to be able to prove that it is safe for every possible input

versed eagle
#

e.g. in math, pythag theorem can be proven without testing every single possible input

versed eagle
#

which im not talking about doing

rugged sparrow
#

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...

versed eagle
rugged sparrow
versed eagle
#

how so?

rugged sparrow
#

once you bring in infinite time, the theoretical system is useless

versed eagle
#

again, how so

#

you were saying that it's not possible at all
im saying that it's possible, but not practically possible

rugged sparrow
#

its not possible

#

not while allowing a full set of python syntax and the current implementation + spec

versed eagle
#

i mean the whole point was to disallow underscores