Pure Programmer
Blue Matrix


Cluster Map

Project: Number of Primes (Estimate)

The number of primes equal to or less than a number x is denoted by the function `π(x)`. There is no easy way to compute this function although there are ways to estimate it. Write a function `π(x)` that uses the estimate formula `x/(ln x - 1)`. Assert that values of x must be greater to or equal to 100. Write a test program to print the estimated values of `π(x)` for x that are powers of 10 from `10^2` up to `10^9`. How does this approach compare to the actual value of `π(x)`?

See [[How Many Primes Are There?]]

Output
$ swiftc NumberOfPrimesEstimate.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation)

Solution