# 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]