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 <iomanip> | |
#include <vector> | |
#include <sstream> | |
#include <memory> | |
#include <cmath> | |
using namespace std; | |
const double PI = 3.14; |
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
require 'json' | |
module SerializableStruct | |
class Dummy | |
def self.members | |
@members | |
end | |
def initialize(*vals) | |
vals.each_with_index do |val, idx| |
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 <map> | |
#include <utility> | |
#include <vector> | |
using namespace std; | |
template <typename T> | |
T Sqr(T x) { | |
return x * x; |
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 <sstream> | |
#include <cmath> | |
#include <map> | |
#include <vector> | |
#include <set> | |
using namespace std; | |
class Rational { |
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
/** | |
* Constructor DependencyInjector | |
* @param {Object} - object with dependencies | |
*/ | |
var DI = function (dependency) { | |
this.dependency = dependency; | |
}; | |
// Should return new function with resolved dependencies | |
DI.prototype.inject = function (func) { |
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
const cartesian = (...arrays) => arrays.reduce((cartesianPart, array) => ( | |
[].concat(... | |
cartesianPart.map(cartesianPartTuple => | |
array.map(it => cartesianPartTuple.concat(it)) | |
) | |
) | |
), [[]]); | |
console.log(cartesian([1,2], [3,4], [5,6])) |
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
function flatten(arr) { | |
return arr.reduce((acc, it) => | |
acc.concat((it instanceof Array) ? flatten(it) : it) | |
, []) | |
} | |
flatten([[[1, [1.1]], 2, 3], [4, 5]]); |
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
class Graph { | |
constructor() { | |
this.adjList = new Map(); | |
} | |
addVertex(v) { | |
this.adjList.set(v, []); | |
return this; | |
} |
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
function Node(data) { | |
this.data = data; | |
this.parent = null; | |
this.children = []; | |
} | |
function Tree(data) { | |
this._root = new Node(data); | |
} |
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
class Queue { | |
constructor() { | |
this.items = []; | |
} | |
enqueue(obj) { | |
this.items.push(obj); | |
} | |
dequeue() { |
NewerOlder