« first day (4370 days earlier)      last day (802 days later) » 

05:51
We do have some vague stuff for "loop over the dict", and there's more related discussion in my room now
 
7 hours later…
13:17
Can someone reopen this question please ? It has wrongly been flagged as duplicated question about permutations, but that's clearly not. I've edited my original post to add an example. stackoverflow.com/questions/73935184/…
@Betcha It's been reopened, but I'm not sure if that's a good idea in its current state. You may want to edit it further.
13:45
The first sentence in that question has the same energy as these kinds of beginner comments
# print the number
print(number)
@MisterMiyagi, thank you. I'm really struggling to understand what is unclear with my question and what could make it more clear... But I don't doubt it was, according to all the people who do not get my point :(
Problems related to permutations can be quite tricky to describe in concise yet objective terms
I think I got the point, however
You should add the input that you used to generate your expected output
But I've never said the word permutation though... :D
In a sense, the function get_appendable_values is the input
13:50
...what
There is no input indeed... We only need to be able to call get_appendable_values
We start with an empty sequence
Are we doing static code analysis? Or brute forcing inputs?
It's an object whose precise details are generally unknown and may vary from execution to execution. Sounds like an input to me.
I'd say that's kind of a tree exploration problem
In any case, what do you think of the answer I posted? Am I in the right ballpark?
13:52
Ah, we start with an empty list? That's a critical piece of information that's missing from the question
I did have to make a small leap of faith that we start with an empty list, because get_appendable_values([]) crashes with an IndexError
@Kevin, that looks great to me. Let me just double check. But at least you are the first one who got the point
Visualizing the process that generates your desired output would go a long way. Something like this maybe
Step 1:
    list = []
    get_appendable_values([]) = [0, 9]
    possible_result_1 = [0]
    possible_result_2 = [9]

Step 2:
    list = [0]
    get_appendable_values([0]) = [0, 9]
    possible_result_1 = [0, 0]
    possible_result_2 = [0, 9]
I call this problem "permutation related" not because the solution involves permutations in the strictest sense of the word. But it does involve creating a series of lists according to logic that can be defined recursively, which is a quality it shares with permutations/combinations/etc.
@Aran-Fey, yes but at Step 2 there is also [9,0] and [9,9]
14:00
That's step 3
@Betcha what make it unclear to me is the example/desired output you used. Like, if you wanted every permutation/possible sequence of N elements, that's easy to understand, but the confusing part lies either on "sequential rules" or the numbers used in your example, such as 9, 12, 4 and 7, which is confusing given it's hardcoded in the get_appendable_values function.
@NordineLotfi, right ! I initially did not want to give any implementation of that function, because I wanted the algorithm to be agnostic to that. But then a lot of people did not get my point and asked for an example of expected result, which forced me to write a dummy implementation
What I find interesting about the problem is that the logic can be used to implement both permutations and combinations, if you define get_appendable_values in particular ways. For example pastebin.com/raw/xE7Thc25. And I'm sure there are lots of other interesting results you can get beyond just those two.
@Betcha I see :) can you maybe clarify the use cases or a more agnostic implementation? I played around with permutation myself a while ago, but I have to admit, I'm kind of confused in this case
@Kevin :O yeah, I guess this make more sense now. This looks really useful
Oops, I got the terminology mixed up. When I said "permutation", I meant "cartesian product", and when I said "combination", I meant "permutation"
Now with correct terminology, and an extra demo: pastebin.com/raw/Mud9qCwd
14:16
For your information, my use case is related to trick-card game. I want to be able to generate all possible tricks that can be played with respect to the players cards. Player can only play legal cards. What defines a legal card are complicated rules based on the sequence of previous cards.
Interesting :-)
Trick taking game
A few things have changed in the 6 years since that article was written...
Anybody else notice all the pipes and weird gravity this morning?
@0x263A hmm? do you mean on SO or irl?
14:26
it seems that Aran-Fey's plan to turn the universe into Flappy Bird is going according to schedule
Things look normal around here but I'm optimistic that my local reality will get rewritten before my long work meeting this afternoon
14:47
I think I may have messed up one of the frame-perfect inputs. Will try again next week
15:16
@Betcha I've taken the liberty to edit the question to say that the empty list is the starting point. That should clear up most of the confusion by making it actually solvable (RE: my earlier comment that it won't be in the generic case). You still might want to extend the question with a short sample on how the first output case [0, 0, 4, 7] would be derived, since that alone is far from obvious (prominently, where the duplicate 0 comes from).
 
1 hour later…
16:23
I am trying to invent a new kind of recursion which is even more confusing than normal. It's going well, or perhaps terribly. It's not easy to tell.
Seems like you succeeded then, doesn't it?
@Kevin It's going well, or perhaps, well, or perhaps, well, or perhaps, well, or perhaps, well, or perhaps, well, or perhaps, well, or perhaps, well,,,,, terribly
Accurate
17:02
#old and boring recursion
def f(x):
    if x == 0:
        return "0"
    else:
        return "(" + f(x-1) + ")"
print(f(5)) #(((((0)))))


#cool new recursion
compose = lambda a, b: lambda x: a(b(x))
def g(predicate, default, pre, post):
    def h(x, pending_calls=lambda x:x):
        if predicate(x):
            return pending_calls(default)
        else:
            return h(pre(x), compose(pending_calls, post))
    return h

j = g(lambda x: x == 0, "0", lambda x: x-1, lambda x: "(" + x + ")")
Because of the way that the pending calls get passed through one context to another, I have decided to call this approach "threading"
 
1 hour later…
18:03
I spent the whole day trying to do the equivalent of def a_classmethod(cls: Type[T]) -> T: in TypeScript, only to learn that it's not possible. So I'm starting a petition to rename that language to JokeScript
Introducing a new language, ScapeGoat. Anything you want to do is both possible and stylistically approved in ScapeGoat.
If you go to the ScapeGoat forums and ask, "how do I do X to achieve Y?", and someone replies "why would you want to do that?", they will immediately be suspended for a week
If you try to do something in ScapeGoat and it doesn't work, it is ScapeGoat's fault, guaranteed
Okay I know this isnt the right chat room but the java one is empty and hoping some sr devs could point me into a good book for Java Troubleshooting. I have an interview coming up for a Support Engineer role and have everything but the java experience, but I do have C# and python so figured it cant be too much work to learn a little before
It's not the right chat room, but I sympathize with your plight
Yeah, figured Id toss something out here to just see. Ill ask in java and see if anyone is just lurking
18:19
I consider C# to be pretty Java-like, so you've got that
Thats what Ive seen based on stuff Ive looked at. Would rather this job be C# but eh Id like to learn what I can from them
 
1 hour later…
19:32
SyntaxError: too many nested parentheses -- I'll tell you when I've had enough, Python!
19:43
Something tells me that you didn't write all those parentheses manually. In which case I can only recommend bypassing the need for a parser and programmatically generating an AST instead of code
I will ponder this approach, and whether it defeats the purpose of the silly thing I'm trying to do
Maybe if I inspect the AST and search for the exact point where a 200-times-nested function call is about to occur, and rewrite it so it stops at 199...
# e.g. This
a(b(c(d(e(f(g(h(x))))))))

# becomes this
y = e(f(g(h(x))))
a(b(c(d(y))))
But y'know deeper
I think if you have it as an AST you've already won. At that point you just run it
tree = ast.parse('print(3)')
code = compile(tree, "<Kevin's brain>", 'exec')
exec(code)
19:58
Hey guys, how might I go about making some kind of switch to detect gamepad button presses? I'm using psychopy's Joystick class, which uses pygame. I have a method to detect when a button is pressed, but the problem is it detects the press on every frame that I have my finger down (~15-20 frames per button press). I need some kind of "switch" that turns on on the first detected button press frame, does all the logic associated with the press,...
then turns off for the rest of the frames that my finger is down.
Sorry if it's dummy easy logic but I keep tripping myself up over it
In many frameworks, there is an event that occurs "on button up" and "on button down". Maybe the framework you are using has something similar?
Here are the docs for psychopy.hardware.Joystick: psychopy.org/_modules/psychopy/hardware/joystick.html#Joystick. I haven't checked pygame's docs but so far I see no such implementation
Perhaps the real docs and not the source code would be more helpful: psychopy.org/api/hardware/joystick.html
Yeah, pretty sure something based on pygame won't have something as fancy as events. They're fans of polling in a while True: loop
oh boy
@Code-Apprentice Do you know of any framework in particular that handles events like this? I may consider switching to it if this gets too hairy
Might be worth looking for other modules that let you get joystick inputs
20:08
pygame has a joystick class built-in pygame.org/docs/ref/…
@0x263A Yes but the only method potentially useful there to my use case is Joystick.get_button, which does the same thing my current implementation does
Partial victory. An AST constructed without using parse indeed does not suffer from the 200 nested parentheses limit. You still get RecursionError at ~1000, but a 5x gain isn't so bad. pastebin.com/raw/bJL3X2Vx
Specificially it's ast.fix_missing_locations that crashes with RecursionError. In principle, I don't have to use that. I just can't be bothered to figure out what it does and do it myself.
> You've earned the "Populist" badge (Highest scoring answer that outscored an accepted answer with score of more than 10 by more than 2x) for "Calling parent class __init__ with multiple inheritance, what's the right way?".
Only took 194 upvotes 😎
@Catyre Ah, I misunderstood what you needed.
@Catyre Keep two variables: one for the state of the button in the current frame, and one for the state in the previous frame. When the current state is "down" and the previous state is "up", perform your event. If they're both "down", do nothing.
20:24
@Kevin That just might work. Thanks for the suggestion!
Code: *does nothing*
`while True:` loop: Do it again!
when you said "!" that reminded me of the tags page from pygame's website: pygame.org/tags
"ALL the Tags!" they said. Sure, I wouldn't have noticed :o

« first day (4370 days earlier)      last day (802 days later) »