python – Super Greedy Algorithm for Exact Three Cover

I had trouble solving instances of Exact Three Cover with 100 units in input C. All in a reasonable amount of time. Mainly because the problem is NP-complete. So I came up with an approximate solution (Don’t ask me the ratio for correctness, because I don’t know) I have gotten 100, 500 and 1000 units in C to return correct solutions. Screenshot of 3000 units in C. And, here is a link to my approximation algorithm where C has 100 units.

I believe that if I don’t have significant amounts of chaff (sets that could cause my algorithm to fail) I can solve instances of Exact Three Cover I usually come upon quite quickly.

Now, I don’t have to wait for millennia to solve C with 500 units when I encounter these cases.

Please don’t ask me to change my constants; because I’m testing for 10,000 units in C. So I need a large constant for my while-loop.

import random
from itertools import combinations
from itertools import permutations
import sympy
import json

s =  input("Input set of integers for S : ").split(',')
c =  input('enter list for C (eg. ((1,2,3),(4,5,6))): ')
c = json.loads(c)

for a in range(0, len(s)):
    s(a) = int(s(a))

# Need a prime
# seems to help spread
# 3sets apart.

count = len(s)//3
while True:
    count = count + 1
    if sympy.isprime(count) == True:
        prime = count

# This is a SUPER Greedy
# Algorithim that runs
# in polynomial time.
# It is impractical
# for NO instances
# It will TAKE FOREVER (constant of 241.. Duhh...)
# to halt and
# return an approximated
# no.

# The purpose of why I got
# such a large constant
# is because I needed
# to find Exact Three
# Covers in lists of C with
# lengths of 100, 500, 1000
# units long.

# The Exact 2^n solution
# is unreasonably to long
# for me.

# This is a formula
# to count all
# possible combinations
# of THREE except
# I am using a constant
# value of 241.

while_loop_steps = len(s)*241*((len(s)*241)-1)*((len(s)*241)-2)//6

# Don't worry about this.
#p = (len(s)//3)/while_loop_steps * 100

if len(s) % 3 != 0:
    print('invalid input')

# Sort list to remove
# sets like (1,2,3) and (1,3,2)
# but leave (1,2,3)

delete = ()
for a in range(0, len(c)):
    for i in permutations(c(a), 3):
        if list(i) in c(a:):
            if list(i) != c(a):

for a in range(0, len(delete)):
    if delete(a) in c:
        del c(c.index(delete(a)))

# remove sets
# that have
# repeating
# elements

remove = ()
for rem in range(0, len(c)):
    if len(c(rem)) != len(set(c(rem))):

for rem_two in range(0, len(remove)):
    if remove(rem_two) in c:
        del c(c.index(remove(rem_two)))

# remove sets
# that have
# elements
# that don't
# exist in S.

for j in range(0, len(c)):
   for jj in range(0, len(c(j))):
        if any(elem not in s for elem in c(j)):

for rem_two in range(0, len(remove)):
    if remove(rem_two) in c:
        del c(c.index(remove(rem_two)))

# Remove repeating sets

solutions =(c(x) for x in range(len(c)) if not(c(x) in c(:x)))

# check left and right for solutions

def check_for_exact_cover(jj):
    jj_flat = (item for sub in jj for item in sub)
    jj_set = set(jj_flat)
    if set(s) == jj_set and len(jj_set) == len(jj_flat):
        print('yes', jj)

# Well if length(c) is small
# use brute force with polynomial constant

if len(c) <= len(s)//3*2:
    for jj in combinations(c, len(s)//3):
if len(c) >= len(s)//3*2:
  for jj in combinations(c(0:len(s)//3*2), len(s)//3):
if len(c) >= len(s)//3*2:
    X = list(reversed(c))
    for jj in combinations(X(0:len(s)//3*2), len(s)//3):

# Well, I have to quit
# if the loop above
# didn't find anything.
# when len(c) <= len(s)//3*2

if len(c) <= len(s)//3*2:

# will need these Three (what a prime!)
# just in case my algorithim
# needs to reverse in loop.

length = len(solutions)
ss = s
c = solutions

# Primes
# have been
# observed
# in nature
# to help
# avoid conflict.
# So why not
# pre shuffle C
# prime times?

for a in range(0, prime):

# while loop to see
# if we can find
# an Exact Three Cover
# in poly-time.

stop = 0
Potential_solution = ()
opps = 0
failed_sets = 0

#Don't worry about this. (100/p*while_loop_steps)

while stop <= while_loop_steps:

    # Shuffling c randomly
    # this seems to help
    # select a correct set
    opps = opps + 1
    stop = stop + 1

    if len(Potential_solution) == len(ss) // 3:
        # break if Exact
        # three cover is
        # found.
        print('YES SOLUTION FOUND!',Potential_solution)
        print('took',stop,'steps in while loop')
        failed_sets = failed_sets + 1

    # opps helps
    # me see
    # if I miss a correct
    # set
    if opps > len(c):
        if failed_sets < 1:
            s = set()
            opps = 0

    # Keep c(0)
    # and append to
    # end of list
    # del c(0)
    # to push >>
    # in list.
    del (c(0))
    Potential_solution = ()
    s = set()
    for l in c:
        if not any(v in s for v in l):

    if len(Potential_solution) != len(ss)//3:
        if stop == length:
          # Reverse list just
          # to see if I missed a solution
         for cc in range(0, len(c)):
              c = list(reversed(c))


  • What parts of my sorting algorithms could be shortened and improved?
  • Is the usage of primes to theoretically space out sets pointless?
  • What variable names would you use in my code?

differential equations – Find Solution to Exact ODE with 4 Variables?

OK, I give up. I was trying to use the solution in this post to solve an exact ODE with 4 independent variables. This works

DSolve(D(a(x, y, z), {{x, y, z}}) == D(x*y*z, {{x, y, z}}), a(x, y, z), {x, y, z})

but this doesn’t

DSolve(D(a(w, x, y, z), {{w, x, y, z}}) == D(w*x*y*z, {{w, x, y, z}}), a(w, x, y, z), {w, x, y, z})

Is there a way (similar to the former’s?) to get Mathematica to solve the latter equation? Thank you in advance for any assistance you can provide.

agile – should I design a simplified version of a use case and implement it, or should I stick to the exact use case while designing?

I know that user stories and use cases are written by a customer not the development team alone. And I know that on each iteration the development team picks a number of requested use cases and delivers them by the end of the sprint.

The question is: Should the requirements analysis and design phase on each iteration be aimed to target the exact given use case at the first place?

Let’s say that we, as the development team, are given a use case to develop like this:

” Jimmy, as the bank owner, should be able to see the charts showing how much profits has changed on each day during the last week.”

As a developer I feel more comfortable to first design and impalement a feature which helps the user to see information in textual form:

Jimmy, as the bank owner , should be able to see some texts showing how much profit has changed on each day during the last week

after I reach at the point where everything works, start to redesign and change the code so that charts are shown instead of textual info.

If it’s okay to first start by focusing on a simplified version of the actual requirement and then move toward the actual requirement gradually, what are those simplified intermediate outcomes called? should they be listed as backlogs?

Thanks in advance.

ag.algebraic geometry – Profinite completion of the etale fundamental group and homotopy exact sequence

Let $X$ be a geometrically connected variety over a filed k; consider the exact sequence of etale fundamental groups

$$1 rightarrow pi_1 (X_{bar{k}},bar{x})rightarrow pi_1 (X,bar{x})rightarrow Gal(k)rightarrow 1$$
for some geometric point $bar{x}$.

I am asking if we can,under somme conditions, get an exact sequence of profinite completions

$$1 rightarrow widehat{pi_1(X_{bar{k}},bar{x})} rightarrow widehat{pi_1 (X,bar{x})}rightarrow Gal(k)rightarrow 1$$

Note that ,by a recent paper, it work for the pro-etale fundamental group $pi_1^{proét} (X,bar{x})$ defined by Bhatt and Scholze.

homological algebra – Is it ever useful to consider a long exact sequence as a chain complex?

Here are two common ways of obtaining chain complexes with vanishing homology:

  1. Chain complexes that compute the reduced homology of a contractible space
  2. Chain complexes that arise as a “long exact sequence in homology” induced by a short exact sequence of chain complexes

These two examples seem to be on different footing. It is easy to think of useful maps within a type:

  • for 1), a continuous map of contractible spaces induces a chain map
  • for 2), a map of short exact sequences induces a map on long exact sequences

but I cannot really imagine a map between these two types, mostly because the three-fold periodicity in type 2) seems utterly incompatible with the ethos of type 1). The two types seem like unrelated notions that happen to have the same mathematical definition.

So here is my precise question, trying to see if there is any crossover:

Suppose (X,A) is a pair of spaces, $A subseteq X$ so that there is a short exact sequence of singular chains $0 to C_bullet A to C_bullet X to C_bullet(X,A) to 0$. Is it possible to functorially construct a filtered contractible space $Lambda = Lambda(X,A)$ with $Lambda_0 subseteq Lambda_1 subseteq ldots$ so that

  • $H_bullet(Lambda_{3k},Lambda_{3k-1}) cong H_k A$,
  • $H_bullet(Lambda_{3k+1},Lambda_{3k}) cong H_k X$, and
  • $H_bullet(Lambda_{3k+2},Lambda_{3k-1}) cong H_k(X, A)$,
    so that the spectral sequence of the filtered space $Lambda$ recovers the long exact sequence of (X,A) as the $E^1$-page?

Motivation: I am writing a Macaulay2 package that makes it easy for the user to generate long exact sequences. I originally considered returning such a sequence as a “ChainComplex” object, since this data type already exists in M2 and can be used by other functions. Then I decided that this is not so convenient, actually, because it obscures the threefold periodicity. But now I wonder if it could ever be useful to consider a long exact sequence as a chain complex.

What kind of keywords should we use while doing blog, exact keywords or long tail keywords?

What kind of keywords should we use while doing blog, exact keywords or long tail keywords?

Will two equal floating point compare equal after the exact same set or operations?

Yes, a==b will return true*. People are sometimes surprised by the results of floating point operations and think that there is some element of randomness involved. There’s not, unless you call a random number generator. Finite precision floating point arithmetic is completely deterministic, it’s just that it doesn’t match our expectations for arithmetic with infinite precision integers or reals.

*unless a and b have become NAN (not a number). A value of NAN is not equal to any other value including another NAN. This is one of those elements of floating point math that is completely deterministic, but violates casual expectations.

dnd 5e – Are there any official rules for the exact meaning of the phrase “when the target willingly moves” in Booming Blade?

The Booming Blade cantrip’s secondary effect states that “(the target) becomes sheathed in booming energy until the start of your next turn. If the target willingly moves before then, it immediately takes 1d8 thunder damage, and the spell ends”. We can deduce, then:

  • That the damage does not trigger when the target is dragged or pushed around via physical means (grappling, shoving, scenario effects, etc.)
  • That the damage does not trigger when the target is dragged or pushed around via magical means (Gust, Eldritch Blast with Grasp of Hadar, Graviturgist’s Gravity Well, etc.)

This seems pretty clear. However, what happens when the following cases arise?

  • The target is ordered to move via the use of Command (assuming they don’t know yet that the thunderous aura is damaging).
  • The target is forced to move via the use of Compulsion.
  • The target is invited to move via the use of Suggestion.
  • The target is Turned.
  • The target is Frightened and forced to run via Dissonant Whispers.
  • The target has a Geas that prohibits them from ending a turn next to an enemy if they can avoid it.
  • The target is threatened into leaving the area or else. This one seems “willingly”, but are they truly willing if they are panicking because you are telling them you will cut their heads off if they don’t run?

This tweet seems to suggest that forcing people to move via mind control spells doesn’t count as willing. However, after the release of the 2019 Sage Advice Compendium, Jeremy Crawford’s Twitter rulings are no longer considered official, so I was looking for something more solid to make a RAW judgement of this interaction.

ds.dynamical systems – Exact solution to a periodic linear ODE sought

We have been studying a Hamiltonian system that possesses a one-parameter family of periodic orbits, depending on the energy level $h$. We “know” via various non-rigorous means that these periodic orbits are stable for $h<frac{1}{8}$ and unstable for $h>frac{1}{8}$ but haven’t been able to prove it.

We know that if the linearization possesses a periodic orbit at the critical value $h=frac{1}{8}$, then this value of $h$ lies on the boundary between stability and instability. We have numerically calculated this periodic orbit using ultra-high-precision arithmetic and a 30th order ODE solver. We have also used Hill’s method of harmonic balance to high order in computer algebra to show that $h_{rm critical}$ agrees with $1/8$ to double precision, using no ODE solves.

If we could simply show that the following ODE has a $2pi$-periodic orbit, we would have a proof. Does anybody know how find such a solution?

$$frac{d}{dtheta} vec{x} = A(theta) vec{x},$$

$$ A(theta) =
frac{1}{4sqrt{17+8 cos{2 theta} }}
– sin{2 theta} &
frac{7+12 cos{2 theta} -4 cos{4 theta}-3sqrt{17+8 cos{2 theta} } }{2-2cos{2 theta}} \
frac{3-4 cos{2 theta} -4cos{4 theta}-sqrt{17+8 cos2 theta }} {2+2cos 2theta}&
sin{2 theta} \

This would answer the one big question we left unanswered in this paper also available on my website.

On the Facebook, is there a way to not display the exact time of posting?

Short question is: if I post on the Facebook, can I omit the part about posting at 2:30am, but just “Posted June 3, 2020”?


Sometimes I am too tired after work, so I may sleep around 6pm and then wake up around 2am.

Then I may play a little Animal Crossing on the Nintendo Switch. Sometimes I did something great, such as able to fish a whale shark. Now that’s no crime, but if I post to Facebook as a public post, I don’t want my coworkers and managers, being able to see it some day, think or have the judgment that “wow this guy is playing Animal Crossing at 2:30am… hm…”

I think the same with the situation: if we went through some tough time to fix something on the website, deployed it, and now I have a coffee break at 3:30pm for 15 minutes and I played some Animal Crossing, and there is a post I wanted to post on my profile and also share with a Facebook Animal Crossing group, is there a way to post it as “June 5, 2020, 3:35pm” which might give a wrong impression about “what is he doing during a workday?”

So I hope to have the post, at least after a few days, just to say, “Posted June 3, 2020” instead of “Posted June 3, 2020, at 2:30am”. Is that possible?