LoginSignup
2
0

More than 1 year has passed since last update.

【Ruby】4乗ガウス問題

Posted at

4乗的ガウス問題をRubyにて解いてみました。

【問題】
1から50までの整数の4乗の和を求めなさい。

【回答】

Ruby
i = 0
while i <= 49
  i += 1
  num = num.to_i + (i ** 4)
  puts num
end

答え 65666665

もっとシンプルに計算できるような気もします…。
今の私に思いつく式は上記しかなかったので、他に分かりやすいコードがあれば教えていただければ幸いです。

2
0
6

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
2
0