Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Ruby | Integer | lcm

概要

Integer#lcm

詳細

最小公倍数の配列を取得します。
lcm = Least Common Multiple

サンプルコード
# encoding: utf-8
require 'tbpgr_utils'

bulk_puts_eval binding, <<-EOS
2.lcm 4
2.lcm -4
2.lcm 3
2.lcm 0
0.lcm 2
12.lcm 24
EOS

__END__
下記はTbpgrUtils gemの機能
bulk_puts_eval

https://rubygems.org/gems/tbpgr_utils
https://github.com/tbpgr/tbpgr_utils
出力
2.lcm 4 # => 4
2.lcm -4 # => 4
2.lcm 3 # => 6
2.lcm 0 # => 0
0.lcm 2 # => 0
12.lcm 24 # => 24