Skip to content

Instantly share code, notes, and snippets.

View marionette-of-u's full-sized avatar

arithmeticae marionette-of-u

View GitHub Profile
(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"
(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
(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)] [])
#include <memory>
#include <utility>
#include <iostream>
#include <gmpxx.h>
namespace cmpxx{
namespace aux{
template<class T>
struct expr_wrapper{
typedef T type;
@marionette-of-u
marionette-of-u / dfs.cpp
Created September 24, 2012 13:35
depth first search in expression template
// debug
#include <iostream>
#include <string>
#include <typeinfo>
#include <cxxabi.h>
// caution!! memory leaks!!
namespace debug{
inline std::string demangle(const std::string &str){
@marionette-of-u
marionette-of-u / binary_search_in_vector.cpp
Created November 3, 2012 11:55
binary_search_in_vector
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;
@marionette-of-u
marionette-of-u / binary_search_and_lower_bound_and_upper_bound_in_vector.cpp
Created November 7, 2012 11:01
binary_search_and_lower_bound_and_upper_bound_in_vector
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);
@marionette-of-u
marionette-of-u / gist:4239961
Created December 8, 2012 11:49
test std::thread
#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();
@marionette-of-u
marionette-of-u / m_shima2.cpp
Created December 9, 2012 03:51
m_shima2 - draft
#include <string>
#include <random>
#include <fstream>
#include <locale>
#include <vector>
#include <memory>
#include <array>
#include <functional>
#include <thread>
#include <mutex>
@marionette-of-u
marionette-of-u / gist:4405135
Created December 29, 2012 07:04
多倍精度浮動小数点数型 mpf_class において対数関数 ln(x) を求める
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;