Skip to content

Instantly share code, notes, and snippets.

@oskimura
oskimura / g.hs
Created April 13, 2011 08:45
差分抽出
g (x:xs) (y:ys)
| x==y = g xs ys
| otherwise = (y:ys)
g [] ys = ys
g _ [] = []
g [] [] = []
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math#-}
{-# OPTIONS_GHC -funbox-strict-fields -fexcess-precision -monly-3-regs #-}
{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
module Main where
import Control.Applicative
import Data.List
import Data.Function (on)
import Text.Printf
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math#-}
{-# OPTIONS_GHC -funbox-strict-fields -fexcess-precision -monly-3-regs #-}
{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
module Main where
import Control.Applicative
import Data.List
import Data.Function (on)
import Text.Printf
module Lcs where
import Data.Array
makeTable xs ys = tbl
where
n = length xs
m = length ys
tbl :: Array (Int,Int) Integer
tbl = array ((0,0),(n,m)) [let x = if (xs!!(i-1)) == (ys!!(j-1)) then 1 else 0
module LevenshteinDistance where
import Data.Array
levenshteinDistance xs ys = tbl!(n,m)
where
n = length xs
m = length ys
tbl = listArray ((0,0),(n,m)) [ let x = if xs!!(i-1) == ys!!(j-1) then 0 else 1
in
if i==0 then j
trace a b = unsafePerformIO $ print a >> return b
@oskimura
oskimura / BDepression.hs
Created April 20, 2011 03:43
Haskellだと小数点のmodをとるのが大変
module Main where
import Control.Applicative
import Data.List
import Data.Maybe
import Data.Function (on)
import Text.Printf
splitBy :: (a -> Bool) -> [a] -> [[a]]
splitBy p [] = []
splitBy p xs = a : (splitBy p $ dropWhile p $ b)
module Main where
import Control.Applicative
import Data.List
import Data.Maybe
import Data.Function (on)
import Text.Printf
splitBy :: (a -> Bool) -> [a] -> [[a]]
splitBy p [] = []
splitBy p xs = a : (splitBy p $ dropWhile p $ b)
@oskimura
oskimura / gist:943704
Created April 27, 2011 04:18
BMakeitSmooth.hs
{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -cpp #-}
module Main where
import Data.List (zipWith4, foldl', genericLength)
import Control.Monad
import Data.Array
import Control.Applicative
import Text.Printf
applyDP edits edge xs y = applyDP'
where
@oskimura
oskimura / BMakeitSmooth.hs
Created April 27, 2011 04:19
BMakeitSmooth.hs
{-# OPTIONS_GHC -O2 -optc-O3 -optc-ffast-math -cpp #-}
module Main where
import Data.List (zipWith4, foldl', genericLength)
import Control.Monad
import Data.Array
import Control.Applicative
import Text.Printf
applyDP edits edge xs y = applyDP'
where