Ruby: Finding duplicate array elements in two dimentional array [closed] - ruby

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 8 years ago.
Improve this question
I have this array:
a= [[1,2],[3,4],[1,2],[2,3],[2,3]]
How can I make user to enter an array element ex:[1,2] and it should take that element and return the number of times it is found in the array.

You have your array a and the user input (i1 and i2), all you have to do is:
a.count([i1, i2])

Related

A pseudocode for any positive integer (decimal ) and will display it as binary output [closed]

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 8 days ago.
Improve this question
Want a appropriate pseudocode
Write a pseudocode for any positive integer(decimal ) and display it as binary output .

Ruby count of the most frequent number in big integer [closed]

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 1 year ago.
Improve this question
I have big number for example 123456782345673455676767878
And i need to find the amount of the most frequent number in this big integer
num = num.digits # turn num into an array of digits [1, 2, ...]
num.tally.max_by { |digit, count| count }[0]
Note: solution only works on ruby 2.7+ (when tally method was added)

Insert element at index and Delete element by value in a Array [closed]

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 3 years ago.
Improve this question
What is the fastest way to insert an element at the index and Delete an element by value in a large Array? I can loop over the contents of the array (find the location and then shift all the elements) but it will give complexity of o(n).
Is there a built-in that can help shift the elements in an array/slice? or if there is another data structure that can help?
[Is there a] Go[...] datatype similar to List in Python [?]
No, there is not.

Sorted values not correctly sorted [closed]

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 8 years ago.
Improve this question
I am stumped by the sorting algorithm that is employed by the sorting method for a hash object. I have an hash with the following key values which are all floats.
0
0.0113867473179591
103.77896959717717
2.039453159239391
99.99575298164214
These are the values I got when I use map_values.values.sort(). I don't understand why 103.778.... comes before 2.0394...
Are your values strings? This kind of sorting makes sense when dealing with strings. If you want to sort by the float values you should convert the strings to floats.
map_values.values.map(&:to_f).sort

What would be the language generated by Σ*-x? [closed]

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
Say, for example, Σ={x,y}.
And you carried out the operation Σ*-x. What would be the resulting language? Would it essentially be y* or would it just minus one occurrence of x in all strings generated in Σ*?
i.e xxyyxx to xyyxx.
It would be the language of all strings generated by Σ* minus the string x. (so: xx, epsilon, xyx, y, etc... but not x)

Resources