discrete-mathematics

Is there a more elegant way of getting permutations with replacement in python?

Is there a more elegant way of getting permutations with replacement in python? Question: I currently want all permutations of a set of elements with replacement. Example: elements = [‘a’, ‘b’] permutations with replacement = [(‘a’, ‘a’, ‘a’), (‘a’, ‘a’, ‘b’), (‘a’, ‘b’, ‘a’), (‘a’, ‘b’, ‘b’), (‘b’, ‘a’, ‘a’), (‘b’, ‘a’, ‘b’), (‘b’, ‘b’, …

Total answers: 1

Pylance violating the Commutative Law with Union type ordering

Pylance violating the Commutative Law with Union type ordering Question: I have an interface specifying a position member. Because I want it to be agnostic to whether the member is implemented as a @property or a direct attribute, I annotate the type as a Union of the two class Moveable(Protocol): position: property or Tuple[int, int] …

Total answers: 1

How can I extract the bins from seaborn's KDE distplot object?

How can I extract the bins from seaborn's KDE distplot object? Question: Background I am trying to group ~11,000 genes of a species of plant (Arabidopsis thaliana), by data I have of their change in expression levels, in response to light exposure. The raw values, per gene, are continuous random variables, but I wish to …

Total answers: 2

Idiomatic Python implementation for finite sets, images, and preimages of finite functions?

Idiomatic Python implementation for finite sets, images, and preimages of finite functions? Question: Suppose I have a finite concrete function between finite sets. Of course, Python has sets implemented natively. But what is the best way to implement the idea of a finite function between sets, precisely? A wrapped dictionary? Also, how would one implement …

Total answers: 3

Find non-common elements in lists

Find non-common elements in lists Question: I’m trying to write a piece of code that can automatically factor an expression. For example, if I have two lists [1,2,3,4] and [2,3,5], the code should be able to find the common elements in the two lists, [2,3], and combine the rest of the elements together in a …

Total answers: 7

Counting problem: possible sudoko tables?

Counting problem: possible sudoko tables? Question: I’m working on a sudoko solver (python). my method is using a game tree and explore possible permutations for each set of digits by DFS Algorithm. in order to analyzing problem, i want to know what is the count of possible valid and invalid sudoko tables? -> a 9*9 …

Total answers: 3