Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 months ago.
This post was edited and submitted for review 3 months ago and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
Favorite data of multiple users (no more than 10000) are as follows:
user1: url_ 1, url_ 5, url_ 13, url_ 104, ....
user2: url_ 3, url_ 20, url_ 104, url_ 638, ....
user3: url_ 11, url_ 13, url_ 57, url_ 104, ....
....
userN: url_ 3, url_ 310, url_ 517, url_ 638, ....
The number of favorite url for each user is generally tens to hundreds, and at most not more than 1000, but the possibility of url is unlimited.
All user are filtered by conditions in advance. So the repeatability of each user's favorite url is estimated to be between 3% and 20%.
What algorithm is most suitable for calculating the similarity between users? Thanks.
You are looking for the similarity between two unordered subsets (no duplicates) from the same universe. The most common distance measure for this use case is the Jaccard similarity coefficient.
Related
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 6 months ago.
Improve this question
I have the following array:
[1,1,3,3,3,3,1023,1023,1,3,3,3, ...]
Is there a way to sort the array in a way where the items can appear more mixed up?
Like:
[1, 3, 1023, 3, 1, 3, 1023, ...]
You could shuffle
a=[1,1,3,3,3,3,1023,1023,1,3,3,3]
p a.shuffle
Output
[1023, 1, 1, 1, 3, 3, 1023, 3, 3, 3, 3, 3]
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
How can I remove elements from a given array of integers that are evenly divisible by 3? A new array should be returned and the original array should not be altered.
For example, if
array = [1,2,3,4,1,5,2,6,7,8,9,10,7,11,12,13,14,15]
the array
[1, 2, 4, 1, 5, 2, 7, 8, 10, 7, 11, 13, 14]
should be returned.
Just found it:
array.reject{|a| a % 3 == 0}
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 5 years ago.
Improve this question
I got a list [1, 1, 20, 20, 20, 4, 4, 7, 5, 5, 7].
In Ruby, How do I check if the list is "frequently united"?
An example: [2, 2, 150, 150, 150, 70, 70, 70] is frequently united.
Edit
Another example: [2, 2, 150, 150, 150, 70, 70, 70, 150] is not frequently united because the 150 are not together.
Something like checking if the next element is equal to the current one?, like:
p [1, 1, 20, 20, 20, 4, 4, 7, 5, 5, 7].chunk_while(&:==).all? { |e| e.size > 1 }
p [2, 2, 150, 150, 150, 70, 70, 70].chunk_while(&:==).all? { |e| e.size > 1 }
# => false
# => true
Edit:
def some_method(array)
hash = Hash.new(0)
array.each { |e| hash[e] += 1 }
if hash.values.any?(&1.method(:==))
true
else
array.chunk_while(&:==).all? { |e| e.size > 1 }
end
end
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I came to know that graph colouring algorithms are NP-Complete problems. Still, I want to know whether any implementation is possible using heuristic approach or not, especially the distinguishing graph colouring? If possible then is there any suitable resource to learn about that ?
As discussed in a somewhat related post:
Constraint solvers like MiniZinc are able to solve a broad range of graph colouring problems.
This MiniZinc example demonstrates colouring of the Petersen graph:
% Petersen Graph
set of int: Colors = 1..3;
set of int: Nodes = 1..10;
set of int: Edges = 1..15;
array[Edges] of Nodes: aFrom = [ 1, 2, 3, 4, 1, 1, 2, 3, 4, 5, 6, 7, 7, 8, 6 ];
array[Edges] of Nodes: aTo = [ 2, 3, 4, 5, 5, 6, 7, 8, 9, 10, 8, 10, 9, 10, 9 ];
array[int] of string: colorName = [ "red", "green", "blue", "purple", "yellow", "brown", "black" ];
array[Nodes] of var Colors: nodeColor;
constraint
forall(e in Edges) (
nodeColor[aFrom[e]] != nodeColor[aTo[e]]
);
solve satisfy;
output [ show(colorName[nodeColor[n]]) ++ "\n" | n in Nodes ];
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 6 years ago.
Improve this question
I had 10 items in total. I lost all of them in 3 days: 5 items on the 1st day, 3 items on the 2nd day, and 2 items on the last day. I need to get an array [5, 2, 0] of remaining items at the end of each day. How can I get the array, given total 10 and the array of lost items [5, 3, 2]?
[5, 3, 2].each_with_object([10]){|e, a| a.push(a.last - e)}.drop(1)
# => [5, 2, 0]
Know why you need the complication drop(1)? It is because, without it, the answer makes more logical sense. Your requirement is what was complicated.
[5, 3, 2].each_with_object([10]){|e, a| a.push(a.last - e)}
# => [10, 5, 2, 0]
The initial 10 represents the initial state.