ruby diamonds? Okay!
def riamond(karat) unless karat.odd? && karat > 0 raise ArgumentError.new("You want a #{karat} karat diamond? That's crazy!") end cut = 1 layers = [] until cut > karat layers.push(("*" * cut).center(karat)) cut += 2 end cut = karat until cut <= 1 cut -= 2 layers.push(("*" * cut).center(karat)) end puts layers.join("\n") end alias diamond riamond # since we're gonna use "actual words" i guess > diamond(9) * *** ***** ******* ********* ******* ***** *** * > riamond(3) * *** * > riamond(5) * *** ***** *** * > riamond(-5) # => ArgumentError (You want a -5 karat diamond? That's crazy!) > riamond(8) # => ArgumentError (You want a 8 karat diamond? That's crazy!)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
ruby diamonds? Okay!