Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
116 Prime Sandwich times out
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jim Altieri  
View profile  
 More options Oct 4 2012, 1:17 pm
From: Jim Altieri <j...@tweeg.net>
Date: Thu, 4 Oct 2012 10:17:05 -0700 (PDT)
Local: Thurs, Oct 4 2012 1:17 pm
Subject: 116 Prime Sandwich times out

Hey folks,
I know my solution is probably not the best, but it executes on my machine
pretty quickly. Am I doing anything obviously wrong?

(fn [x] (let [prime? (fn [n] (if (= 2 n)
                               true
                               (not-any? #(zero? (rem n %)) (concat '(2)
(range 3 (+ 1 (int (Math/sqrt n))))))))
               nextprime (fn [n] (if (= 2 n)
                                  3
                                  (some #(if (prime? %) %) (iterate
(partial + 2) (+ n 2)))))]
           (if (>= x 5)
             (if (prime? x)
               (let [prev (do (- x (- (nextprime x) x)))]
                 (and (prime? prev) (= (nextprime prev) x)))
               false)
             false)))


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
hak  
View profile  
 More options Oct 5 2012, 4:27 am
From: hak <hkue...@googlemail.com>
Date: Fri, 5 Oct 2012 01:27:07 -0700 (PDT)
Local: Fri, Oct 5 2012 4:27 am
Subject: Re: 116 Prime Sandwich times out

java functions, like Math/sqrt will kill the performance on 4clojure
replace (+ 1 (int (Math/sqrt n))) with n and it will work

Am Donnerstag, 4. Oktober 2012 19:17:05 UTC+2 schrieb Jim Altieri:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »