結果

問題 No.6 使いものにならないハッシュ
ユーザー TANIGUCHI Kousuke
提出日時 2015-07-29 14:25:51
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 836 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-07-17 22:05:45
合計ジャッジ時間 7,151 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 27 WA * 5
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# Here your code !
require 'prime'

def xxx_hash(n)
    if n < 10
        n
    else
        xxx_hash(n.to_s.chars.map(&:to_i).inject(0) {|s,v| s+v})
    end
end

l,h = 2.times.map { gets.to_i }
primes = Prime.each(h).select {|prime|  prime >= l}
puts primes.each_with_index.each_with_object({primes: [], hashes: [], max: 0, head: 0}) {|(v,i),s|
    hash = xxx_hash(v)
    
    if s[:hashes].include?(hash)
        offset = s[:hashes].index(hash)
        s[:hashes] = s[:hashes].drop(offset + 1)
        s[:primes] = s[:primes].drop(offset + 1)
        s[:hashes].push(hash)
        s[:primes].push(v)
    else
        s[:primes].push(v)
        s[:hashes].push(hash)
        
        if s[:hashes].size >= s[:max]
            s[:max] = s[:hashes].size
            s[:head] = s[:primes].first
        end
        
    end
    
}[:head]
0