aboutsummaryrefslogtreecommitdiff
path: root/entries/gerui/fib.pl
diff options
context:
space:
mode:
authorBraxton Hall2022-10-31 16:18:17 +0000
committerGitHub2022-10-31 16:18:17 +0000
commit11be438aea968cf34f6e1d9dc4425ad2d76d0479 (patch)
tree6a404e96019951e5e98538494e153e441792f16b /entries/gerui/fib.pl
parentb19e171b583785feb3bc74cacd5be2f238bfef30 (diff)
parent15c42c1c1290997601eddd3a5fce34924760b7de (diff)
Merge pull request #76 from gerui/main
Add Rui Ge
Diffstat (limited to 'entries/gerui/fib.pl')
-rw-r--r--entries/gerui/fib.pl15
1 files changed, 15 insertions, 0 deletions
diff --git a/entries/gerui/fib.pl b/entries/gerui/fib.pl
new file mode 100644
index 0000000..0065246
--- /dev/null
+++ b/entries/gerui/fib.pl
@@ -0,0 +1,15 @@
+% To my surprise, there has been no Prolog implementation submitted so far.
+% To get the ball rolling, and to pay respect to Prolog, here is a well-known Prolog implementation of the Fibonacci sequence.
+
+% fib(N, S): S is the Nth Fibonacci number.
+
+:- table fib/2.
+
+fib(0, 1) :- !.
+fib(1, 1) :- !.
+fib(N, S) :- N > 1,
+ N1 is N-1,
+ N2 is N-2,
+ fib(N1, S1),
+ fib(N2, S2),
+ S is S1+S2.