brewersfan1976

numbers_grouping.rb

Oct 3rd, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.54 KB | None | 0 0
  1. def numbersGrouping(a)
  2.     numbers = a.length
  3.     groups = Array.new(100000)
  4.     x = 0
  5.    
  6.     while (x < 100000)
  7.           groups[x] = 0
  8.           x = x + 1
  9.     end
  10.    
  11.     x = 0
  12.    
  13.     while (x < a.length)
  14.           y = a[x] / 10000
  15.        
  16.           if a[x] % 10000 == 0 then
  17.              y = y - 1
  18.           end
  19.              
  20.           if y < 1 then
  21.              y = 0
  22.           end
  23.              
  24.           groups[y] = 1  
  25.           x = x + 1
  26.     end
  27.                    
  28.     return groups.count(1) + numbers
  29. end
Add Comment
Please, Sign In to add comment