結果

問題 No.593 4進FizzBuzz
ユーザー gemmarogemmaro
提出日時 2020-07-17 09:32:36
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,399 ms / 2,000 ms
コード長 507 bytes
コンパイル時間 66 ms
コンパイル使用メモリ 11,268 KB
実行使用メモリ 135,036 KB
最終ジャッジ日時 2023-08-18 12:58:18
合計ジャッジ時間 22,070 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,340 KB
testcase_01 AC 73 ms
15,148 KB
testcase_02 AC 73 ms
15,116 KB
testcase_03 AC 75 ms
15,296 KB
testcase_04 AC 72 ms
15,216 KB
testcase_05 AC 80 ms
15,128 KB
testcase_06 AC 72 ms
15,076 KB
testcase_07 AC 71 ms
15,040 KB
testcase_08 AC 72 ms
15,144 KB
testcase_09 AC 75 ms
15,304 KB
testcase_10 AC 72 ms
15,296 KB
testcase_11 AC 73 ms
15,308 KB
testcase_12 AC 76 ms
15,156 KB
testcase_13 AC 74 ms
15,228 KB
testcase_14 AC 70 ms
15,044 KB
testcase_15 AC 73 ms
15,280 KB
testcase_16 AC 728 ms
133,464 KB
testcase_17 AC 714 ms
133,512 KB
testcase_18 AC 732 ms
133,560 KB
testcase_19 AC 1,399 ms
134,976 KB
testcase_20 AC 697 ms
133,560 KB
testcase_21 AC 718 ms
133,424 KB
testcase_22 AC 1,366 ms
134,864 KB
testcase_23 AC 702 ms
133,676 KB
testcase_24 AC 692 ms
133,412 KB
testcase_25 AC 699 ms
133,464 KB
testcase_26 AC 1,352 ms
135,036 KB
testcase_27 AC 1,364 ms
134,828 KB
testcase_28 AC 702 ms
133,516 KB
testcase_29 AC 1,359 ms
134,740 KB
testcase_30 AC 696 ms
133,532 KB
testcase_31 AC 701 ms
133,520 KB
testcase_32 AC 715 ms
133,500 KB
testcase_33 AC 1,357 ms
134,976 KB
testcase_34 AC 709 ms
133,524 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Array
  def dividable_by_3
    (sum % 3).zero?
  end

  def dividable_by_5
    (alternating_sum % 5).zero?
  end

  def alternating_sum
    x = 0
    is_positive = true

    each do |i|
      if is_positive
        x += i
        is_positive = false
      else
        x -= i
        is_positive = true
      end
    end

    x
  end
end

def solve
  tmp = (N.dividable_by_3 ? 'Fizz' : '') + (N.dividable_by_5 ? 'Buzz' : '')
  tmp == '' ? N.join : tmp
end

N = gets.chomp.chars.map(&:to_i)

puts solve
0