brewersfan1976

apple_boxes.rb

Feb 25th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.39 KB | None | 0 0
  1. def appleBoxes(k)
  2.     yellow_apples = 1
  3.     red_apples = 0
  4.     x = 2
  5.    
  6.     while (x <= k)
  7.         if x % 2 != 0 then
  8.             yellow_apples = yellow_apples + (x * x)
  9.         end
  10.            
  11.         if x % 2 == 0 then
  12.             red_apples = red_apples + (x * x)
  13.         end
  14.            
  15.         x = x + 1
  16.     end
  17.            
  18.          return red_apples - yellow_apples
  19. end
Advertisement
Add Comment
Please, Sign In to add comment