Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def weakNumbers(n)
- max_weakness = 0
- x = 1
- number_of_divisors = 0
- d = Array.new
- weakness = Array.new
- output = Array.new
- z = 0
- while (x <= n)
- y = 1
- # find the number of divisors for the current number
- while (y <= x)
- if x % y == 0 then
- number_of_divisors = number_of_divisors + 1
- end
- y = y + 1
- end
- d[z] = number_of_divisors
- # find the weakness level
- y = 0
- while (y < d.length)
- if d[y] > number_of_divisors then
- max_weakness = max_weakness + 1
- end
- y = y + 1
- end
- weakness[z] = max_weakness
- max_weakness = 0
- number_of_divisors = 0
- x = x + 1
- z = z + 1
- end
- # find the highest weakness and the number of times it occurs
- weakness = weakness.sort
- weakness = weakness.reverse
- output[0] = weakness[0]
- output[1] = weakness.count(weakness[0])
- return output
- end
Advertisement
Add Comment
Please, Sign In to add comment