Skip to content

Instantly share code, notes, and snippets.

@yusuketanabe
yusuketanabe / feb28.cpp
Last active March 1, 2022 04:04
Recursive function memo at ATC001. Depth First Search(深さ優先探索)
#include <iostream>
#include <vector>
/*
DFS: depth-first search
1
/|\
2 7 8
/ \ | \
3 6 9 12
@yusuketanabe
yusuketanabe / feb7-2.cpp
Last active February 7, 2022 03:35
Recursive function memo
#include <iostream>
#include <vector>
// dataのi番目以降の要素を逆順にした配列を返す
std::vector<int> reverse_array_from_i(std::vector<int> &data, int i) {
// Base
if (i == data.size()) {
std::vector<int> empty_array(0); // 要素数0の配列。0なので出力されない。試しに1とか入れてみて。出力されるから。
return empty_array;
/*
@yusuketanabe
yusuketanabe / feb7.cpp
Last active February 7, 2022 03:34
Recursive function memo
#include <iostream>
// Auxiliary functions of is_prime
bool has_divisor(int N, int i) {
// Base
// 0ならば対象の整数がないまたは、i == Nなら自分(と1)以外約数が存在しない。
if (i == N) return false;
// i~N-1までの範囲で約数が存在する。
if (N % i == 0) return true;
// Recursive
@yusuketanabe
yusuketanabe / feb2-2.cpp
Created February 2, 2022 03:23
Recursive function memo
#include <iostream>
#include <vector>
// Sum of array elements
// sum of [i, i+1] = [i] + [i+1]
int array_sum_from_i(std::vector<int> &data, int i) {
// Base
if (i == data.size()) return 0;
// Recursive
int s = array_sum_from_i(data, i+1);
@yusuketanabe
yusuketanabe / feb2.cpp
Last active March 1, 2022 04:08
Recursive function memo
#include <iostream>
// a <= b
int sum_range(int a, int b) {
// Base
if (a == b) return a;
// Recursive
return a + sum_range(a+1, b);
// or return b + sum_range(a, b-1);
}
@yusuketanabe
yusuketanabe / 0_ethclient.go
Created October 23, 2021 06:43
Ethereum Client Sample
package main
import (
"context"
"fmt"
"log"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
)
@yusuketanabe
yusuketanabe / 0_reuse_code.js
Created January 14, 2016 02:52
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console