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
| [tool.poetry] | |
| name = "tmpdir2" | |
| version = "0.1.0" | |
| description = "" | |
| authors = ["Adam Smith <my@email.com>"] | |
| [tool.poetry.dependencies] | |
| python = "^3.7" | |
| [tool.poetry.dev-dependencies] |
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 collections | |
| def rps(*choices): | |
| """choices must be in order so that each proceeding element defeats its neighbor. | |
| Returns a function that takes two members of choices and decides which one would win in that RPS game. | |
| rps("rock", "paper", "scissors") or rps("paper", "scissors", "rock"), but never rps("scissors", "paper", "rock") | |
| """ | |
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 combine_dicts(a, b, *, op=lambda x: x, default=None): | |
| result = {} | |
| for k, va in a.items(): | |
| vb = b.get(k, default) | |
| result[k] = op(va, vb) | |
| return result |
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
| everyOther :: [a] -> [a] | |
| everyOther xs = [v | (k,v) <- zip (cycle [True, False]) xs, k] | |
| betweenAF :: String -> Bool | |
| betweenAF = all (flip elem ['a'..'f']) . everyOther |
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(isSpace) | |
| -- splitOnTest (=='x') "AxBxC" -> ["A", "B", "C"] | |
| splitOnTest :: (Char -> Bool) -> String -> [String] | |
| splitOnTest = splitOnTest' [] | |
| where splitOnTest' :: String -> (Char -> Bool) -> String -> [String] | |
| splitOnTest' acc _ [] = [(reverse acc)] | |
| splitOnTest' acc f (x:xs) | f x = [(reverse acc)] ++ splitOnTest f xs | |
| | otherwise = splitOnTest' (x:acc) f 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 Data.List.Split(splitOn) | |
| import qualified Data.Text as T | |
| parse :: String -> [Int] | |
| parse s | '-' `elem` s = expandedS | |
| | otherwise = singleS | |
| where expandedS = let (x':(y':[])) = splitOn "-" s | |
| x = read x' :: Int | |
| y = read y' :: Int | |
| in [x..y] |
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
| Name of the file: test.txt | |
| vowels: 20 | |
| consonants: 39 | |
| punctuation: 15 |
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 zlib | |
| import base64 | |
| import json | |
| import sys | |
| def flip_entity(entity): | |
| # translation tables | |
| newX = [-3,-2, 0, 2,3,2,0,-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(toUpper, toLower) | |
| alternateCase :: String -> String | |
| alternateCase [] = [] | |
| alternateCase (x:[]) = [toUpper x] | |
| alternateCase (x:y:xs) = (toUpper x):(toLower y):(alternate xs) | |
| alternateCase "abcdefg" | |
| -- "AbCdEfG" |
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 | |
| problem1 :: IO () | |
| problem1 = do | |
| input <- replicateM 3 getLine | |
| putStrLn $ show . sum . map (read :: String -> Int) $ input | |
| problem2 :: IO () | |
| problem2 = do | |
| input <- replicateM 2 getLine |
NewerOlder