aboutsummaryrefslogtreecommitdiff
path: root/challenge-104
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2021-03-22 00:30:30 +0000
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2021-03-22 00:30:30 +0000
commit816a93d813adbad0616374a025065e09996c426f (patch)
tree6bea2a048066d44ffd3b10f298f30df6b4309bf7 /challenge-104
parentce13ffed92a5204f80e4d010f246bd92892618c4 (diff)
downloadperlweeklychallenge-club-816a93d813adbad0616374a025065e09996c426f.tar.gz
perlweeklychallenge-club-816a93d813adbad0616374a025065e09996c426f.tar.bz2
perlweeklychallenge-club-816a93d813adbad0616374a025065e09996c426f.zip
- Added C, Gembase, Python and Ruby by Laurent Rosenfeld.
Diffstat (limited to 'challenge-104')
-rw-r--r--challenge-104/laurent-rosenfeld/c/ch-1.c21
-rw-r--r--challenge-104/laurent-rosenfeld/gembase/ch-1.dml21
-rw-r--r--challenge-104/laurent-rosenfeld/python/ch-2.py24
-rw-r--r--challenge-104/laurent-rosenfeld/ruby/ch-1.rb16
4 files changed, 82 insertions, 0 deletions
diff --git a/challenge-104/laurent-rosenfeld/c/ch-1.c b/challenge-104/laurent-rosenfeld/c/ch-1.c
new file mode 100644
index 0000000000..d79a80894a
--- /dev/null
+++ b/challenge-104/laurent-rosenfeld/c/ch-1.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+
+#define SIZE 50
+
+int fusc[SIZE];
+
+int main(void) {
+ int fusc[SIZE];
+ fusc[0] = 0;
+ fusc[1] = 1;
+ for (int i = 2; i < SIZE; i++) {
+ fusc[i] = i % 2 ?
+ fusc[(i-1)/2 ] + fusc[(i+1)/2] :
+ fusc[i/2];
+ };
+ for (int i = 0; i < SIZE; i++) {
+ printf("%d ", fusc[i]);
+ }
+ printf("\n");
+ return 0;
+}
diff --git a/challenge-104/laurent-rosenfeld/gembase/ch-1.dml b/challenge-104/laurent-rosenfeld/gembase/ch-1.dml
new file mode 100644
index 0000000000..6d16337351
--- /dev/null
+++ b/challenge-104/laurent-rosenfeld/gembase/ch-1.dml
@@ -0,0 +1,21 @@
+PROCEDURE_FORM FUSC
+ #size = 50
+ #fusc(0) = 0
+ #fusc(1) = 1
+ #i = 2
+ while(#i < #size)
+ if (mod (#i, 2))
+ #fusc(#i) = #fusc((#i-1)/2) + #fusc((#i+1)/2)
+ else
+ #fusc(#i) = #fusc(#i/2)
+ end_if
+ #i = #i + 1
+ end_while
+ #string = ""
+ #i = 0
+ while (#i < #size)
+ #string = #string & #fusc(#i) & " "
+ #i = #i + 1
+ end_while
+ print(#string)
+END_FORM
diff --git a/challenge-104/laurent-rosenfeld/python/ch-2.py b/challenge-104/laurent-rosenfeld/python/ch-2.py
new file mode 100644
index 0000000000..d260e649dc
--- /dev/null
+++ b/challenge-104/laurent-rosenfeld/python/ch-2.py
@@ -0,0 +1,24 @@
+heap_count = 12
+max_picks = 3
+def pick_one_val(count):
+ pick = input("There are " + str(count) + " tokens left. How many tokens do you pick? ");
+ return pick
+
+who_starts = input("Please say who starts (Y/I):")
+if who_starts == "Y":
+ pick = pick_one_val(heap_count)
+ heap_count = heap_count - int(pick)
+while True:
+ pick = heap_count % (max_picks + 1)
+ if pick == 0:
+ pick = 1
+ print("I picked ", str(pick), " tokens.")
+ heap_count = heap_count - int(pick)
+ if heap_count == 0:
+ print("I won!");
+ break
+ pick = pick_one_val(heap_count)
+ heap_count = heap_count - int(pick)
+ if heap_count == 0:
+ print ("You won!")
+ break
diff --git a/challenge-104/laurent-rosenfeld/ruby/ch-1.rb b/challenge-104/laurent-rosenfeld/ruby/ch-1.rb
new file mode 100644
index 0000000000..db7155fedb
--- /dev/null
+++ b/challenge-104/laurent-rosenfeld/ruby/ch-1.rb
@@ -0,0 +1,16 @@
+$fusc = Hash.new
+$fusc[0] = 0
+$fusc[1] = 1
+$size = 50
+
+for i in 2 .. ($size-1) do
+ if i % 2 == 0
+ $fusc[i] = $fusc[i/2]
+ else
+ $fusc[i] = $fusc[(i-1)/2] + $fusc[(i+1)/2]
+ end
+end
+for i in 0..($size-1) do
+ print $fusc[i], " "
+end
+print "\n"