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 <string> | |
using namespace std; | |
int main() | |
{ | |
string line; | |
getline(cin, line); | |
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 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]; |
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
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) |
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
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 = {} |
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 "fmt" | |
type memoizeFunction func(int) interface{} | |
func fibonacci(n int) interface{} { | |
if n == 0 { |