brewersfan1976

house_of_cats.rb

Oct 9th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.66 KB | None | 0 0
  1. def houseOfCats(legs)
  2.     output_array = Array.new
  3.     x = legs
  4.     y = 0
  5.    
  6.     if legs % 4 == 0 then
  7.        output_array[y] = 0
  8.        y = y + 1
  9.     end
  10.    
  11.     while (x >= 0)
  12.           if x - 4 > 0 then
  13.              x = x - 4
  14.           else
  15.              break
  16.           end
  17.     end
  18.      
  19.     output_array[y] = x / 2
  20.     y = y + 1
  21.    
  22.     x = 1
  23.        
  24.     while (x * 2 <= legs)
  25.           amount = legs - (2 * x)  
  26.        
  27.           if legs - (2 * x) == 0 or amount % 4 == 0 then
  28.              output_array[y] = x
  29.              y = y + 1
  30.           end
  31.              
  32.           x = x + 1
  33.     end
  34.        
  35.    return output_array.uniq
  36. end
Advertisement
Add Comment
Please, Sign In to add comment