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/lua | |
| 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/lua')
| -rw-r--r-- | challenge-003/abigail/lua/ch-1.lua | 30 | ||||
| -rw-r--r-- | challenge-003/abigail/lua/ch-2.lua | 51 |
2 files changed, 81 insertions, 0 deletions
diff --git a/challenge-003/abigail/lua/ch-1.lua b/challenge-003/abigail/lua/ch-1.lua new file mode 100644 index 0000000000..70de9b1923 --- /dev/null +++ b/challenge-003/abigail/lua/ch-1.lua @@ -0,0 +1,30 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-1.lua < input-file +-- + +for max in io . lines () do + local max = tonumber (max) + local base2 = 1 + -- + -- Lua doesn't have a for (expr; expr; expr) syntax. + -- This is missed here. + -- + while base2 <= max do + local base3 = base2 + while base3 <= max do + local base5 = base3 + while base5 <= max do + print (base5) + base5 = base5 * 5 + end + base3 = base3 * 3 + end + base2 = base2 * 2 + end +end diff --git a/challenge-003/abigail/lua/ch-2.lua b/challenge-003/abigail/lua/ch-2.lua new file mode 100644 index 0000000000..0e30b0a9c6 --- /dev/null +++ b/challenge-003/abigail/lua/ch-2.lua @@ -0,0 +1,51 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-2.lua < input-file +-- + + +-- +-- Iterate over the input +-- +for line in io . lines () do + local rows = tonumber (line) + + -- + -- Create and print row 0 + -- + local row = {1} + print "1" + + local r + for r = 1, rows do + -- + -- Create a new row + -- + local new = {} + for i = 1, r + 1 do + sum = 0; + if i > 1 + then sum = sum + row [i - 1] + io . write (" ") + end + if i <= r + then sum = sum + row [i] + end + -- + -- Assign new element, and print it + -- + new [i] = sum + io . write (sum) + end + io . write ("\n") + -- + -- New row becomes current row + -- + row = new + end +end |
