This file contains hidden or 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 Control.Monad.State.Lazy | |
import System.Random | |
import RemoveAt | |
choose = do | |
(gen, xs) <- get | |
let (idx, gen') = randomR (1, length xs) gen | |
let (val, xs') = removeAt idx xs | |
put (gen', xs') | |
return val |
This file contains hidden or 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
wallet | |
class Edge { | |
order: { | |
placed: false, | |
place: async function() { | |
... | |
this.placed = true | |
orderid = await cctx.placeOrder() | |
do { |
This file contains hidden or 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 Id a = Id a | |
deriving (Show) | |
instance Functor Id where | |
fmap f (Id a) = Id $ f a | |
instance Applicative Id where | |
pure = Id | |
(Id f) <*> (Id a) = Id (f a) |
This file contains hidden or 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
axios = require('axios') | |
function main() { | |
writeToConsole() | |
makeHttpRequest() | |
} | |
async function writeToConsole() { | |
while (true) { | |
console.log('lol') |
This file contains hidden or 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 Control.Monad | |
import Data.Key | |
import qualified Data.Map as Map | |
memoizedPrimeFactors :: Int -> Map.Map Int Int | |
memoizedPrimeFactors = (map primeFactors [0..] !!) | |
where primeFactors :: Int -> Map.Map Int Int | |
primeFactors 1 = Map.empty | |
primeFactors n = Map.insertWith (+) p 1 ps | |
where |
This file contains hidden or 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
split :: [a] -> [[a]] | |
split xs = f ([], []) xs | |
where f :: ([a], [[a]]) -> [a] -> [[a]] | |
f (seen, acc) [] = acc | |
f (seen, acc) (x:xs) = f (seen ++ [x], acc ++ [x:(seen ++ xs)]) xs | |
perms :: [a] -> [[a]] | |
perms [] = [[]] | |
perms xs = foldl f [] $ split xs | |
where f :: [[a]] -> [a] -> [[a]] |
This file contains hidden or 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 | |
perms :: Eq a => [a] -> [[a]] | |
perms [] = [[]] | |
perms s = do | |
x <- s | |
xs <- perms $ delete x s | |
return (x:xs) | |
main = print $ perms "abc" |
This file contains hidden or 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 Control.Monad (guard) | |
triplets :: [[Int]] | |
triplets = do | |
a <- [1..998] | |
b <- [a+1..998] | |
let c = 1000 - a - b | |
guard $ a^2 + b^2 == c^2 | |
return [a, b, c] |
This file contains hidden or 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 math | |
import bigfloat | |
from bigfloat import BigFloat, precision | |
MAX_MU = 50 | |
def choose(n,r): | |
f = math.factorial | |
return f(n) // f(r) // f(n-r) |
This file contains hidden or 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
count_parens s = fst $ foldl cnt (0, [0]) s | |
where cnt (i, acc) '(' = (i, 0:acc) | |
cnt (i, [x]) ')' = (i, [0]) | |
cnt (i, a:b:bs) ')' = (i + b + 1, (b + 1):bs) | |
main = print $ count_parens "(())()" |