Does this give the set with the lowest sum? <br><br>Also, where is ec.ss?<br><br><div><span class="gmail_quote">On 6/4/07, <b class="gmail_sendername">Jens Axel Søgaard</b> <<a href="mailto:jensaxel@soegaard.net">jensaxel@soegaard.net
</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">An "real world" example from Project Euler. It features<br>five nested loops with four guards.
<br><br> The primes 3, 7, 109, and 673, are quite remarkable. By taking any<br> two primes and concatenating them in any order the result will always<br> be prime. For example, taking 7 and 109, both 7109 and 1097 are prime.
<br> The sum of these four primes, 792, represents the lowest sum for a<br> set of four primes with this property.<br><br> Find the lowest sum for a set of five primes for which any two primes<br> concatenate to produce another prime.
<br><br><br>; :primes ... and next-prime is in ec.ss.<br>; In prime? put an extra 0 or two on N, if you want<br>; more speed.<br><br>(require ec mzscheme)<br>(define N 10000)<br><br>(define (number-append x y)<br> (string->number
<br> (string-append<br> (number->string x) (number->string y))))<br><br><br>(first-ec 'not-found<br> (:primes a 3 N)<br> (:primes b (next-prime a) N)<br> (if (and (prime? (number-append a b))
<br> (prime? (number-append b a))))<br> (:primes c (next-prime b) N)<br> (if (and (prime? (number-append a c))<br> (prime? (number-append c a))<br> (prime? (number-append b c))
<br> (prime? (number-append c b))))<br> (:primes d (next-prime c) N)<br> (if (and (prime? (number-append a d))<br> (prime? (number-append d a))<br> (prime? (number-append b d))
<br> (prime? (number-append d b))<br> (prime? (number-append c d))<br> (prime? (number-append d c))))<br> (:primes e (next-prime d) N)<br> (if (and (prime? (number-append a e))
<br> (prime? (number-append e a))<br> (prime? (number-append b e))<br> (prime? (number-append e b))<br> (prime? (number-append c e))<br> (prime? (number-append e c))
<br> (prime? (number-append d e))<br> (prime? (number-append e d))))<br> (list a b c d e))<br><br><br><br><br>/Jens Axel<br><br><br>_________________________________________________
<br> For list-related administrative tasks:<br> <a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br></blockquote></div><br>