Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
4 votes
2 answers
232 views

Ruby Array#own_shuffle method

I have tried to implement the Array-shuffle method myself. Haven't had a look on some similar algorithm-examples by purpose and tried to figure out something myself. The actual Array-extension: ...
michael.zech's user avatar
  • 4,972
7 votes
2 answers
2k views

Counting the elements of one array that are less than or equal to some other numbers

I have a method which compares two array О(n2), maxes with each element in nums against <...
Said Kaldybaev's user avatar
5 votes
1 answer
459 views

Next, greater permutation of digits of a number

Was looking at this question (which I initially misunderstood completely), to which Peter Taylor posted a good answer outlining a much better algorithm. For kicks, I implemented it in Ruby, but I ...
Flambino's user avatar
  • 33.2k
1 vote
2 answers
140 views

Combine arrays and preserve ordering - but prioritize one array's ordering over another

I have two arrays and I want to combine them both in a manner similar to this: ...
max pleaner's user avatar
6 votes
2 answers
5k views

Algorithm to rotate array elements in Ruby

I wrote this algorithm to rotate elements in an array. It's not very efficient, but it works. It has another disadvantage that it doesn't rotate right (it would be nice to pass it negative steps, for ...
Mohamad's user avatar
  • 2,044
4 votes
2 answers
785 views

Find all integers between m and n whose sum of squared divisors is itself a square

Divisors of 42 are : 1, 2, 3, 6, 7, 14, 21, 42. These divisors squared are: 1, 4, 9, 36, 49, 196, 441, 1764. The sum of the squared divisors is 2500 which is 50 * 50, a square! Given two ...
Jazz's user avatar
  • 43
9 votes
3 answers
167 views

Finding if sequential numbers for total exists

Question: Given a sequence of positive integers A and an integer T, return whether there is a continuous sequence of A that sums up to exactly T Example: ...
suzukimilanpaak's user avatar
3 votes
3 answers
199 views

Max contiguous slice in Ruby

I need to compute the max contiguous slice in an array. I wrote this function, but I am not sure if it is correct or I am missing edge cases. I ran several cases. ...
aarti's user avatar
  • 923