Skip to content

Commit 9520747

Browse files
committed
Provide a Prolog implementation
1 parent 1b1ac01 commit 9520747

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/prolog/standard/README.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Prolog
2+
[Prolog][lang:prolog] is a
3+
4+
> Prolog is a logic programming language that has its origins in artificial
5+
> intelligence, automated theorem proving and computational linguistics.
6+
7+
## Development
8+
For this you need a Prolog runtime like [swi-prolog][swi-prolog] or an online
9+
environment like [swish][swish].
10+
11+
The following database will suffice
12+
13+
```prolog
14+
fizzbuzz(N, "FizzBuzz") :- Q is mod(N, 15), Q == 0.
15+
fizzbuzz(N, "Buzz") :- Q is mod(N, 5), Q == 0.
16+
fizzbuzz(N, "Fizz") :- Q is mod(N, 3), Q == 0.
17+
fizzbuzz(N, N).
18+
```
19+
20+
One then can ask questions like
21+
22+
```plain
23+
?- fizzbuzz(9, X).
24+
X = "Fizz"
25+
```
26+
27+
[lang:prolog]: https://en.wikipedia.org/wiki/Prolog
28+
[swi-prolog]: https://www.swi-prolog.org/
29+
[swish]: https://wasm.swi-prolog.org/wasm/shell

src/prolog/standard/fizzbuzz.pl

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fizzbuzz(N, "FizzBuzz") :- Q is mod(N, 15), Q == 0.
2+
fizzbuzz(N, "Buzz") :- Q is mod(N, 5), Q == 0.
3+
fizzbuzz(N, "Fizz") :- Q is mod(N, 3), Q == 0.
4+
fizzbuzz(N, N).

0 commit comments

Comments
 (0)