- 118 名前:デフォルトの名無しさん mailto:sage [2019/08/13(火) 07:30:43.99 ID:kJJDzO2R.net]
- >>91
Ruby で # 数字の配列の配列。改行は削除 nums = <<"EOT".lines( chomp: true ).map{ |str| str.split( "," ).map( &:to_i ) } 1,1,1,1,2,2,2,3,3,4 1,2,3,4,5,5,4,3,2,1 3,1,4,1,5,9,2,6,5,3,5 EOT results = nums.each_with_object( [ ] ) do |ary, results| uniq_ary = ary.uniq # 重複排除 uniq_ary.sort! # ソート res = -1 uniq_ary.each do |num| if ary.count( num ) == 1 res = num; break end end results.push res end p results #=> [4, -1, 2]
|

|