This file contains 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 <iostream> | |
#include <vector> | |
/* | |
DFS: depth-first search | |
1 | |
/|\ | |
2 7 8 | |
/ \ | \ | |
3 6 9 12 |
This file contains 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 <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; | |
/* |
This file contains 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 <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 |
This file contains 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 <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); |
This file contains 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 <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); | |
} |
This file contains 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
package main | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"github.com/ethereum/go-ethereum/common" | |
"github.com/ethereum/go-ethereum/ethclient" | |
) |
This file contains 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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |