Skip to content

Instantly share code, notes, and snippets.

// assume that coins is an array of positive integers
// assume that amount is non-negative
function minCoinChange(coins, amount) {
// create an array to hold the minimum number of coins to make each amount
// amount + 1 so that you will have indices from 0 to amount in the array
const minCoins = new Array(amount + 1).fill(Infinity);
// there are 0 ways to make amount 0 with positive coin values
minCoins[0] = 0;
// look at one coin at a time
@simion
simion / base_command.py
Created October 18, 2016 14:52
Django management command - multiprocessing helper
import multiprocessing
from django.core.management import BaseCommand
def multiprocess_func(view_func):
""" Decoratior which closes database connection before running wrapped function.
Also unpacks args for multiprocessing module. """
def _decorator(args):
connection.close()
@conrjac
conrjac / Split string
Created April 15, 2013 11:12
C++ Split String and store in vector
int main()
{
std::string input = "abc,def,ghi";
std::istringstream ss(input);
std::string token;
vector<string> playerInfoVector;
while(std::getline(ss, token, ',')) {
playerInfoVector.push_back(token);
std::cout << token << '\n';