Skip to content

Instantly share code, notes, and snippets.

View VincentTam's full-sized avatar
🏀
Rolling around

Vincent Tam VincentTam

🏀
Rolling around
View GitHub Profile
@VincentTam
VincentTam / swap.py
Last active January 27, 2018 08:31
Echange "pythonique" de deux nombres
# input
a = int(input("Donner la valeur de a: "))
b = int(input("Donner la valeur de b: "))
# avant échange
print("a = ",a)
print("b = ",b)
# échange
a, b = b, a
Nvec = 10000:10000:1000000; % no of intervals
rrsumvec = zeros(size(Nvec));
for ind = 1:length(Nvec)
N = Nvec(ind);
dx = 5 / N;
x = (1:N) * dx;
fx = sqrt(25 - x.^2);
rrsum(ind) = sum(fx * dx);
end

My answer to a deleted question Interpretation of exponentation and permutation on math.SE

WayneXMayersX asked this question.

Question

I have $3^3$, can I call it a permutation/permutation with repetition?

@VincentTam
VincentTam / mydual.m
Last active February 21, 2017 09:32
My Octave dual simplex tableau generator
# Show dual simplex tableau
# Prereq: matrix A, vectors b,c, basis
printf("Current basis:"); printf(" %2i", basis); disp("");
B = A(:,basis); cB = c(basis);
Bm1A = B\A; xB = B\b; zrow = cB'*Bm1A-c'; zval = cB'*xB;
if length(xB(xB<0)) >= 1
ovp = find(xB==min(xB(xB<0)))(1);
r = zrow./Bm1A(ovp,:); # ratio for display
T = [0:size(A)(2) 0; basis' Bm1A xB; 0 zrow zval; 0 r 0]
# compute min ratio
@VincentTam
VincentTam / mytest.m
Last active February 20, 2017 13:34
My Octave simplex tableau generator
# Show simplex tableau
# Prereq: matrix A, vectors b,c, basis
printf("Current basis:"); printf(" %2i", basis); disp("");
B = A(:,basis); cB = c(basis);
Bm1A = B\A; x_B = B\b; zrow = cB'*Bm1A-c'; zval = cB'*x_B;
nv = find(zrow==min(zrow(zrow<=0)))(1);
r = x_B./Bm1A(:,nv);
T = [0:size(A)(2) 0 0; basis' Bm1A x_B r; 0 zrow zval 0]
if length(r(r>=0)) >= 1
ovp = find(r==min(r(r>=0)))(1);
@VincentTam
VincentTam / bday-prblm.c
Last active January 27, 2017 23:47
Catalan no. & Pascal Triangle use GNU MP
#include <stdio.h>
float myfct(int i) {
return i == 1? 1 : (366.0-i)/365.0*myfct(i - 1);
}
int main() {
int i;
double ans;
printf("Enter a value: ");
@VincentTam
VincentTam / sample-output.txt
Last active January 25, 2017 22:04
Octave script for French postal fee with min no. of stamps, run on http://octave-online.net/
Valeur de timbre (€) | Quantité
---------------------+---------
0.71 | 0
0.73 | 0
1.46 | 1
2.92 | 6
0.85 | 0
1.70 | 0
3.40 | 7
1.30 | 0
@VincentTam
VincentTam / .vimrc
Last active April 5, 2017 09:04
My VIMRC for Vim in Git for Windows
" Vundle settings
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=$HOME/vimfiles/bundle/Vundle.vim
"call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
call vundle#begin('$HOME/vimfiles/bundle/')
@VincentTam
VincentTam / .vimrc
Last active January 10, 2017 22:19
My VIMRC on USB
set nocompatible
filetype off
let iCanHazVundle=1
let vundle_readme=expand("~/.vim/bundle/vundle/README.md")
if !filereadable(vundle_readme)
echo "Installing Vundle.."
echo ""
silent !mkdir -p ~/.vim/bundle
silent !git clone https://github.com/gmarik/vundle ~/.vim/bundle/vundle
let iCanHazVundle=0
\documentclass[tikz]{standalone}
\usetikzlibrary{calc,through}
\begin{document}
\begin{tikzpicture}[scale = 2]
\coordinate [label=left:$O$] (O) at (0,0);
\coordinate [label=left:$L$] (L) at (0.7,1.1);
\coordinate [label=below:$S_n$] (Sn) at (0.6,0.7);
\coordinate (SqCorn1) at (0.2,0.6);
\coordinate (SqCorn2) at (1.2,1.6);
\coordinate (SqCorn3) at (1.2,0.6);