0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

0
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

他の回答例

  • これは全く同じ。

    • [https://qiita.com/sackey_24/items/8fc236bb054aff6b74c8:title]
  • 実は再帰つかわなくても解けた模様。

    • [http://yucatio.hatenablog.com/entry/2019/05/07/225412:title]
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?