Skip to content

Instantly share code, notes, and snippets.

@tkuriyama
tkuriyama / LC_Password_Fragment.py
Last active September 9, 2020 21:48
Leetcode Strong Password Fragment (Incomplete)
from re import findall
def has_digit(s:str) -> bool:
return any(c.isdigit() for c in s)
def has_upper(s:str) -> bool:
return any(c.isupper() for c in s)
def has_lower(s:str) -> bool:
return any(c.islower() for c in s)
@tkuriyama
tkuriyama / BoolMonoid.hs
Created September 2, 2020 14:29
Study group progress on Bool Monoid
-- {-# LANGUAGE FlexibleInstances, FlexibleContexts #-}
import Data.Monoid
data Bool' = True' | False'
deriving (Show, Ord, Eq)
(and') = (&&)
(or') = (||)
@tkuriyama
tkuriyama / cis_194_hw7.hs
Last active September 8, 2020 17:18
CIS 194 HW7
{-# LANGUAGE FlexibleInstances, TypeSynonymInstances #-}
module JoinList where
import Data.Monoid
import Control.Applicative
-- import qualified Foldable as F
import Buffer
import Sized
import Scrabble
@tkuriyama
tkuriyama / cis_104_hw6.hs
Last active August 31, 2020 13:52
CIS194 HW6
{-# LANGUAGE FlexibleInstances #-}
{-# OPTIONS_GHC -fno-warn-missing-methods #-}
module Fibonacci where
-- Exercise 1
fib :: Integer -> Integer
fib 0 = 0
fib 1 = 1
@tkuriyama
tkuriyama / cis194_hw5.hs
Created August 27, 2020 17:17
CIS 194 HW5
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
module Calc where
import qualified Data.Map as M
import ExprT
import Parser
import qualified StackVM as VM
import Data.Maybe
@tkuriyama
tkuriyama / cos194_hw4.hs
Last active August 25, 2020 14:41
CIS 194 HW4
-- Exercise 1
fun1 :: [Integer] -> Integer
fun1 [] = 1
fun1 (x:xs)
| even x = (x - 2) * fun1 xs
| otherwise = fun1 xs
fun1' :: [Integer] -> Integer
@tkuriyama
tkuriyama / cis194_hw3_pairing.hs
Last active August 21, 2020 14:57
CIS194 HW3 Pair Programming
import Data.List (nub, sort)
-- Local Maxima
localMaxima :: [Integer] -> [Integer]
localMaxima (x:y:z:zs)
| y > x && y > z = y : localMaxima (z:zs)
| otherwise = localMaxima (y:z:zs)
localMaxima _ = []
@tkuriyama
tkuriyama / cis194_hw3.hs
Created August 19, 2020 14:57
CIS 194 HW3
module Golf where
import Data.List
import qualified Data.Map.Strict as Map
-- Skips
everyN :: Int -> [a] -> [a]
everyN n xs = case drop (n-1) xs of
(y:ys) -> y : (everyN n ys)
@tkuriyama
tkuriyama / cis194_hw2.hs
Created August 18, 2020 15:03
CIS 194 HW2
{-# OPTIONS_GHC -Wall #-}
module LogAnalysis where
import Text.Read (readMaybe)
import Log
rmInt :: String -> Maybe Int
rmInt = readMaybe
rmTime :: String -> Maybe TimeStamp
@tkuriyama
tkuriyama / cis194_hw1.hs
Created August 17, 2020 12:57
CIS 194 HW1
-- Credit Cards
toDigitsRev :: Integer -> [Integer]
toDigitsRev 0 = []
toDigitsRev n = (n `mod` 10) : toDigitsRev (n `div` 10)
toDigits :: Integer -> [Integer]
toDigits = reverse . toDigitsRev
doubleEveryOther :: [Integer] -> [Integer]