I have a data structude ST that contains an array of entities of ST.
struct ST {
ST[];
}
I need to sort it by deep-value.
For example i have an array of ST: [A { B, C, D }, B { C, D }, C, D { E }, E, F]
And i want to get result like this: [E, D, C, B, E, F, A]
Can somebody help me?
The solution depends on what language you are using however the basic idea remains the same. The idea is that each struct can have a value assigned which can then be used for sorting.
A similar question was asked here: Sort ArrayList of custom Objects by property
I hope this helps, but generally you should try asking questions in greater detail
Related
I have a map with this structure:
Map<String, List<String>> values = {
A: [B],
B: [D],
C: [A],
D: [],
E: [C,D]
}
in this map every value has an list of other values who can't be next to them.
I need a function who gets a list of values and finds a possible order for them.
Something like:
input: function([A,C,D,E])
output: [E,A,D,C]
Does someone have a way to solve this?
I want to use it in Dart but i would try to translate it if someone has a solution in an other language or pseudo code.
Thanks.
I need a matching algorithm between a collection(Xi) and a collection(collection(Yj))
knowing that Collection()Yj may have elements in common
I explain with an example:
suppose we have a web service S with 3 inputs (I1,I2,I3)
I1 can be provided by services A, B, C, D
I2 can be provided by service A,E
I3 can be provided by services F
I need an algorithm or a function to find the best combinaison between the available services(A to F) to provide the input of S (I1,I2,I3)
Collection(Xi)={I1,I2,I3}
Collection(Collection(Yj))= {{A,B,C,D},{A,E},{F}}
Thank you.
This is exactly the explanation of Maximum Bipartite Matching problem.
One part is {i1, i2, i3 .....}, the other part is {A, B, C, D, ....}
Read more about it here.
http://www.geeksforgeeks.org/maximum-bipartite-matching/
I am working with Odoo 8 and I want to set a couple of domains. I thought I understood reverse Polish notation but domains are not working so I guess I am wrong.
The domains I want to achieve using reverse Polish notation are:
A and B and C and (D or (E and F)): I tried to implement it with the expression A B C or D E F, but it did not work.
A and B and (C or D or (E and F)): I tried to implement it with the expression A B or or C D E F, but it did work neither.
Note: I am not writing ANDs in domains (if you do not specify anything
in Odoo, it is supposed to use &).
My domains are wrong because I always get no record.
Can anyone help me, please?
I have the answer. Despite if you do not specify anything, Odoo takes an AND by default, you must write ANDs when there are expressions which must be executed before other and Odoo does not know which are because you have a complex and long expression.
In my cases, E and F must be executed before any other expression, so we cannot leave them without AND, so:
A and B and C and (D or (E and F)): The solution is A B C or D and E F.
A and B and (C or D or (E and F)): The solution is A B or or C D and E F.
In an XML domain in Odoo, these domains will be:
[A, B, C, '|', D, '&', E, F].
[A, B, '|', '|', C, D, '&', E, F].
Where each letter will be an expression like ('field', 'operator', 'value').
Note: ampersands must be escaped.
EDIT
I have answered a question here:
I donĀ“t understand Normal Polish Notation (NPN or PN). How to build a complex domain in Odoo?
In which I explain with details a great method to resolve complex domains. I hope it helps to someone.
If I have something like:
value is between 1-1000
And if value is within 1-100, output A
within 101-200, output B
within 201-300, output C
within 301-400, output D
within 401-500, output E
else, output F
Can this be done more "efficiently" or better than having if statements for each one?
You could use a mapping between value and output:
outputs = [ A, B, C, D, E, F, F, F, F, F]
output = outputs[(int)((value - 1)/ 100)]
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Like this
oldArray = [[a, b, c, d],[e, f, g, h]]
I need one line of code that will return a new array of, say, element 2 in each element of oldArray
newArray = coolLine(oldArray, 2)
newArray -> [c, g]
This does element number 2:
oldArray.map { |a| a[2] }
Smells a little like homework, but you're looking for the map function.
http://www.ruby-doc.org/core-2.0/Array.html
Have fun!
2nd element in each element of oldArray
oldArray = [[a, b, c, d],[e, f, g, h]]
newArray = coolLine(oldArray, 2)
newArray -> [c, g]
The thing you want can be achieved in many ways. Most common would be the map and zip.
The map function allows you to process the sequence and re-calculate any of its items to a new value:
arr = [ [ 1,2,3 ], %w{ a b c }, [ 10,20,30] ]
# proc will be called twice
# 'item' will first be [ 1,2,3 ] then %w{ a b c } and so on
result = arr.map{|item|
item[1]
}
result -> 2, then 'b', then 20
So, creating your "coolLine" seems pretty straightforward.
However, depending on other things, the zip may turn out to be even better. Zip takes N sequences and enumerates them sequentially returning Nth element from all at once. Why, that's almost exactly what you asked for:
arr = [ [ 1,2,3 ], %w{ a b c }, [ 10,20,30] ]
zipped = arr[0].zip(*arr[1..-1)
zipped -> [ [1,'a',10], [2,'b',20], [3,'c',30] ]
Or, of you don't like the [0]/*[1..-1] trick, you can easily write your own 'cleaner zip' like in here https://stackoverflow.com/a/1601250/717732