diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2021-06-24 19:40:05 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2021-06-24 19:40:05 +0100 |
| commit | 47c31b2fddb7e0695795d799aaf1cdbf82083a3f (patch) | |
| tree | 2176e31ea400ef69b153cfd2dc827c428aeb9e76 | |
| parent | cf638c1ad15fad8e756291ea904de1547d286592 (diff) | |
| download | perlweeklychallenge-club-47c31b2fddb7e0695795d799aaf1cdbf82083a3f.tar.gz perlweeklychallenge-club-47c31b2fddb7e0695795d799aaf1cdbf82083a3f.tar.bz2 perlweeklychallenge-club-47c31b2fddb7e0695795d799aaf1cdbf82083a3f.zip | |
Add bc solution to challenge 007
| -rw-r--r-- | challenge-007/paulo-custodio/bc/ch-1.bc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/challenge-007/paulo-custodio/bc/ch-1.bc b/challenge-007/paulo-custodio/bc/ch-1.bc new file mode 100644 index 0000000000..217322c92b --- /dev/null +++ b/challenge-007/paulo-custodio/bc/ch-1.bc @@ -0,0 +1,35 @@ +#!/usr/bin/bc -ql + +/* +Challenge 007 + +Challenge #1 +Print all the niven numbers from 0 to 50 inclusive, each on their own line. +A niven number is a non-negative number that is divisible by the sum of its +digits. +*/ + +scale = 0 + +num = read() + +define niven(n) { + auto rem, sum + sum = 0 + rem = n + while (rem > 0) { + sum += rem % 10 + rem /= 10 + } + if ((n % sum) == 0) { + return 1 + } else { + return 0 + } +} + +for (i = 1; i <= num; i++) + if (niven(i)) + print i, "\n" + +quit |
