Prolog solution by jimbxb
A collection of solutions written in Prolog.
Uses Prolog's infinite-width integers to store the state of the sieve wrapped in the bitvector/2
functor.
Uses a dynamically defined functor (composite/2
) to track the state of the currently known composite numbers.
Uses SWI Prolog's foreign interface with C to implement a more optimised version of the bitvector/2
functor.
$ cd path/to/prolog/solution
$ swipl-ld -cc-options,-w,-O3 -shared -o bitvector bitvector.c
$ ./run.sh
$ cd path/to/dockerfile
$ docker build -t prolog-primes .
$ docker run --rm prolog-primes
$ ./run.sh
jimbxb-prolog-dynamic;4;5.586000;1;algorithm=base,faithful=no
jimbxb-prolog-basic;1;7.271000;1;algorithm=base,faithful=yes,bits=1
jimbxb-prolog-c;56;5.056000;1;algorithm=base,faithful=no,bits=1
C Foreign Language Interface code is inspired by the SWI-PL examples here.