Skip to content

Instantly share code, notes, and snippets.

View banacorn's full-sized avatar
🥺

Ting-gian LUA banacorn

🥺
View GitHub Profile

Ring

Chain of class inclusions

Rings ⊃ Commutative rings ⊃ ID ⊃ UFD ⊃ PID ⊃ ED ⊃ Field

Prime

if a | bc then a | b or a | c, i.e. a can't be torn apart if a is prime

import Control.Monad (forM_)
import Control.Monad.ST (runST)
import Data.IORef
import Data.STRef
-- dirty, can't get rid of IO
sumIO :: [Int] -> IO Int
sumIO xs = do
acc <- newIORef 0
forM_ xs (modifyIORef acc . (+))
maximum :: Ord a => [a] -> a
maximum = foldr max (-∞)
module BatBunker where
import Data.List (findIndices, delete, (\\))
import Data.Ratio
data Cell = Empty | Wall | Bat | AlphaBat deriving (Show, Eq)
type Map = [[Cell]]
type Coord = (Int, Int)
type Vertex = (Cell, Coord)
# confidence from 0% to 100%
cat data/1m | time ./dist/build/homework2-hs/homework2-hs 0.0010 0 100 +RTS -K2000m -H500m -RTS
4.48 real 3.85 user 0.34 sys
cat data/1m | time ./dist/build/homework2-hs/homework2-hs 0.0010 0.1 100 +RTS -K2000m -H500m -RTS
3.96 real 3.59 user 0.32 sys
cat data/1m | time ./dist/build/homework2-hs/homework2-hs 0.0010 0.2 100 +RTS -K2000m -H500m -RTS
3.92 real 3.57 user 0.31 sys
cat data/1m | time ./dist/build/homework2-hs/homework2-hs 0.0010 0.3 100 +RTS -K2000m -H500m -RTS
3.97 real 3.60 user 0.33 sys
批踢踢實業坊›看板 Gossiping
作者Machinator (\⊙▽⊙/)
看板Gossiping
標題[爆卦] 從近期的抗爭談些社會意識的錯誤
時間Mon Apr 14 22:09:04 2014
錯誤一:「警察是無辜的,要找就找後面下令的人。」
複製貼上故事:
test 測試 \n\r <123>
@banacorn
banacorn / catamorphism.hs
Created December 17, 2013 18:45
some algebra shit
module Catamorphism where
import Prelude hiding (sum)
data Mu f = InF { outF :: f (Mu f) }
catamorphism :: Functor f => (f a -> a) -> Mu f -> a
catamorphism f = f . fmap (catamorphism f) . outF
--------------------------------------------------

Group

  • Closed
  • Associative
  • Identity
  • Inverse

Subgroup

Definition

{-# LANGUAGE OverloadedStrings #-}
import Web.Scotty
import Network.Wai (requestHeaders, pathInfo)
import Data.Text (intercalate, unpack)
import Data.Text.Encoding (decodeUtf8)
import Data.Text.Lazy (fromStrict)
import Network.Mime (defaultMimeLookup)
import Control.Applicative ((<$>))
import Control.Monad.Trans (liftIO)