aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-02-27 14:06:18 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-02-27 14:06:18 +0000
commit18eb47ce3819fc1970cce4e690717ec47168a9fc (patch)
treebb40096958eac7023c97079031da477314e6d4ab
parent8c1d54d0d2fee25a02ff012e0c7a8eec2b65a886 (diff)
downloadperlweeklychallenge-club-18eb47ce3819fc1970cce4e690717ec47168a9fc.tar.gz
perlweeklychallenge-club-18eb47ce3819fc1970cce4e690717ec47168a9fc.tar.bz2
perlweeklychallenge-club-18eb47ce3819fc1970cce4e690717ec47168a9fc.zip
- Added more guest contributions by Laurent Rosenfeld.
-rw-r--r--challenge-153/laurent-rosenfeld/awk/ch-1.awk10
-rw-r--r--challenge-153/laurent-rosenfeld/awk/ch-2.awk23
-rw-r--r--challenge-153/laurent-rosenfeld/bc/ch-1.bc8
-rw-r--r--challenge-153/laurent-rosenfeld/bc/ch-2.bc16
-rw-r--r--challenge-153/laurent-rosenfeld/c/ch-1.c13
-rw-r--r--challenge-153/laurent-rosenfeld/c/ch-2.c27
-rw-r--r--challenge-153/laurent-rosenfeld/python/ch-1.py7
-rw-r--r--challenge-153/laurent-rosenfeld/python/ch-2.py15
-rw-r--r--challenge-153/laurent-rosenfeld/ring/ch-1.ring8
-rw-r--r--challenge-153/laurent-rosenfeld/ring/ch-2.ring19
10 files changed, 146 insertions, 0 deletions
diff --git a/challenge-153/laurent-rosenfeld/awk/ch-1.awk b/challenge-153/laurent-rosenfeld/awk/ch-1.awk
new file mode 100644
index 0000000000..a30c9ae1e0
--- /dev/null
+++ b/challenge-153/laurent-rosenfeld/awk/ch-1.awk
@@ -0,0 +1,10 @@
+BEGIN {
+ left_fact = 1
+ fact = 1
+ for (i = 1; i <= 10; i++) {
+ printf "%d ", left_fact
+ fact *= i
+ left_fact += fact
+ }
+ printf "\n"
+}
diff --git a/challenge-153/laurent-rosenfeld/awk/ch-2.awk b/challenge-153/laurent-rosenfeld/awk/ch-2.awk
new file mode 100644
index 0000000000..ccd2287410
--- /dev/null
+++ b/challenge-153/laurent-rosenfeld/awk/ch-2.awk
@@ -0,0 +1,23 @@
+function populate_fact() {
+ fact[0] = 1
+ for (n = 1; n <= 9; n++) {
+ fact[n] = n * fact[n - 1]
+ }
+}
+function is_factorion(num) {
+ sum = 0
+ start_num = num
+ for (n = 0; n < length(start_num); n++) {
+ sum += fact[num % 10]
+ num = int(num / 10)
+ }
+ return sum == start_num
+ }
+BEGIN {
+ populate_fact()
+ for (i = 1; i <= 50000; i++) {
+ if (is_factorion(i)) {
+ print i
+ }
+ }
+}
diff --git a/challenge-153/laurent-rosenfeld/bc/ch-1.bc b/challenge-153/laurent-rosenfeld/bc/ch-1.bc
new file mode 100644
index 0000000000..40c14057fc
--- /dev/null
+++ b/challenge-153/laurent-rosenfeld/bc/ch-1.bc
@@ -0,0 +1,8 @@
+sum = 1
+fact = 1
+
+for (n = 1; n <= 10; n ++) {
+ print sum, " "
+ fact = fact * n
+ sum = sum + fact
+}
diff --git a/challenge-153/laurent-rosenfeld/bc/ch-2.bc b/challenge-153/laurent-rosenfeld/bc/ch-2.bc
new file mode 100644
index 0000000000..f813c4560d
--- /dev/null
+++ b/challenge-153/laurent-rosenfeld/bc/ch-2.bc
@@ -0,0 +1,16 @@
+fact[0] = 1
+for (n = 1; n <= 9; n++) {
+ fact[n] = n * fact[n - 1]
+}
+for (n = 1; n <= 50000; n++) {
+ sum = 0
+ i = n
+ while (i > 0) {
+ sum += fact[i % 10]
+ i /= 10
+ }
+ if (sum == n) {
+ print n, " "
+ }
+}
+halt
diff --git a/challenge-153/laurent-rosenfeld/c/ch-1.c b/challenge-153/laurent-rosenfeld/c/ch-1.c
new file mode 100644
index 0000000000..f5be36aaa2
--- /dev/null
+++ b/challenge-153/laurent-rosenfeld/c/ch-1.c
@@ -0,0 +1,13 @@
+#include <stdio.h>
+
+int main () {
+ int sum = 1;
+ int fact = 1;
+ for (int i = 1; i <= 10; i++) {
+ printf("%d ", sum);
+ fact *= i;
+ sum += fact;
+ }
+ printf ("\n");
+ return 0;
+}
diff --git a/challenge-153/laurent-rosenfeld/c/ch-2.c b/challenge-153/laurent-rosenfeld/c/ch-2.c
new file mode 100644
index 0000000000..9ea60c09fe
--- /dev/null
+++ b/challenge-153/laurent-rosenfeld/c/ch-2.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+
+char is_factorion(int fact[], int num) {
+ int sum = 0;
+ int n = num;
+ while (n > 0) {
+ sum += fact[n % 10];
+ n /= 10;
+ }
+ return num == sum;
+}
+
+int main() {
+ int fact[10];
+ fact[0] = 1;
+ for (int i = 1; i <= 9; i++) {
+ fact[i] = i * fact[i - 1];
+ }
+
+ for (int n = 1; n < 50000; n++) {
+ if (is_factorion(fact, n)) {
+ printf("%d ", n);
+ }
+ }
+ printf("\n");
+ return 0;
+}
diff --git a/challenge-153/laurent-rosenfeld/python/ch-1.py b/challenge-153/laurent-rosenfeld/python/ch-1.py
new file mode 100644
index 0000000000..159f8db710
--- /dev/null
+++ b/challenge-153/laurent-rosenfeld/python/ch-1.py
@@ -0,0 +1,7 @@
+fact = 1
+left_fact = 1
+
+for n in range (1, 11):
+ print(left_fact)
+ fact = fact * n
+ left_fact = left_fact + fact
diff --git a/challenge-153/laurent-rosenfeld/python/ch-2.py b/challenge-153/laurent-rosenfeld/python/ch-2.py
new file mode 100644
index 0000000000..6468fa9f27
--- /dev/null
+++ b/challenge-153/laurent-rosenfeld/python/ch-2.py
@@ -0,0 +1,15 @@
+fact = [1] * 10
+for n in range (1, 10):
+ fact[n] = n * fact[n - 1]
+
+def is_factorion (input):
+ sum = 0
+ n = str(input)
+ for i in range (0, len(n)):
+ sum = sum + fact[int(n[i])]
+
+ return input == sum
+
+for n in range(1, 50000):
+ if is_factorion(n):
+ print(n)
diff --git a/challenge-153/laurent-rosenfeld/ring/ch-1.ring b/challenge-153/laurent-rosenfeld/ring/ch-1.ring
new file mode 100644
index 0000000000..ff0aff779d
--- /dev/null
+++ b/challenge-153/laurent-rosenfeld/ring/ch-1.ring
@@ -0,0 +1,8 @@
+left_fact = 1
+fact = 1
+for i = 1 to 10
+ see " " + left_fact
+ fact *= i
+ left_fact += fact
+next
+see " " + nl
diff --git a/challenge-153/laurent-rosenfeld/ring/ch-2.ring b/challenge-153/laurent-rosenfeld/ring/ch-2.ring
new file mode 100644
index 0000000000..5f9d4989fd
--- /dev/null
+++ b/challenge-153/laurent-rosenfeld/ring/ch-2.ring
@@ -0,0 +1,19 @@
+fact = [1, 1]
+for k = 2 to 9
+ add (fact, k * fact[k]) # list indices start at 1
+next
+# see fact + nl
+for n = 1 to 50000
+ if is_factorion(fact, n)
+ see n + nl
+ ok
+next
+
+func is_factorion fact, input
+ sum = 0
+ n = "" + input
+ for i = 1 to len(n)
+ digit = n[i]
+ sum += fact[1 + digit]
+ next
+ return input = sum