Sorting array of strings (with repetitions) according to a given ordering

We get two arrays:

ordering = ["one", "two", "three"] 

and

input = ["zero", "one", "two", "two", "three", "three", "three", "four"]; 

We want to find the array output so that

output = ["one", "two", "two", "three", "three", "three", "zero", "four"] // or output = ["one", "two", "two", "three", "three", "three", "four", "zero"] 

The strings (with possible repetitions) should be sorted as in the ordering array. Not found/contained strings should be put at the end of the new array and their order doesn’t matter.

The $ n^{2}$ solution is obvious, can we do better? The memory doesn’t matter and it doesn’t have to be an in-place algorithm.

algorithm that finds minimal vertex cover of a given vertex

i am looking for a simple algorithm that gets as an input an undirected graph and a vertex in the graph and outputs the minimal vertex cover that v belongs to.

not sure on how to do it correctly, here’s my attempt:

for a given undirected graph $ G=(V,E)$ and a vertex $ v \in G$

1)$ edges \leftarrow \emptyset $

2)remove adjacent edges to given vertex v(given in the input)

3)while there are edges in graph G:

3.1)$ edges \leftarrow {u,v}$

3.2)$ G\:\leftarrow \:G\:\:\ \:\:\left\{u,v\right\}$ (doesn’t let me mark it correctly, but i meant remove {u,v} from G. doesn’t give me to write \ correctly

3.3)return |x|+1 (including v we got from the input)

how to make it better? would appreciate seeing better algorithms for this and explanations/insights so i can learn

thank you for your efforts

Is there necessarily an infinite number of inputs to any given output in a crypto hash function? [migrated]

This might be a very easy question. Let’s consider cryptograhic hash functions with the usual properties, weak and strong collision resistance and preimage resistance.

For any given output, obviously there are multiple inputs. But is that necessarily an infinite number of preimages, for any given hash value?

How would I go about giving a formal proof that there exists no crypto hash function h() such that there is a given value v = h(m*) for which the possible set of inputs m* is finite? Would this necessarily break collision resistance?

Does there exist an algorithm to generate the production rules of CFG, given a sample production?

Lets say, we provide the algorithm a set of tokens.

e.g.

x + y - z x - x - x 

It will then try to generate a CFG which fits all the provided examples

S -> S O T | T T -> x | y | z O -> + | - 

It feels like a data compression problem but I could be wrong.

Does anybody know any existing literature or a starting point to solve this problem?

Does this problem have a name? What should I Google?

Given the Equivalence relation R = { x, y $\in$ $\Bbb{Z}$ : (x+y) mod 2 = 0}, what are equivalence classes 1 and 2?

Given the Equivalence relation R = { x, y $ \in$ $ \Bbb{Z}$ : (x+y) mod 2 = 0}, what are equivalence classes of 1 and 2?

I can’t really see the equivalence classes of infinite sets. Only by having a drawing of all elements can I distinguish the answers, wich is not the case in the above mentioned example.

What would be the best way to tackle such problems?

Thanks!

Approach for algorithm to find closest 3-D object in a list of many similar objects to a given test case

Lets say I have a list of many (10s of thousands – millions) objects, and each of these objects has a given number of 3-D vertices (my current implementation uses 8 vertices each, but this number can be reduced if it causes a very significant increase in performance). These vertices are currently stored as floats from 0-255, but this range can also be changed if need be, assuming it will not reduce accuracy too drastically. Also, I can store these objects in any data structure that would be beneficial for this algorithm.

I am given another such object, also with the same number (8) 3-D vertices, but of which in general it must be assumed that none of the vertices are common with any vertices included in the list of stored previous objects.

With all of this in mind, I need an algorithm that will return an object from that list that is optimally close to the test case object (close being defined in the normal, euclidean distance, sense). By optimally close, I mean that it does not have to be the global optimum if this will greatly increase performance, although if there is a quick algorithm that will always return the global optimum i would love to hear it.

Select all entries where range of two DATETIME fields includes given date

I’m looking for a way to get all entries from my reservations table to be shown in a calendar.

Now I know that I will have to iterate over all days of the current week and run a database query to select all reservations with dt_from >= start_of_the_week / start_of_the_day and dt_to <= end_of_the_week / end_of_the_day.

But that only gives me the reservations that start or end within the week / respectively within the given day.

What I am trying to figure out is: How do I get the reservations which started earlier and/or end after the current day or week?

I have some kind of the following table design

+----+-------------------+---------------------+---------------------+ | ID | NAME | DT_FROM | DT_TO | +----+-------------------+---------------------+---------------------+ | 1 | Jeff Atwood | 2020-01-06 09:00:00 | 2020-01-16 09:00:00 | | 2 | Terry Jones | 2020-01-30 09:00:00 | 2020-02-16 09:00:00 | | 3 | Brian of Nazareth | 2020-02-06 09:00:00 | 2020-03-16 09:00:00 | +----+-------------------+---------------------+---------------------+

I have been stuck with this for a while now and would appreciate a push into the right direction.

Thank you πŸ™‚

What challenge rating should the Ebondeath stat block have been given?

In the adventure Divine Contention, there’s a creature called Ebondeath, and the adventure provides a stat block for this creature, available on D&DBeyond.

This creature’s stat block appears to be a modified version of the Ghost’s stat block. The Ghost is a CR 4 creature. Ebondeath has also been given a CR of 4, but it has:

This looks like a mistake to me, and given that some traits have been updated where others have not been, it also looks like a lazy effort without paying much attention to the details.

Ebondeath is clearly stronger than a Ghost, and therefore surely must be of a higher CR that 4. What CR should1 this stat block have been given? As a bonus question, what else should be updated to make things more consistent with the CR it should have been given (meaning the Withering Touch attack, and should the save DC of Horrifying Visage be 20 as well)?

1. Note that by “should”, I mean if it were to be derived from its stat block, not just an opinion (the word “should” often has that association, so I just wanted to make that clear).