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
| (ns org.program.main) | |
| (def fizzbuzz | |
| (map first | |
| (iterate | |
| (fn [[a b]] | |
| [(cond | |
| (= 0 (mod b 15)) "fizzbuzz" | |
| (= 0 (mod b 5)) "buzz" | |
| (= 0 (mod b 3)) "fizz" |
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
| (ns org.program.main) | |
| (defn less-vec [v n] | |
| (cond | |
| (= 0 (count v)) [] | |
| :else (let [i (first v)] | |
| (concat (if (< i n) [i] []) (less-vec (rest v) n))))) | |
| (defn greater-vec [v n] | |
| (cond |
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
| (ns org.program.main) | |
| (defn qsort [v] | |
| (cond | |
| (>= 1 (count v)) v | |
| :else (let [p (first v) | |
| r (rest v) | |
| sieve (fn self [[arg-vec cmp-fn]] | |
| (concat | |
| (if (cmp-fn (first arg-vec) p) [(first arg-vec)] []) |
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
| #include <memory> | |
| #include <utility> | |
| #include <iostream> | |
| #include <gmpxx.h> | |
| namespace cmpxx{ | |
| namespace aux{ | |
| template<class T> | |
| struct expr_wrapper{ | |
| typedef T type; |
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
| // debug | |
| #include <iostream> | |
| #include <string> | |
| #include <typeinfo> | |
| #include <cxxabi.h> | |
| // caution!! memory leaks!! | |
| namespace debug{ | |
| inline std::string demangle(const std::string &str){ |
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
| void binary_search_test(){ | |
| std::vector<double> vec = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 }; | |
| auto insert = [&](double value) -> bool{ | |
| if(vec.empty() || value < *vec.begin()){ | |
| vec.insert(vec.begin(), value); | |
| return true; | |
| }else if(*vec.rbegin() < value){ | |
| vec.insert(vec.end(), value); | |
| return true; |
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
| std::cout << "binary search\n"; | |
| { | |
| std::vector<double> vec = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0 }; | |
| auto insert = [&](double value) -> bool{ | |
| if(vec.empty() || value < *vec.begin()){ | |
| vec.insert(vec.begin(), value); | |
| return true; | |
| }else if(*vec.rbegin() < value){ | |
| vec.insert(vec.end(), value); |
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
| #include <thread> | |
| std::thread a, b; | |
| void f(); void g(); void h(); | |
| void f(){ a = std::thread(g); } | |
| void g(){ b = std::thread(h); } | |
| void h(){} | |
| int main(){ | |
| f(); | |
| a.join(); | |
| b.join(); |
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
| #include <string> | |
| #include <random> | |
| #include <fstream> | |
| #include <locale> | |
| #include <vector> | |
| #include <memory> | |
| #include <array> | |
| #include <functional> | |
| #include <thread> | |
| #include <mutex> |
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
| void mpf_ln(mpf_class &r, const mpf_class &x){ | |
| mp_bitcnt_t prec = x.get_prec(); | |
| if(x > 0.5){ | |
| mpf_class term = 1.0 - (1.0 / x), term_k = term, last = r; | |
| r = term_k; | |
| term_k *= term; | |
| r += term_k / 2.0; | |
| for(std::size_t i = 3; !mpf_eq(r.get_mpf_t(), last.get_mpf_t(), prec); ++i){ | |
| last = r; | |
| term_k *= term; |