Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- def count_factors(n)
- count = 0
- c = 2
- while n > 1
- if n % c == 0
- n /= c
- count += 1
- else
- c += 1
- end
- end
- count
- end
- def prime_order(arr)
- arr.sort_by! do |a,b|
- fa = count_factors(a)
- fb = count_factors(b)
- fa == fb ? a <=> b : fa <=> fb
- end
- end
- arr = [11,8,27,4]
- p prime_order(arr)
Advertisement
Add Comment
Please, Sign In to add comment