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 re | |
| def repl_map(xs, ys, none='', take=0): | |
| mapping = dict(zip(xs, ys)) | |
| def f(matchobj): | |
| item = matchobj.group(take) | |
| return mapping.get(item, none) | |
| return f | |
| def replace_pipe(script, replacements): |
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
| {- 1 -} | |
| myFst :: (a, b) -> a | |
| myFst (a, b) = a | |
| {- 2 -} | |
| myOdd :: Int -> Bool | |
| myOdd = (== 1) . flip mod 2 |
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.Char (ord, chr) | |
| import Data.List | |
| import Data.Function (on) | |
| encode :: Int -> String -> String | |
| encode n = map (shift n) | |
| decode :: String -> (String, Int) | |
| decode = aarrr mkPair (flip minimumBy [0..25] . compareOnDiff . count) | |
| where aarrr f g x = f x $ g x |
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
| goldbach :: Int -> Maybe (Int, Int) | |
| goldbach = listToMaybe . goldbachFull | |
| where listToMaybe = foldr (const . Just) Nothing | |
| goldbachFull :: Int -> [(Int, Int)] | |
| goldbachFull n = mkPairs . filter isNegPrime . takeHalfN $ primes | |
| where mkPairs = map (\p -> (p, n-p)) | |
| isNegPrime p = isPrime (n - p) | |
| takeHalfN = takeWhile (\p -> p*2 <= n) |
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 | |
| histogram :: [Int] -> String | |
| histogram = unlines . reverse . putNumber . transpose . mkLines | |
| where putNumber = ("0123456789" :) . ("==========" :) | |
| mkLines :: [Int] -> [String] | |
| mkLines = graph . group . sort . ([0..9] ++) | |
| graph :: [[Int]] -> [String] |
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
| nub :: [Int] -> [Int] | |
| nub [] = [] | |
| nub (x:xs) = x:(nub $ filter (/= x) xs) |
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 enum | |
| FULL_LINE_COMMENT = ';' | |
| class CHAR(enum.Enum): | |
| LEFT = 1 | |
| RIGHT = 2 | |
| SYMBOL = 3 | |
| DIGIT = 4 | |
| SPACE = 5 |
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
| function mkInfFuncToggle(func) { | |
| var X = { x : 0 }; | |
| function infFunc() { | |
| func(); | |
| if (X.x) { setTimeout(infFunc, 1); } | |
| } | |
| function infFuncToggle() { | |
| if (X.x) { X.x = 0; } | |
| else { | |
| X.x = 1; |
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
| def Fibonacci(length) : | |
| a, b = 1, 1 | |
| for _ in range(length) : | |
| yield a | |
| a, b = b, a + b |