Skip to content

Instantly share code, notes, and snippets.

View nikhedonia's full-sized avatar
💭
actively open-sourcing

Gaetano Checinski nikhedonia

💭
actively open-sourcing
View GitHub Profile
double golden(double epsilon=0.00001) {
int a = 0;
int b = 1;
double ratio = 0;
while (1) {
tie(a, b) = tuple{b, a+b};
auto delta = b / (double)a - ratio;
ratio = b / (double)a;
cout << ratio << endl;
template<class TestF class Map>
auto golden(TestF test, Map f) {
  int a = 0;
  int b = 1;
  double ratio = 1;
 
  while (1) {
  tie(a, b) = tuple{b, a+b};
  auto delta = b/(double)a - ratio;
  ratio = b/(double)a;
auto ratiosWithPrecission = []{
return zip([](auto prev, auto next){
return tuple{next, next - prev};
},
fibRatios(),
fibRatios() >> drop(1)
);
};
auto fibRatios = [] {
return fib() >> scan(1, [](auto a, auto b){
return b/(double)a;
});
};
auto fib() -> seq<int> {
  int a = 0;
  int b = 1;
 
  while (1) {
  co_yield a;
  tie(a, b) = tuple{b, a+b};
  }
}
auto ratios = []{
 return fib() >> scan(1, [](auto prev, auto next){
  return next / prev; 
  });
};
int main() {
  auto fiveFibs = fib() >> take(5); // 0, 1, 1, 2, 3
  auto ratiosTenToTwenty = ratios() 
  >> drop(1) 
double golden(double epsilon=0.00001) {
int a = 0;
int b = 1;
double ratio = 0;
while (1) {
tie(a, b) = tuple{b, a+b};
auto delta = b / (double)a - ratio;
ratio = b / (double)a;
if ( abs(delta) < epsilon )
def merge_dicts(x, y):
z = x.copy()
z.update(y)
return z
cxx_library(
name = "python3.8m",
header_namespace= '',
compiler_flags = ["-fwrapv"],
auto fibonacci = []() -> seq<unsigned long long> {
auto a = 0ll;
auto b = 1ll;
while (true) {
co_yield a;
tie(a, b) = tuple{a + b, a};
}
};
#include <type_traits>
namespace conduit {
template <class T>
T id(T const& x) {
return x;
}
template <class T>
auto first(T&& xs) -> decltype(id(*xs.begin())) {
return *xs.begin();
}