This file contains 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
<?php | |
function texfilter($text){ | |
//text mode matches | |
$s[] = '/\\\\begin{theorem}\\[(.*?)\\]\\s/'; | |
$r[] = '<blockquote class="theorem"><strong>Theorem ($1)</strong> '; | |
$s[] = '/\\\\begin{lemma}\\[(.*?)\\]\\s/'; | |
$r[] = '<blockquote class="theorem"><strong>Lemma ($1)</strong> '; | |
$s[] = '/\\\\begin{problem}\\[(.*?)\\]\\s/'; | |
$r[] = '<blockquote class="problem"><strong>Problem ($1)</strong> '; | |
$s[] = '/\\\\begin{corollary}\\[(.*?)\\]\\s/'; |
This file contains 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
:Namespace Problem1 | |
⎕IO ⎕ML ⎕WX ⎕RL←1 0 0 1093457855 | |
adjacency←{ | |
a←(⍺[;1]⍳⍵) ⍝ edge indexed by numbers | |
mat←(2⍴(⍴⍺[;1]))⍴0 ⍝ create a empty matrix | |
mat[↓a⍪⌽a]←1 ⍝ set adjacent edges to 1 | |
mat | |
} |
This file contains 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 | |
rec :: Num a => [a] -> [a] -> [Int] -> [a] | |
rec c b m = a | |
where a = c++rest | |
rest = next [] 0 m | |
next xs k (m:ms) | |
| k == m = next (a:xs) k ms | |
| otherwise = val ++ next (map tail xs) (k+1) (m:ms) | |
where val = if (k<length c) then [] else [sum $ zipWith (*) (reverse (map head xs)) b] |
This file contains 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
integers = 0 : concat [[x,(-x)] | x <- [1..]] | |
generalizedPentagonalNumbers = [(3 * n^2 - n) `div` 2|n<-integers] | |
partitionNumbers = rec [1] (cycle [1,1,-1,-1]) (tail generalizedPentagonalNumbers) |
This file contains 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 cgi | |
form = cgi.FieldStorage() | |
# Create the "head" of our web page | |
print "Content-type: text/html" | |
print """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> |
This file contains 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 java.io.*; | |
import java.util.*; | |
public class Flushing { | |
int[] payment; //what each person must pay | |
int[][] c; //ith person have c[i][j] number of d[j] coins | |
int[] d = {1,5,10,20}; //the value of coins can take. It is assumed the denominator are sorted | |
int[] capacity; //sum of each person's coins*denominator - payment | |
int n; //number of people; | |
public int[][] put; |
This file contains 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
package FlushingCoin; | |
import java.util.ArrayList; | |
import java.util.*; | |
public class Coins { | |
int[] d; | |
int[] c; | |
int[][] k; | |
int[][] x; |
This file contains 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.Array | |
lcs :: String -> String -> Int | |
lcs s t = a!(n,m) | |
where a = array ((0,0),(n,m)) [((x,y), f x y)|x<-[0..n],y<-[0..m]] | |
n = length s | |
m = length t | |
s'= array (0,n-1) $ zip [0..n-1] s | |
t'= array (0,m-1) $ zip [0..m-1] t | |
f :: Int->Int->Int | |
f i j |
This file contains 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
--ST Monad instead! | |
lcs :: (Eq a) => [a] -> [a] -> [a] | |
lcs s' t' = reverse $ build n m | |
where | |
a = runST $ do | |
b <- newArray ((0,0),(n,m)) 0 | |
mapM_ (f b) $ range ((0,0),(n,m)) | |
unsafeFreeze b | |
n = length s' | |
m = length t' |
This file contains 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 | |
spiral xs = (take (n*m) . concat . concat . transpose) $ zipWith (build . ($ xs)) f v | |
where f = [id, init . reverse . transpose . tail, map (reverse . init) . reverse, map reverse . transpose . init] | |
v = [n,m-1,n-1,m-2] | |
n = length (head xs) | |
m = length xs | |
build s t = zipWith (\x l-> take (t-2*x) . drop x $ l) [0..] s |