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 main(arr): | |
arr.sort(key=lambda x: x[0]) | |
if arr: | |
stack = [arr[0]] | |
else: | |
return [] | |
for start, end in arr[1:]: | |
interval = stack[-1] |
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 HotelRank = HotelRank { idh :: Integer, rank :: Integer } deriving (Show, Eq) | |
instance Ord HotelRank where | |
compare (HotelRank i r) (HotelRank i' r') | |
| r == r' = compare i i' | |
| otherwise = if compare r r' == GT then LT else GT | |
l = [(4000, 8), (3000, 7), (2000, 8), (1000, 5), (2000, 5), (4000, 5), (3000, 2)] | |
rankings = map (\(i, r) -> (HotelRank i r)) l |
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 qualified Data.Map as M | |
amount = 18 | |
coins = [5, 4, 2, 1] | |
greedy a cs = fn a cs M.empty | |
where |
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 qualified Data.Map as M | |
l = [5, 3, 7, 0, 1, 4, 2] | |
m = M.fromList [(x,x)| x <- l] | |
searchSumInList xs s = | |
let m = M.fromList [(x,x)| x <- xs] | |
in foldl fn [] $ zip [0..] l |
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
binarySearch :: Ord a => a -> [a] -> Maybe Int | |
binarySearch s xs = let left = 0 | |
right = length xs - 1 | |
in fn left right | |
where fn l r = if l > r | |
then Nothing | |
else let m = (l + r) `div` 2 | |
e = xs !! m | |
in if e < s | |
then fn (m+1) r |
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
l = [25626, 25757, 24367, 24267, 16, 100, 2, 7277] | |
deltaEncoding :: (Ord a, Num a) => [a] -> [a] | |
deltaEncoding xs = head xs : fn (xs) | |
where fn (x:y:ys) = let n = y - x -- : fn (y:ys) | |
in if isSingleByte n | |
then n : fn (y:ys) | |
else -128 : n :fn (y:ys) | |
fn (x:[]) = [] | |
isSingleByte b = -127 <= b && b <= 127 |
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 Data.List.Split (splitOn) | |
-- polygons.txt | |
-- 36 30 36 30 | |
-- 15 15 15 15 | |
-- 46 96 90 100 | |
-- 86 86 86 86 | |
-- 100 200 100 200 | |
-- -100 200 -100 200 |
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 brute_force(arr, s): | |
for i in arr: | |
for j in arr: | |
if i + j == s: | |
print("{} + {} = {}".format(i, j, s)) | |
# brute_force([5, 3, 7, 0, 1, 4, 2], 5) |
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 Expr = Val Int | Div Expr Expr deriving Show | |
eval :: Expr -> Int | |
eval (Val x) = x | |
eval (Div x y) = eval x `div` eval y | |
safeDiv :: Int -> Int -> Maybe Int | |
safeDiv n m = if m == 0 then Nothing else Just (n `div` m) | |
safeEval :: Expr -> Maybe Int |
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
#!/usr/bin/env bash | |
cd ${HOME}/zec | |
SRV="eu1-zcash.flypool.org:3333" | |
ADDRESS="" | |
RIG=`hostname` |