What is impossible? - puzzle

Hi recently i appeared in an aptitude,there was a problem that i realy cant understand please provide some idea, how to solve it.(and sorry to for poor English.)
(Question)-> Three candidates, Amar, Birendra and Chanchal stand for the local election. Opinion polls are
conducted and show that fraction a of the voters prefer Amar to Birendra, fraction b prefer Birendra to
Chanchal and fraction c prefer Chanchal to Amar. Which of the following is impossible?
(a) (a, b, c) = (0.51, 0.51, 0.51);
(b) (a, b, c) = (0.61, 0.71, 0.67);
(c) (a, b, c) = (0.68, 0.68, 0.68);
(d) (a, b, c) = (0.49, 0.49, 0.49);
(e) None of the above.

If you tried to list of possible preferences people can have
are either
ABC (means you prefer A to B, prefer B to C and therefore also prefer A to C)
ACB
BAC
BCA
CAB
CBA
in this case you'll find that each fraction of the population represents:
a=ABC+ACB+CAB
b=ABC+BAC+BCA
c=BCA+CAB+CBA
therefore a+b+c = 2(ABC+BCA+CAB)+ACB+BAC+CBA
as you notice not all groups within the population are repeated. we can therefore assume than (a+b+c) can never be more than twice the population since each member of the population is represented twice at the most.
out of the options C is the one where the sum is more than 2. and is therefore the impossible value.

Related

Pandas dataframe: replace value with that of another column based on original value

I have a pandas dataframe where I want to replace the value in the Prediction column with the value in the column referred to by the prediction column.
A
B
C
D
Prediction
stipulation
interrelation
jurisdiction
interpretation
D
typically
conceivably
tentatively
desperately
C
familiar
imaginative
apparent
logical
A
plan
explain
study
discard
B
I have tried a few methods using df.apply() and map() but they haven't worked. The resulting dataframe would look like this:
A
B
C
D
Prediction
stipulation
interrelation
jurisdiction
interpretation
interpretation
typically
conceivably
tentatively
desperately
tentatively
familiar
imaginative
apparent
logical
familiar
plan
explain
study
discard
explain
# create a dictionary for each row and return the key value of Prediction
df['val']=df.apply(lambda x: x.to_dict( )[x['Prediction']], axis=1)
df
A B C D Prediction val
0 stipulation interrelation jurisdiction interpretation D interpretation
1 typically conceivably tentatively desperately C tentatively
2 familiar imaginative apparent logical A familiar
3 plan explain study discard B explain
We used to have lookup ... but it had been removed. One work around
df['new'] = df.values[df.index,df.columns.get_indexer(df.Prediction)]
df
Out[318]:
A B ... Prediction new
0 stipulation interrelation ... D interpretation
1 typically conceivably ... C tentatively
2 familiar imaginative ... A familiar
3 plan explain ... B explain
[4 rows x 6 columns]

how can i get weighted finite automaton?

1.how can i get this automaton(non blocking and weighted)?
2.I want to see some simple examples.
Your original automaton is already a weighted one as stated in the problem. The new one adds to it loops for every letter in every state. Further it gives weight 0 to all the original transitions and a weight to the new ones that is not understandable from the information you give (what is \psi_{i,j}?).
You formally get this automaton by simply aplying the definitions you provide on the original automaton.
For example: original automaton over alphabet {a,b}, states {q (initial), p (final)}, transitions: (q, a, p) weight 1, (p, b, p) weight 2. In the new automaton you get (q, a, p) weight 0 and (p, b, p) with the weight that cannot be understood from your definitions. Further you get the new transitions (q, a, q), (q, b, q), and (p, a, p).

Optaplanner: Vehicle Routing – order of precedence while visiting cities

Suppose that you have a car that is required to visit cities A, B, C, D and E in the shortest possible time or distance. But there is order of precedence in which these cities can be visited. For e.g., B must be visited first before you visit “A,” and “E” must be visited first before you can visit “C.” So all of the following solutions are valid:
Car -> B, D, E, A, C
Or
Car -> D, E, B, A, C
Or
Car -> E, B, A, D, C
Following routes will be invalid:
Car -> A, B, D, E, C (Constraint violated since B must be visited first before you can visit A)
Or
Car -> B, D, A, C, E (Constraint violated since E must be visited first before you can visit C)
In Optaplanner, is there any way to enforce such constraints? I think this has to be done while forming a chain. The default chain might have to be manually revisited to enforce such a constraint. But I don’t know how. Any pointers will be greatly appreciated.
Vikas
Introduce a shadow variable that keeps the chainIndex in a chain of a vehicles.
For example: Vehicle A starts in Brussels then goes to Paris then to London. Vehicle B starts in Brussels then goes to Berlin and then to Prague. Then it works like this:
Paris's anchor is A and its chainIndex is 1.
London's anchor is A and its chainIndex is 2.
Berlin's anchor is B and its chainIndex is 1.
Prague's anchor is B and its chainIndex is 2.
Adding your constraint by using that chainIndex and the anchor is then trivial.

How to determine if a context-free grammar describes a regular language?

Given an arbitrary context-free grammar, how can I check whether it describes a regular language?
I'm not looking for exam "tricks". I'm looking for a foolproof mechanical test that I can code.
If it helps, here's an example of a CFG that I might receive as an input.
Specifically, notice that the answer must be much more complicated than just looking for left- or right-recursion, since the presence of another type of recursion does not automatically imply the grammar is irregular.
S: A B C D X
A: A a
A:
B: b B
B:
C: c C c
C: c
D: D d D
D: d
X: x Y
X:
Y: y X
Y:
There is no such mechanical procedure because the problem of determining whether a CFG defines a regular language is undecidable.
This result is a simple application of Greibach's Thereom.

Arrange numbers in order

I've some variables, Lets say a, b, c, d. All belongs to a fixed interval [0, e]
Now i've some relations between them like
a > b
a > c
b > d
Something like this; I want to make a function which print all the possible cases for this.
Example:
a b c d
a c b d
a b d c
a c b d
In essence, what you have is a directed acyclic graph.
A relatively simple approach is to store, for each variable, a set of the variables that must precede them. (In your example, this storage would map b to {a}, c to {a}, and d to {b}.) You can then write a recursive function that generates all valid tails consisting of a subset of these variables (in your case, for example, the subset {c,d} produces two valid tails: [c,d] and [d,c]). This recursive function examines each variable in the subset and determines whether its prerequisites are already met. (For example, since b maps to {a}, any subset including both a and b cannot produce a tail that begins with b.) If so, then it can recursively call itself on the subset excluding that variable.
There are some optimizations you can then perform, if desired. For example, you can use dynamic programming to avoid repeatedly re-computing the set of valid tails for the same subset.