diff options
| author | 冯昶 <seaker@qq.com> | 2021-03-15 18:13:51 +0800 |
|---|---|---|
| committer | 冯昶 <seaker@qq.com> | 2021-03-15 18:13:51 +0800 |
| commit | 8b6be37fe4dac8b4c6489a95e55514b76b298d15 (patch) | |
| tree | ae36c8ec2c71f606c0e36adaa19dba366a68a0b4 /challenge-003/abigail/ruby | |
| parent | 865acfd056fb6f409ec6b1a81d60b931cbcb69fe (diff) | |
| parent | c9aec2da6bcb04b488183f09ca94bee488557aff (diff) | |
| download | perlweeklychallenge-club-8b6be37fe4dac8b4c6489a95e55514b76b298d15.tar.gz perlweeklychallenge-club-8b6be37fe4dac8b4c6489a95e55514b76b298d15.tar.bz2 perlweeklychallenge-club-8b6be37fe4dac8b4c6489a95e55514b76b298d15.zip | |
Merge branch 'master' of github.com:seaker/perlweeklychallenge-club
Diffstat (limited to 'challenge-003/abigail/ruby')
| -rw-r--r-- | challenge-003/abigail/ruby/ch-1.rb | 26 | ||||
| -rw-r--r-- | challenge-003/abigail/ruby/ch-2.rb | 39 |
2 files changed, 65 insertions, 0 deletions
diff --git a/challenge-003/abigail/ruby/ch-1.rb b/challenge-003/abigail/ruby/ch-1.rb new file mode 100644 index 0000000000..c0a22397b0 --- /dev/null +++ b/challenge-003/abigail/ruby/ch-1.rb @@ -0,0 +1,26 @@ +#!/usr/bin/ruby + +# +# See ../README.md +# + +# +# Run as: ruby ch-1.rb < input-file +# + +ARGF . each_line do |_| + max = _ . to_i + base2 = 1 + while base2 <= max + base3 = base2 + while base3 <= max + base5 = base3 + while base5 <= max + puts base5 + base5 *= 5 + end + base3 *= 3 + end + base2 *= 2 + end +end diff --git a/challenge-003/abigail/ruby/ch-2.rb b/challenge-003/abigail/ruby/ch-2.rb new file mode 100644 index 0000000000..85736b99cb --- /dev/null +++ b/challenge-003/abigail/ruby/ch-2.rb @@ -0,0 +1,39 @@ +#!/usr/bin/ruby + +# +# See ../README.md +# + +# +# Run as: ruby ch-2.rb < input-file +# + +ARGF . each_line do |_| + rows = _ . to_i + + # + # 0-th row + # + row = [1] + puts row [0] + for r in 1 .. rows do + # + # Create new row + # + new = [] + for i in 0 .. r do + new [i] = (i == 0 ? 0 : row [i - 1]) + + (i == r ? 0 : row [i]) + if i > 0 + then print " " + end + print new [i] + end + puts "" + + # + # New row becomes current row + # + row = new + end +end |
