LoginSignup
0
0

More than 3 years have passed since last update.

Ruby手習い(再帰または算数)

Posted at

[https://blog.jnito.com/entry/2019/05/03/121235:title]

上記記事のボーナスドリンク問題。

自分で書いたコード

class BonusDrink
    def self.calc(count)
        count + self.bonus_of(count)
    end

    private

    def self.bonus_of(count)
        return 0 if count < 3
        count / 3 + self.bonus_of(count / 3 + count % 3)
    end
end

他の回答例

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0