diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2021-12-06 14:55:30 +0000 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2021-12-06 14:55:30 +0000 |
| commit | cd04687f29d4ebea2fd5ec165585b21f2951f413 (patch) | |
| tree | 5c17b623d6b7a8cb803a4464f19d157152143e62 /challenge-141/abigail/lua | |
| parent | fe57a0405720a40beaeb75100e069aaa13e4c49e (diff) | |
| parent | b9773f5c38387d865a093d2ecdfd1b01b4452c34 (diff) | |
| download | perlweeklychallenge-club-cd04687f29d4ebea2fd5ec165585b21f2951f413.tar.gz perlweeklychallenge-club-cd04687f29d4ebea2fd5ec165585b21f2951f413.tar.bz2 perlweeklychallenge-club-cd04687f29d4ebea2fd5ec165585b21f2951f413.zip | |
Merge branch 'master' into devel
Diffstat (limited to 'challenge-141/abigail/lua')
| -rw-r--r-- | challenge-141/abigail/lua/ch-1.lua | 36 | ||||
| -rw-r--r-- | challenge-141/abigail/lua/ch-2.lua | 37 |
2 files changed, 73 insertions, 0 deletions
diff --git a/challenge-141/abigail/lua/ch-1.lua b/challenge-141/abigail/lua/ch-1.lua new file mode 100644 index 0000000000..f9b626f6a9 --- /dev/null +++ b/challenge-141/abigail/lua/ch-1.lua @@ -0,0 +1,36 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-1.lua +-- + +local count = 10 +local nr_of_divisor = 8 + +local n = 0 +while count > 0 do + n = n + 1 + local s = math . floor (math . sqrt (n)) + if n == s * s then + goto end_while + end + local c = 0 + for d = 1, s do + if n % d == 0 then + c = c + 2 + if c > nr_of_divisor then + goto end_while + end + end + end + if c == nr_of_divisor then + print (n) + count = count - 1 + end + + ::end_while:: +end diff --git a/challenge-141/abigail/lua/ch-2.lua b/challenge-141/abigail/lua/ch-2.lua new file mode 100644 index 0000000000..b7f87027f4 --- /dev/null +++ b/challenge-141/abigail/lua/ch-2.lua @@ -0,0 +1,37 @@ +#!/opt/local/bin/lua + +-- +-- See ../README.md +-- + +-- +-- Run as: lua ch-2.lua < input-file +-- + +function substrings (n, m, prefix, max) + if n : len () == 0 then + if prefix > -1 and prefix < max and prefix % m == 0 then + return 1 + else + return 0 + end + end + + local fc = tonumber (n : sub (1, 1)) + local tail = n : sub (2) + local n_prefix + if prefix == -1 then + n_prefix = fc + else + n_prefix = 10 * prefix + fc + end + + return substrings (tail, m, n_prefix, max) + + substrings (tail, m, prefix, max) +end + + +for line in io . lines () do + local _, _, n, m = line : find ("([0-9]+)%s+([0-9]+)") + print (substrings (n, tonumber (m), -1, tonumber (n))) +end |
