Created
May 30, 2013 22:00
-
-
Save acgetchell/5681609 to your computer and use it in GitHub Desktop.
problem7.jl for debugging jocco
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# in problem7.jl | |
# find the 10,001st prime number | |
# isPrime(n) uses the sieve of Eratosthenes | |
# Test LaTeX | |
# Using [Pandoc] allows us to have math inline $x=y$ or in display mode | |
# $$ | |
# \begin{aligned} | |
# \nabla \times \vec{\mathbf{B}} -\, \frac1c\, | |
# \frac{\partial\vec{\mathbf{E}}}{\partial t} &= | |
# \frac{4\pi}{c}\vec{\mathbf{j}} \\ | |
# \nabla \cdot \vec{\mathbf{E}} &= 4 \pi \rho \\ | |
# \nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, | |
# \frac{\partial\vec{\mathbf{B}}}{\partial t} &= \vec{\mathbf{0}} \\ | |
# \nabla \cdot \vec{\mathbf{B}} &= 0 | |
# \end{aligned} | |
# $$ | |
# if you wish. This uses the [MathJax] Content Distribution Network script to | |
# turn $\LaTeX$ source into rendered output and thus an internet connection is | |
# required. [MathJax] may be installed locally if offline access is desired. | |
# | |
# @Knuth:1984:LP might be something we should read when building a literate | |
# programming tool. We can also reference this in a note.[^1] | |
# | |
# This [Julia] port of [Docco] is roughly structured the same as the [Lua] | |
# port [Locco]. Its source is released in the public domain and is available | |
# on [GitHub](http://github.com/lcw/jocco). | |
function isPrime(n) | |
if n == 1 | |
return false | |
elseif n < 4 | |
return true | |
elseif mod(n,2) == 0 | |
return false | |
elseif n < 9 | |
return true | |
elseif mod(n,3) == 0 | |
return false | |
else | |
r = floor(sqrt(n)) | |
f = 5 | |
while f <= r | |
if mod(n,f) == 0 | |
return false | |
elseif mod(n,f+2) == 0 | |
return false | |
else | |
f += 6 | |
end | |
end | |
end | |
return true | |
end | |
limit = 10001 | |
count = 1 | |
candidate = 1 | |
while count != limit | |
candidate += 2 | |
if isPrime(candidate) | |
count += 1 | |
end | |
end | |
println(candidate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment