Skip to content

Instantly share code, notes, and snippets.

View Cornpop456's full-sized avatar
🎯
Focusing

Victor Ginzburg Cornpop456

🎯
Focusing
View GitHub Profile
#include <iostream>
#include <string>
using namespace std;
int main()
{
string line;
getline(cin, line);
function reduce(array, fn, initial) {
if (!(array instanceof Array)) {
throw new TypeError('Illegal first argument, (not an array)');
} else if (!(fn instanceof Function)) {
throw new TypeError('Illegal second argument, (not a function)');
}
let startIndex = 1,
current = array[0];
data Tree a = Leaf | Node (Tree a) a (Tree a) deriving (Show, Eq)
treeTest :: Tree Integer
treeTest = Node (Node Leaf 5 (Node Leaf 4 Leaf)) 10 (Node Leaf 20 (Node Leaf 50 (Node Leaf 100 Leaf)))
treeSum :: Tree Integer -> Integer
treeSum tree | tree == Leaf = error "Empty tree!"
| otherwise = helper 0 tree where
helper acc (Node f d s) | (f == Leaf && s == Leaf) = acc + d
| (f /= Leaf && s /= Leaf) = (helper (acc + d) f) + (helper acc s)
def fib(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fib(n - 1) + fib(n - 2)
def wrapper(func):
cache = {}
@Cornpop456
Cornpop456 / fib.go
Created March 30, 2017 16:20
Memoiz fibonaci
package main
import "fmt"
type memoizeFunction func(int) interface{}
func fibonacci(n int) interface{} {
if n == 0 {