** palendromic primes
:PROPERTIES:
:DATE: 2010-07-20
:END:
Note that because Haskell is funny about what can be typed into the
interpreter, the following should be loaded with
=org-babel-load-in-session=.
#+begin_src haskell
palendromic_primes = [x | x <- [1..], prime x, palendrome x]
where
factors n = [x | x <- [1..floor(sqrt(fromIntegral(n)))], n `mod` x == 0]
prime n = factors n == [1]
primes = [x | x <- [2..], prime x]
palendrome n = show(n) == reverse(show(n))
palendromic_prime_distances = map (\(x,y)-> y-x) neighbors
where
neighbors = (zip palendromic_primes (tail palendromic_primes))
#+end_src
#+name: palendromic_prime_distances
#+begin_src haskell
take 180 (zip [1..] palendromic_prime_distances)
#+end_src
For high-quality png output from gnuplot, the following sequence of
graphing to a =.eps= file, and then converting to a =.png= can be
useful.
#+name: dist-graph
#+begin_src gnuplot :var data=palendromic_prime_distances :file pps.eps
set term postscript landscape color enhanced
set log y
set title "distance between consecutive palendromic primes"
plot "$data" with fs notitle
#+end_src
The =convert= command is part of the [[http://www.imagemagick.org/script/index.php][imagemagick]] suite.
#+begin_src sh :var input=dist-graph :results file
convert -depth 300 -rotate 90 $input pps.png
echo "pps.png"
#+end_src