Skip to content

Instantly share code, notes, and snippets.

View chaoxu's full-sized avatar
😀

Chao Xu chaoxu

😀
  • University of Electronic Science and Technology of China
  • Chengdu, Sichuan, China
View GitHub Profile
@chaoxu
chaoxu / word_problem_braid_group.hs
Created June 23, 2011 05:54
Word Problem for Braid Group
default (Int, Integer, Rational, Double)
if' :: Bool -> a -> a -> a
if' True x _ = x
if' False _ y = y
isBraidIdentity x n =
[1..n] == concat (map (braidReduce x) [[y] | y <- [1..n]])
braidReduce = flip (foldr homomorphism)
@chaoxu
chaoxu / yotta.py
Last active July 21, 2020 02:21
Yotta quantiles
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
import math
N = 400 # number of tickets
i = 100000 # number of trials
k = 52 # number of weeks
rate = 0.002 # standard apr
@chaoxu
chaoxu / VCG.md
Last active April 8, 2020 15:48
关于Visa GC

这么多GC里面最强力的GC应该是Visa GC了(同理还有Mastercard和amex的, 但是比较少见, 用起来差不多). Visa GC (VGC)会有不同的银行发行.

让p%为你的最强任意地方返现卡. 相信大多人这张卡是下面3个

  • 各种类似的2%返现卡.
  • Chase freedom unlimited, 1.5 UR, 价值2.25%.
  • Citi double cash, 可以转换成 2 TYP, 价值2.5%.
  • Amex blue business plus 2 MR 价值2.5% (上限是一年50k spend, 普通人应该用不完).
  • BoA premium + platinum honors 是2.625%.
@chaoxu
chaoxu / chao.sty
Last active August 21, 2019 06:44
the sty file I always include.
% ========================-*- LaTeX -*-=========================
%
% chao.sty -- modified from jeffe.sty
% jeffe.sty can be found at http://web.engr.illinois.edu/~jeffe/pubs/latex.html
%
% ==========================================================
\RequirePackage{latexsym,amsmath}
\RequirePackage[dvipsnames,usenames]{xcolor}
%\PassOptionsToPackage{hyphens}{url}
import java.util.*;
class PLC{
public TreeMap<Integer, Integer> segmentlist = new TreeMap<Integer, Integer>();
public int upperBound = 0;
public int lastSlope = 0;
public int startValue = 0;
public int shift = 0;
private static int INF = 100000000;
private int lb() {
\begin{itemize}
\item Tree reconstruction from inorder and postorder.
\item find path sum in the tree \url{https://leetcode.com/problems/path-sum-ii/}
\item longest substring without repeated character. \url{https://leetcode.com/problems/longest-substring-without-repeating-characters/}
\item Longest Palindromic Substring \url{https://leetcode.com/problems/longest-palindromic-substring/}
\item Container With Most Water \url{https://leetcode.com/problems/container-with-most-water/solution/}
\item 3sum, 4sum, ksum
\item next permutation \url{https://leetcode.com/problems/next-permutation/}
\item Permutation generation \url{https://leetcode.com/problems/permutations-ii/}
\item Group Anagrams \url{https://leetcode.com/problems/group-anagrams/}
\begin{itemize}
\item Tree reconstruction from inorder and postorder.
\item find path sum in the tree \url{https://leetcode.com/problems/path-sum-ii/}
\item longest substring without repeated character. \url{https://leetcode.com/problems/longest-substring-without-repeating-characters/}
\item Longest Palindromic Substring \url{https://leetcode.com/problems/longest-palindromic-substring/}
\item Container With Most Water \url{https://leetcode.com/problems/container-with-most-water/solution/}
\item 3sum, 4sum, ksum
\item next permutation \url{https://leetcode.com/problems/next-permutation/}
\item Permutation generation \url{https://leetcode.com/problems/permutations-ii/}
\item Group Anagrams \url{https://leetcode.com/problems/group-anagrams/}
@chaoxu
chaoxu / MatrixRankSelection.hs
Created January 31, 2019 07:10
Matrix Rank Selection
import Data.List
import Control.Applicative
import Control.Arrow
import Control.Monad
import RankSelection
-- this provides selectRank, which outputs the kth largest element of a list
-- selectRank :: Ord a => [a] -> Int -> a
type Matrix a = (Int->Int->a, Int, Int)
# Logic:
# a > b --> discard everything to the left of a
# a < b --> discard everything to the right of b
# a = b = c --> we know that either
# a) all elements between a and b are all equal to b, or
# b) all elements between b and c are all equal to b.
# time for a linear search.
def minvalley(xs, l, r):
while True: