Instantly share code, notes, and snippets.

# Sinha, Ujjawal Sinha-Ujjawal

Last active May 24, 2023 16:04
Subset Sum using mknapsack library
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:
Last active October 23, 2022 14:59
Either type in Python
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)
Created September 25, 2022 07:47
SK Combinators (Building blocks for all pure functions)
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
Last active September 25, 2022 08:15
Linked List Definition In Python Using SKI Combinators
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)
Created September 10, 2022 13:20
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'
Created September 10, 2022 13:19
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
Created September 10, 2022 13:18