Skip to content

Latest commit

 

History

History
 
 

solution_1

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Prolog solution by jimbxb

Algorithm Faithfulness Faithfulness Parallelism Bit count Bit count

A collection of solutions written in Prolog.

Solution 1.1 - Basic

Algorithm Faithfulness Parallelism Bit count

Uses Prolog's infinite-width integers to store the state of the sieve wrapped in the bitvector/2 functor.

Solution 1.2 - Dynamic

Algorithm Faithfulness Parallelism Bit count

Uses a dynamically defined functor (composite/2) to track the state of the currently known composite numbers.

Solution 1.3 - C Foreign Interface

Algorithm Faithfulness Parallelism Bit count

Uses SWI Prolog's foreign interface with C to implement a more optimised version of the bitvector/2 functor.

Run

Locally

$ cd path/to/prolog/solution
$ swipl-ld -cc-options,-w,-O3 -shared -o bitvector bitvector.c
$ ./run.sh

Docker

$ cd path/to/dockerfile
$ docker build -t prolog-primes .
$ docker run --rm prolog-primes

Output

$ ./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

Acknowledgements

C Foreign Language Interface code is inspired by the SWI-PL examples here.