diff options
| author | E7-87-83 <fungcheokyin@gmail.com> | 2022-02-22 07:56:32 +0800 |
|---|---|---|
| committer | E7-87-83 <fungcheokyin@gmail.com> | 2022-02-22 07:56:32 +0800 |
| commit | 645f6594284fc138b8a54647f5fbf96fe3afdac7 (patch) | |
| tree | 432bb51547f2d259e58ddb6058b983d4763fdd5e | |
| parent | b77e7339ff36bfcd47a7c1464d43e9fd8bb935e8 (diff) | |
| download | perlweeklychallenge-club-645f6594284fc138b8a54647f5fbf96fe3afdac7.tar.gz perlweeklychallenge-club-645f6594284fc138b8a54647f5fbf96fe3afdac7.tar.bz2 perlweeklychallenge-club-645f6594284fc138b8a54647f5fbf96fe3afdac7.zip | |
The Weekly Challenge 153: Dart solution
| -rw-r--r-- | challenge-153/cheok-yin-fung/dart/ch-1.dart | 20 | ||||
| -rw-r--r-- | challenge-153/cheok-yin-fung/dart/ch-2.dart | 30 |
2 files changed, 50 insertions, 0 deletions
diff --git a/challenge-153/cheok-yin-fung/dart/ch-1.dart b/challenge-153/cheok-yin-fung/dart/ch-1.dart new file mode 100644 index 0000000000..192902b5c7 --- /dev/null +++ b/challenge-153/cheok-yin-fung/dart/ch-1.dart @@ -0,0 +1,20 @@ +// The Weekly Challenge 153 +// Task 1: Left Factorials +// Usage: dart ch-1.dart + +void main() { + const arg = 10; + var factorial = [1]; + for (int i = 1; i <= arg; i++) { + factorial.add(factorial[i-1]*i); + } + + var leftfactorial = [0]; + + for (int i = 1; i <= arg; i++) { + leftfactorial.add(leftfactorial[i-1]+factorial[i-1]); + } + for (int i = 1; i <= arg; i++) { + print(leftfactorial[i]); + } +} diff --git a/challenge-153/cheok-yin-fung/dart/ch-2.dart b/challenge-153/cheok-yin-fung/dart/ch-2.dart new file mode 100644 index 0000000000..4a54b1fee5 --- /dev/null +++ b/challenge-153/cheok-yin-fung/dart/ch-2.dart @@ -0,0 +1,30 @@ +// The Weekly Challenge 153 +// Task 2: Factorions +// Usage: dart ch-2.dart [Positive Integer] + +void main(List<String> arguments) { +// define factorial + var factorial = [1]; + for (int i = 1; i <= 9; i++) { + factorial.add(factorial[i-1]*i); + } + +// convert input into a list of positive integers < 10 + String mystr = arguments[0]; + var myint = int.parse(mystr); + mystr = myint.toString(); // avoid leading zeros + var digits = <int>[]; + mystr.split("").forEach((item) { + digits.add(int.parse(item)); + }); + +// sum + var sum = 0; + digits.forEach((d) { + sum += factorial[d]; + }); + +// wrap-up + print( myint.toString() + " is a factorion: " + + (sum == myint).toString() ); +} |
