summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2022-04-23 09:54:47 +0100
committerPaul Buetow <paul@buetow.org>2022-04-23 09:54:47 +0100
commit5eca78af0ff07060b7c740a5be7ce94d7206bf02 (patch)
tree9cce4b94ee307f3898718cf0abca3315ea8c2cdb
parent932844e590156a2bf9d970151382aae50acc30c4 (diff)
this is also valid C++ code (besides of Raku)
-rw-r--r--Makefile9
-rw-r--r--fibonacci.pl.c41
-rw-r--r--fibonacci.pl.raku.c41
-rw-r--r--out.txt49
4 files changed, 90 insertions, 50 deletions
diff --git a/Makefile b/Makefile
index 3132051..3685443 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,10 @@
all:
- gcc fibonacci.pl.c.raku -o fibonacci
+ gcc fibonacci.pl.raku.c -o fibonacci
./fibonacci
@echo
- perl fibonacci.pl.c.raku
+ g++ fibonacci.pl.raku.c -o fibonacci
+ ./fibonacci
+ @echo
+ perl fibonacci.pl.raku.c
@echo
- raku fibonacci.pl.c.raku
+ raku fibonacci.pl.raku.c
diff --git a/fibonacci.pl.c b/fibonacci.pl.c
deleted file mode 100644
index 2482a41..0000000
--- a/fibonacci.pl.c
+++ /dev/null
@@ -1,41 +0,0 @@
-#include <stdio.h>
-
-#define $arg function_argument
-#define my int
-#define sub int
-#define BEGIN int main(void)
-
-my $arg;
-
-sub hello() {
- printf("Hello, welcome to Perl-C!\n");
- printf("This program is both, valid C and Perl code!\n");
- printf("It calculates all fibonacci numbers from 0 to 9!\n\n");
- return 0;
-}
-
-sub fibonacci() {
- my $n = $arg;
-
- if ($n < 2) {
- return $n;
- }
-
- $arg = $n - 1;
- my $fib1 = fibonacci();
- $arg = $n - 2;
- my $fib2 = fibonacci();
-
- return $fib1 + $fib2;
-}
-
-BEGIN {
- hello();
- my $i = 0;
-
- while ($i <= 10) {
- $arg = $i;
- printf("fib(%d) = %d\n", $i, fibonacci());
- $i++;
- }
-}
diff --git a/fibonacci.pl.raku.c b/fibonacci.pl.raku.c
new file mode 100644
index 0000000..ef1af2b
--- /dev/null
+++ b/fibonacci.pl.raku.c
@@ -0,0 +1,41 @@
+#include <stdio.h>
+
+#define $arg function_argument
+#define my int
+#define sub int
+#define BEGIN int main(void)
+
+my $arg;
+
+sub hello() {
+ printf("Hello, welcome to the Fibonacci Numbers!\n");
+ printf("This program is all, valid C and C++ and Perl and Raku code!\n");
+ printf("It calculates all fibonacci numbers from 0 to 9!\n\n");
+ return 0;
+}
+
+sub fibonacci() {
+ my $n = $arg;
+
+ if ($n < 2) {
+ return $n;
+ }
+
+ $arg = $n - 1;
+ my $fib1 = fibonacci();
+ $arg = $n - 2;
+ my $fib2 = fibonacci();
+
+ return $fib1 + $fib2;
+}
+
+BEGIN {
+ hello();
+ my $i = 0;
+
+ while ($i <= 10) {
+ $arg = $i;
+ printf("fib(%d) = %d\n", $i, fibonacci());
+ $i++;
+ }
+}
diff --git a/out.txt b/out.txt
index 86a9882..2fb01e9 100644
--- a/out.txt
+++ b/out.txt
@@ -1,7 +1,7 @@
-gcc fibonacci.pl.c -o fibonacci
+gcc fibonacci.pl.raku.c -o fibonacci
./fibonacci
-Hello, welcome to Perl-C!
-This program is both, valid C and Perl code!
+Hello, welcome to the Fibonacci Numbers!
+This program is all, valid C and Perl and Raku code!
It calculates all fibonacci numbers from 0 to 9!
fib(0) = 0
@@ -14,10 +14,46 @@ fib(6) = 8
fib(7) = 13
fib(8) = 21
fib(9) = 34
+fib(10) = 55
-perl fibonacci.pl.c
-Hello, welcome to Perl-C!
-This program is both, valid C and Perl code!
+g++ fibonacci.pl.raku.c -o fibonacci
+./fibonacci
+Hello, welcome to the Fibonacci Numbers!
+This program is all, valid C and Perl and Raku code!
+It calculates all fibonacci numbers from 0 to 9!
+
+fib(0) = 0
+fib(1) = 1
+fib(2) = 1
+fib(3) = 2
+fib(4) = 3
+fib(5) = 5
+fib(6) = 8
+fib(7) = 13
+fib(8) = 21
+fib(9) = 34
+fib(10) = 55
+
+perl fibonacci.pl.raku.c
+Hello, welcome to the Fibonacci Numbers!
+This program is all, valid C and Perl and Raku code!
+It calculates all fibonacci numbers from 0 to 9!
+
+fib(0) = 0
+fib(1) = 1
+fib(2) = 1
+fib(3) = 2
+fib(4) = 3
+fib(5) = 5
+fib(6) = 8
+fib(7) = 13
+fib(8) = 21
+fib(9) = 34
+fib(10) = 55
+
+raku fibonacci.pl.raku.c
+Hello, welcome to the Fibonacci Numbers!
+This program is all, valid C and Perl and Raku code!
It calculates all fibonacci numbers from 0 to 9!
fib(0) = 0
@@ -30,3 +66,4 @@ fib(6) = 8
fib(7) = 13
fib(8) = 21
fib(9) = 34
+fib(10) = 55