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
import numpy as np | |
from mknapsack import solve_subset_sum | |
def subset_sum(*, weights: np.array, capacity: float) -> np.array: | |
assert capacity > 0, f"Capacity must be positive!, given: {capacity}" | |
n_weights = len(weights) | |
if n_weights < 2: |
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
from typing import Generic, Tuple, TypeVar, Iterable, List, Optional, Any, Union | |
L = TypeVar("L") | |
R = TypeVar("R") | |
# SKI+ Combinators | |
S = lambda f: lambda g: lambda x: f(x)(g(x)) | |
K = lambda x: lambda y: x | |
I = S(K)(K(K)) | |
KI = K(I) |
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
from typing import Generic, Tuple, TypeVar, Iterable, List, Optional, Any | |
L = TypeVar("L") | |
R = TypeVar("R") | |
# SKI+ Combinators | |
S = lambda f: lambda g: lambda x: f(x)(g(x)) | |
K = lambda x: lambda y: x | |
I = S(K)(K(K)) | |
KI = K(I) |
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
S = lambda f: lambda g: lambda x: f(x)(g(x)) | |
K = lambda x: lambda y: 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
class Bifunctor f where | |
bimap :: (a -> a') -> (b -> b') -> f a b -> f a' b' |
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 Either a b = Left a | Right b | |
-- Implicit functions | |
-- Left :: a -> Either a b | |
-- Right :: b -> Either a b |
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 Pair a b = Pair a b | |
fst :: Pair a b -> a | |
fst (Pair a _) = a | |
snd :: Pair a b -> b | |
snd (Pair _ b) = b |
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
{-# LANGUAGE ScopedTypeVariables #-} | |
import Prelude (IO, pure, print, String, Bool(True, False), Int, Show) | |
(.) :: (b -> c) -> (a -> b) -> (a -> c) | |
g . f = \x -> g (f x) | |
($) :: (x -> y) -> x -> y | |
f $ x = f x | |
id :: a -> a |
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
-- This is a starter contract, based on the Game contract, | |
-- containing the bare minimum required scaffolding. | |
-- | |
-- What you should change to something more suitable for | |
-- your use case: | |
-- * The MyDatum type | |
-- * The MyMyRedeemerValue type | |
-- | |
-- And add function implementations (and rename them to | |
-- something suitable) for the endpoints: |