This file contains hidden or 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
def sum_arithmetic_series(n): | |
return n*(n+1)/2.0 | |
def missing_one(upto,missing_one): | |
return sum_arithmetic_series(upto) - sum(missing_one) |
This file contains hidden or 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
def nth_prime(n): | |
i = 2 | |
prime_count = 0 | |
while True: | |
if is_prime(i): | |
if prime_count == n: | |
return i | |
prime_count += 1 | |
if i == 2: | |
i += 1 |
This file contains hidden or 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
def naive_is_prime(n): | |
if n <= 1: | |
return False | |
if n == 2: | |
return True | |
if n % 2 == 0: | |
return False | |
for i in xrange(3,n): | |
if n % i == 0: | |
return False |
This file contains hidden or 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
(import '(java.io BufferedReader InputStreamReader FileReader File BufferedWriter FileWriter)) | |
(defn cmd [p] (.. Runtime getRuntime (exec (str p)))) | |
(defn cmdout [o] | |
(let [r (BufferedReader. | |
(InputStreamReader. | |
(.getInputStream o)))] | |
(dorun (map println (line-seq r))))) |
This file contains hidden or 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
(defn mark-up [tag-name value] | |
(str "<" tag-name ">" value "</" tag-name ">")) | |
(defn xmlify [names fields] | |
(reduce str (map #(mark-up %1 %2) names fields))) | |
;;will work, but ugly... makes each html element | |
(?<- (stdout) [?p ?xml-name ?xml-age ?xml-gender] (age ?p ?a) (gender ?p ?g)(mark-up "name" ?p :> ?xml-name) (mark-up "age" ?a :> ?xml-age)(mark-up "gender" ?g :> ?xml-gender)) | |
NewerOlder