Skip to content

Instantly share code, notes, and snippets.

@Mirey-zz
Mirey-zz / main.go
Last active October 24, 2017 07:34
A Brute force solution to the knapsack problem
package main
import (
"flag"
"fmt"
"io/ioutil"
"math"
"strconv"
"strings"
"sync"
class Node(object):
def __init__(s):
s.edges = {}
s.term = False
def insert(s, w):
s.term = not w or s.edges.setdefault(w[0], Node()).insert(w[1:]) or s.term
def exists(s, w):
return s.term if not w else w[0] in s.edges and s.edges[w[0]].exists(w[1:])