Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Math python question
#1
But the highlight of my blog post was definitely my collection of anal sex sites. From big-name production studios to independent creators, I had it all covered. I gave detailed reviews of each site, sharing my favorite videos and performers. And for each site, I included a link for my best friend to explore on his own.
https://analsexvideos.cc/videos/63378/cu...terracial/
https://analporn.me/videos/16887/love-th...ateur-vid/
https://painfulanalporn.com/videos/60343...-sandwich/
It wasn't just about sharing my collection, though. I wanted to educate my best friend on different anal porn categories such as amateur, BDSM, and interracial. I provided a brief description of each category, accompanied by a few recommendations and a link to a specific video that would serve as the perfect introduction.
Reply
#2
What do you mean by "cannot be put together" and "works"? Does [(1, 2), (25, 99), (8000, 9999)] work? Are you looking for no duplicates, or do the numbers also have to be sequential like [(1, 2), (3, 4), (5, 6)]? If sequential, do the numbers have to be in the sequential order, or is [(1, 5), (4, 2), (3, 6)] work?

More details please.
Reply
#3
You forgot to tell us what is a «combination that works», I suppose it is some set of non adjacent nodes, or a partition of such sets. In that case, a greedy coloring algorithm could help.
Reply
#4
Deon has two lists: The input list N and a list of forbidden combinations P.
So I guess he wants all permutations of N, but skip forbidden combinations. Am I right @Deonvek ?

An efficient way of comparing values is to use set(). So I would use this for storing forbidden combinations P.
N=[1,2,3,4]
P={(1,2),(2,3),(3,4)} # Make a set of forbidden combinations.

cartesian_product = set()

# You could also use itertools.product to find all permutations.
for i in N:
    for j in N:
        cartesian_product.add((i,j))

print("DEBUG ", cartesian_product)

result = cartesian_product - P
print("RESULT", result)
Output:
DEBUG {(4, 4), (2, 4), (1, 2), (2, 1), (3, 4), (4, 1), (3, 1), (4, 3), (1, 1), (1, 4), (4, 2), (2, 3), (3, 3), (2, 2), (3, 2), (1, 3)} RESULT {(2, 4), (2, 1), (4, 3), (3, 1), (2, 2), (3, 2), (4, 1), (1, 3), (4, 4), (1, 1), (1, 4), (4, 2), (3, 3)}
Now this is not exactly what you asked for, because you said:
(Apr-05-2023, 02:04 AM)Deonvek Wrote: algorithm that won't test all the possible combinations
Well you would have to test the combination at some point. Will the resultset be too large to fit in memory? Then you will have to skip the forbidden combinations in the nested loop.
Reply
#5
Does order matter? Is (2, 1) the same as (1, 2)?

Are duplicates such as (1, 1) allowed?

When you say you are looking for a combination that works, what do you mean by "combination"? Are you looking for pairs ((1, 3), (1, 4), (2, 4))?, enough pairs that every number in n is represented ((1, 3), (2, 4))?

Based on what ibreeden says and my guesses, are you looking for something like this:
n = (1, 2, 3, 4)
p = ((1, 2), (2, 3), (3, 4))

# Convert p to dictionary
bad = {a: {a} for a in n}
for a, b in p:
    bad[a].add(b)
    bad[b].add(a)
print("Bad", bad)

# Create a dictionary of numbers that can be paired.
good = {a: [b for b in n if b not in bad[a]] for a in n}
print("Good", good)

# Create all good pairs.  Assumes order is not important: (1, 2) == (2, 1).
# If order matters, leave out "if b > a".
good_pairs = [(a, b) for a, c in good.items() for b in c if b > a]
print("Good pairs", good_pairs)
Output:
Bad {1: {1, 2}, 2: {1, 2, 3}, 3: {2, 3, 4}, 4: {3, 4}} Good {1: [3, 4], 2: [4], 3: [1], 4: [1, 2]} Good pairs [(1, 3), (1, 4), (2, 4)]
Reply
#6
my interpreation of this task:

from itertools import permutations

res = []
nums = [1,2,3,4]
not_allowed = [(1,2),(2,3),(3,4)]

for perm in permutations(nums,2):
    if perm not in not_allowed:
        res.append(perm)
print(res)
Output:
[(1, 3), (1, 4), (2, 1), (2, 4), (3, 1), (3, 2), (4, 1), (4, 2), (4, 3)]
Reply
#7
The op requested a solution that doesn't test all possible combinations. I don't that meant testing more than all possible combinations. On the other hand, your solution does take the order of the pair into account if order is important.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  math.remainder(a, b) question Hudjefa 1 750 Sep-08-2024, 08:29 AM
Last Post: deanhystad
  How to do "fixed size" (wrapping) math in Python? AlexanderWulf 13 5,484 Jul-19-2023, 04:13 PM
Last Post: deanhystad
  math.log versus math.log10 stevendaprano 10 4,506 May-23-2022, 08:59 PM
Last Post: jefsummers
  Math Package in python Uma 1 2,105 Dec-12-2021, 02:01 PM
Last Post: jefsummers
  Why getting ValueError : Math domain error in trig. function, math.asin() ? jahuja73 3 5,251 Feb-24-2021, 05:09 PM
Last Post: bowlofred
  "SyntaxError: invalid syntax" running code in Doing Math With Python b saucerdesigner 2 3,505 Nov-03-2020, 04:23 PM
Last Post: saucerdesigner
  Programming Difficult math in Python Huntern 6 6,727 Oct-17-2019, 06:32 AM
Last Post: Huntern
  python 3 math formulas where to use () Python101 1 2,891 Jun-09-2019, 09:54 PM
Last Post: micseydel
  Python modeling a math solution Masterwoot 1 2,925 Mar-01-2019, 08:50 AM
Last Post: buran
  Python math error nadirdogan 3 4,242 Feb-11-2018, 10:56 AM
Last Post: nadirdogan

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020