結果
| 問題 | No.593 4進FizzBuzz | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-07-17 09:32:36 | 
| 言語 | Ruby (3.4.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,553 ms / 2,000 ms | 
| コード長 | 507 bytes | 
| コンパイル時間 | 33 ms | 
| コンパイル使用メモリ | 7,296 KB | 
| 実行使用メモリ | 138,624 KB | 
| 最終ジャッジ日時 | 2024-11-27 18:08:14 | 
| 合計ジャッジ時間 | 24,083 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 31 | 
コンパイルメッセージ
Syntax OK
ソースコード
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
            
            
            
        