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
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) 
int main () {
  int n=100;
  auto prevRatio = 0.0;
  for (auto ratio: fibRatios()) {
  cout << ratio << endl;
  auto delta =  ratio - prevRatio;
  if (n==0 || delta < 0.0001)
  break;
  prevRatio = ratio;
  n- - ;
auto fib() -> seq<int> {
  int a = 0;
  int b = 1;
 
  while (1) {
  co_yield a;
  tie(a, b) = tuple{b, a+b};
  }
}
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;
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"],
#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();
}
auto fibonacci = []() -> seq<unsigned long long> {
auto a = 0ll;
auto b = 1ll;
while (true) {
co_yield a;
tie(a, b) = tuple{a + b, a};
}
};
// Sum of the first 10 squares
auto total = squares() >> take(10) >> sum();
// Jumps between the first 10 squares
auto jumps = squares()
>> scan(0, [](auto x, auto y) { return y - x; })
>> take(10);
// The obligatory fibonacci
auto fibonacci = []() -> seq<int> {
std::vector<int> v = range()
>> take(5)
>> toVector();
// v = { 0, 1, 2, 3, 4 }