議事録(117) - hamamatsu-rb/hamamatsu-rb.github.com GitHub Wiki
Hamamatsu.rb 117
告知
Ruby Advent Calendar 2020
Ruby 3.0 Advent Calendar 2020
基礎文法最速マスターランキング
-
興味のある人は書いてください
浜松IT合同勉強会2020 LT大会もよろしく(12/19)
Rubyプログラミング体験会
前回の振り返り
- 問題案を提示していただきました
yukicoder
Array Battle
皆の回答
-
配列のpermutationとzipが肝
io = STDIN
io.gets
aa = io.gets.split(' ').map(&:to_i)
ba = io.gets.split(' ').map(&:to_i)
max_point = 0
max_point_count = 0
aa.permutation do |a_seq| #全組み合わせを生成
sum = 0
a_seq.zip(ba) do |a, b|
point = a - b #いっこずつ比較
sum += point if point.positive?
end
if max_point < sum
max_point = sum
max_point_count = 1
elsif max_point == sum
max_point_count += 1
end
end
puts max_point_count
class Array
using Module.new {
refine Integer do
def -(other)
(super other).tap { break 0 if _1 < 0 }
end
end
}
def battle(other)
zip(other).map { |a, b| a - b }.sum
end
end
def calc(inputs)
a, b = inputs[1..].map { _1.split.map(&:to_i) }
a.permutation.map { |xs| xs.battle(b) }.then { |result|
result.count result.max
}
end
inputs = [
"3",
"3 4",
"1 4"
]
# inputs = [
# "3",
# "5 5 5",
# "7 5 6"
# ]
# inputs = [
# "5",
# "6 5 5 4 4",
# "1 3 5 7 9"
# ]
inputs = [gets, gets, gets]
puts calc(inputs)
p a.permutation.map { |xs| xs.battle(b) }.tally
# => {7=>28, 6=>48, 5=>36, 4=>8}
-
ワンライナーにも挑戦したがマニアワナカッタ...
-
☆1.5も油断ならない
-
最大と最小を充てた方が速いのかもしれない
-
書き途中↓
3.times.map { gets } in [_, a, b]
[a, b].map { _1.split.map(&:to_i) } in [a, b]
[a.sort!, b.sort! { _2 <=> _1 }].transpose.group_by { _1 > _2 ? :win : :lose } in results
if results.key?(:win)
else
results[:lose].map(&:first).permutation.to_a.length
end
- _1 は hoge { |_1| _1 } と hoge { _1 } と同じ意味です
言語処理100本ノック
-
- 文字列の逆順
"stressed".reverse
-
- 「パタトクカシーー」
-
ワンライナー回答
p "パタトクカシーー".chars.select.with_index { |c, i| i.even? }.join
p "パタトクカシーー".scan(/(.)./).join
puts 'パタトクカシーー'.chars.partition.with_index(1) { _2.odd? }.first.join
puts 'パタトクカシーー'.chars.values_at(1, 3, 5, 7).join
puts "パタトクカシーー".gsub(/(.)./, '\1')
puts 'パタトクカシーー'.chars.values_at(*1.step(7, 2).map { _1 }).join
おすすめの本
-
珠玉のプログラミング 本質を見抜いたアルゴリズムとデータ構造
KPT
KEEP
-
色々な解法が見れて良かった ★2
-
参加できた
-
values_at ★2
-
言語処理100本も面白そう ★1
-
values_atかっこいい
PROBLEM
-
1問目がマニアワナカッタ... ★1
-
遅刻してしまった… ★1
-
1問目
-
前回も出てきた#permutationがサクッとでてこないかった ★2
-
数学っぽい問題は「Rubyで遊ぶ余裕」みたいなのが無くなってしまうかもしれない ★5
-
1問目あと2ケースがテスト通らない・・・
-
PC の調子が悪くてつらい… ★1
-
問題の意図を読み取るのがむずかしい… ★1
TRY
-
よく使いそうな関数をまとめておく ★2
-
議事録リアルタイム化 ★4
-
言語処理に強くなる ★1
-
問題を解き直す ★1
-
復習する ★1
-
もうちょっと簡単な問題を解いてみるのでもよいかも ★1
-
後で、Slackに質問します! ★1
-
次回12/9(水)通常開催 ★1
-
次回は 2020/12/9(水) ★2
-
数学問題避けるか… ★3
雑談
-
次回はesaで議事録を取ります
次回
- 12/9(水)オンラインで開催します