Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0b3cf64

Browse files
committed
Added rest of project
1 parent ff69fd6 commit 0b3cf64

File tree

8 files changed

+292
-0
lines changed

8 files changed

+292
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
main_mod.tex
2+
build/*
3+
main.pdf

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ALGORITHMS=./algorithms
2+
.PHONY: pdf main.pdf clean
3+
main.pdf:
4+
mkdir -p build
5+
python substitute.py $(ALGORITHMS)
6+
pdflatex --output-directory ./build main_mod.tex
7+
cp ./build/main_mod.pdf ./main.pdf
8+
pdf: main.pdf
9+
clean:
10+
rm -R ./build

algorithms/gcd.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Greatest common denominator
2+
def gcd(a, b):
3+
while b != 0:
4+
c = a % b
5+
a = b; b = c
6+
return a
7+

algorithms/is_prime.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Check primality
2+
def is_prime(n):
3+
if n < 2: return False
4+
if n == 2: return True
5+
if n % 2 == 0: return False
6+
for i in range(3, int(n**0.5)+1):
7+
if n % i == 0: return False
8+
return True
9+

algorithms/totient.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Euler's totient function
2+
def totient(n):
3+
ans = n
4+
i = 2
5+
while i**2 <= n:
6+
if n % i == 0: ans -= ans / i
7+
while n % i == 0: n /= i
8+
i += 1
9+
if n > 1: ans -= ans / n
10+
return ans
11+

highlighting.tex

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
\definecolor{mygreen}{rgb}{0,0.6,0}
2+
\definecolor{mygray}{rgb}{0.5,0.5,0.5}
3+
\definecolor{mymauve}{rgb}{0.58,0,0.82}
4+
5+
\lstset{ %
6+
backgroundcolor=\color{white}, % choose the background color; you must add \usepackage{color} or \usepackage{xcolor}
7+
basicstyle=\footnotesize\ttfamily, % the size of the fonts that are used for the code
8+
breakatwhitespace=false, % sets if automatic breaks should only happen at whitespace
9+
breaklines=true, % sets automatic line breaking
10+
captionpos=b, % sets the caption-position to bottom
11+
commentstyle=\color{mygreen}, % comment style
12+
deletekeywords={...}, % if you want to delete keywords from the given language
13+
escapeinside={\%*}{*)}, % if you want to add LaTeX within your code
14+
extendedchars=true, % lets you use non-ASCII characters; for 8-bits encodings only, does not work with UTF-8
15+
frame=single, % adds a frame around the code
16+
keepspaces=true, % keeps spaces in text, useful for keeping indentation of code (possibly needs columns=flexible)
17+
keywordstyle=\color{blue}, % keyword style
18+
otherkeywords={*,...}, % if you want to add more keywords to the set
19+
%numbers=left, % where to put the line-numbers; possible values are (none, left, right)
20+
%numbersep=5pt, % how far the line-numbers are from the code
21+
%numberstyle=\tiny\color{mygray}, % the style that is used for the line-numbers
22+
rulecolor=\color{black}, % if not set, the frame-color may be changed on line-breaks within not-black text (e.g. comments (green here))
23+
showspaces=false, % show spaces everywhere adding particular underscores; it overrides 'showstringspaces'
24+
showstringspaces=false, % underline spaces within strings only
25+
showtabs=false, % show tabs within strings adding particular underscores
26+
%stepnumber=2, % the step between two line-numbers. If it's 1, each line will be numbered
27+
stringstyle=\color{mymauve}, % string literal style
28+
tabsize=2, % sets default tabsize to 2 spaces
29+
%title=\lstname % show the filename of files included with \lstinputlisting; also try caption instead of title
30+
}
31+

main.tex

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
\documentclass[a4paper, twocolumn]{article}
2+
\usepackage[landscape, a4paper, left=1cm, right=1cm, top=1cm, bottom=2cm]{geometry}
3+
\usepackage[parfill]{parskip}
4+
\usepackage{fancyhdr}
5+
\usepackage{tikz}
6+
\usepackage{xcolor}
7+
\usepackage{listings}
8+
\usepackage{amsmath}
9+
\usepackage{titlesec}
10+
\usepackage{tabularx}
11+
\usepackage{graphicx}
12+
13+
% Colour definitions
14+
\definecolor{SpecialBlue}{RGB}{0, 166, 214}
15+
16+
% Team Name
17+
\newcommand{\teamname}{Crystal Math}
18+
19+
% Useful commands
20+
\renewcommand{\vec}{\overrightarrow}
21+
\newcommand{\pageend}{\vfill\newpage}
22+
\newcommand{\arrow}{$\rightarrow$ }
23+
\newcommand{\ms}{\texttt}
24+
\newcommand{\point}[4]{\draw[fill] (#1,#2) circle (1pt) node[#4] {#3}}
25+
26+
% Syntax Highlighting
27+
\lstset{language=python}
28+
\input{highlighting.tex}
29+
30+
% Pagestyle
31+
\renewcommand{\familydefault}{\sfdefault}
32+
\pagestyle{fancy}
33+
\newcommand{\mkfoot}{
34+
\begin{tikzpicture}[remember picture,overlay]
35+
\node[yshift=0] at (current page.south west) {
36+
\begin{tikzpicture}[remember picture,overlay]
37+
\fill [SpecialBlue] (0cm, 0cm) rectangle (\paperwidth, 1.5cm);
38+
\end{tikzpicture}
39+
};
40+
\end{tikzpicture}
41+
}
42+
\fancyhead{\mkfoot}
43+
\fancyfoot{}
44+
\fancyfoot[L]{\color{white} \large \textbf{\teamname} Cheatsheet}
45+
\fancyfoot[R]{\color{white} \large \textbf\thepage}
46+
\renewcommand{\headrulewidth}{0cm}
47+
\renewcommand{\headrulewidth}{0cm}
48+
49+
\titlespacing*{\section}{0pt}{1.0pt plus 0.5pt minus .2pt}{0.8pt plus .2pt}
50+
\titlespacing*{\subsection}{0pt}{1.0pt plus 0.5pt minus .2pt}{0.8pt plus .2pt}
51+
52+
53+
\begin{document}
54+
55+
\section{Modules}
56+
\subsection{Python}
57+
\begin{itemize}
58+
\item Priority queue \arrow \ms{queue.PriorityQueue}
59+
\end{itemize}
60+
\subsection{C++}
61+
\begin{itemize}
62+
\item \ms{std::pair<T,G>, std::make\_pair} \arrow \ms{\#include <utility>}
63+
\item \ms{std::vector<T>} \arrow \ms{\#include <vector>}
64+
\item \ms{std::queue<T>} (Priority queue) \arrow \ms{\#include <queue>}
65+
\end{itemize}
66+
67+
\section{Mathematics}
68+
\subsection*{Formulas for Geometric Shapes}
69+
\vspace{-1em}
70+
\begin{align*}
71+
\text{oppervlakte cirkel} &: \pi r^2 \\
72+
\text{omtrek cirkel} &: \pi d \\
73+
\text{oppervlakte ellips} &: \pi a b \\
74+
\text{oppervlakte kegel} &: \pi r^2 + \pi r \sqrt{r^2 h^2} \\
75+
\text{inhoud kegel} &: \frac{1}{3}\pi r^2 h \\
76+
\text{oppervlakte bol} &: 4 \pi r^2 \\
77+
\text{inhoud bol} &: \frac{4}{3} \pi r^3 \\
78+
\text{oppervlakte cillinder}&: 2\pi rh + 2\pi r^2 \\
79+
\text{inhoud cilinder} &: \pi r^2 h
80+
\end{align*}
81+
\vspace{-2em}
82+
\subsection*{More Formulas}
83+
\vspace{-1.5em}
84+
\begin{align*}
85+
\text{least common multiple} &: \text{lcm}(m, n) = \frac{|m \cdot
86+
n|}{\text{gcd(m, n)}} \\
87+
\text{Catalan number} &: C_n = \frac{1}{n+1}{2n \choose n} =
88+
\frac{(2n)!}{(n+1)!n!} = \prod^n_{k=2}\frac{n+k}{k} \\
89+
\text{Catalan numbers} &: C = \{1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862,
90+
16796\} \\
91+
\text{Triangle numbers} &: T = \{1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78,
92+
91, 105, 120, 136\} \\
93+
\text{Triangle numbers} &: T_n = \sum_{k=1}^nk = \frac{n(n+1)}{2} = {n+1 \choose
94+
2}
95+
\end{align*}
96+
\vspace{-1em}
97+
\newpage
98+
\subsection*{Fibonacci Numbers}\vspace*{-1em}
99+
\begin{align*}
100+
1,1,2,3,5,8,13,21,34,55,89, 144, 233, 377, 610, 987, 1597, 2584
101+
\end{align*}
102+
\begin{itemize}
103+
\item When we take a pairs of large consecutive Fibonacci numbers, we can
104+
approximate the golden ratio by dividing them.
105+
\item The sum of any ten consecutive Fibonacci numbers is divisible by 11.
106+
\item Two consecutive Fibonacci numbers are co-prime.
107+
\item The Fibonacci numbers in the composite-number (i.e. non-prime)
108+
positions are also composite numbers.
109+
\end{itemize}
110+
\subsection*{Cross product}\vspace{-2.5em}
111+
\begin{align*}
112+
a \times b &= \begin{bmatrix} a_x \\ a_b \\ a_z \end{bmatrix}
113+
\times \begin{bmatrix} b_x \\ b_y \\ b_z \end{bmatrix} =
114+
\begin{bmatrix} a_yb_z - a_zb_y \\ a_zb_x - a_xb_z \\
115+
a_xb_y - a_yb_x \end{bmatrix}
116+
\end{align*}
117+
\subsection*{Links of rechts ombuigen}\vspace{-0.5em}
118+
\begin{minipage}{0.45\linewidth}
119+
\begin{tikzpicture}
120+
\draw[->, >=latex] (0mm, 0mm) node[left] {A} -- (15mm, 10mm) node[above left] {B};
121+
\draw[->, >=latex] (15mm, 10mm) -- (40mm, 20mm) node[above] {C};
122+
\end{tikzpicture}
123+
\end{minipage}%
124+
\begin{minipage}{0.25\linewidth}
125+
\begin{align*}
126+
\vec{AB} &= \begin{bmatrix} p \\ q \end{bmatrix} \\
127+
\vec{n} &= \begin{bmatrix} q \\ -p \end{bmatrix} \\
128+
\end{align*}
129+
\end{minipage}%
130+
\begin{minipage}{0.25\linewidth}
131+
\begin{align*}
132+
\vec{n} &\cdot \vec{BC} < 0 \Rightarrow \text{linksaf} \\
133+
\vec{n} &\cdot \vec{BC} > 0 \Rightarrow \text{rechtsaf}
134+
\end{align*}
135+
\end{minipage}
136+
\subsection*{Punt in concaaf/convex polygon test}
137+
Tel het aantal doorsnijdingen van polygon met lijn $P$ naar oneindig. Als het
138+
aantal \\ doorsnijdingen oneven is, dan $P \in ABCDE$. \\
139+
\begin{minipage}{.45\linewidth}
140+
\begin{align*}
141+
\alpha &= \angle APB + ... + \angle DPE + \angle EPA \\
142+
\alpha &= 0 \Rightarrow P \notin ABCDE \\
143+
\alpha &= 2\pi \Rightarrow P \in ABCDE
144+
\end{align*}
145+
\end{minipage}\hfill%
146+
\begin{minipage}{.5\linewidth}
147+
\centering
148+
\begin{tikzpicture}
149+
\point{20mm}{0mm}{A}{left};
150+
\point{10mm}{-10mm}{B}{left};
151+
\point{40mm}{-15mm}{C}{below};
152+
\point{55mm}{5mm}{D}{right};
153+
\point{5mm}{10mm}{E}{left};
154+
\point{35mm}{-2mm}{P}{below left};
155+
\draw (20mm,0mm) -- (10mm,-10mm) -- (40mm, -15mm) -- (55mm, 5mm) --
156+
(5mm,10mm) -- (20mm, 0mm);
157+
\draw[dashed] (35mm, -2mm) -- (20mm, 0mm);
158+
\draw[dashed] (35mm, -2mm) -- (10mm, -10mm);
159+
\draw[dashed] (35mm, -2mm) -- (40mm, -15mm);
160+
\draw[dashed] (35mm, -2mm) -- (55mm, 5mm);
161+
\draw[dashed] (35mm, -2mm) -- (5mm, 10mm);
162+
\end{tikzpicture}
163+
\end{minipage}
164+
165+
\vspace{-2.1em}
166+
\subsection*{Centroid of polygon} \vspace{-0.3em}
167+
The centroid or geometric center of a plane figure is the arithmetic mean
168+
("average") position of all the points in the shape. Informally, it is the point
169+
at which an infinitesimally thin cutout of the shape could be perfectly balanced
170+
on the tip of a pin.
171+
\vspace{-0.5em}
172+
\begin{align*}
173+
C_x &= \frac{1}{6A}\sum_{i=0}^{n-1}(x_i+x_{i+1})(x_iy_{i+1}-x_{i+1}y_i) \\
174+
C_y &= \frac{1}{6A}\sum_{i=0}^{n-1}(y_i+y_{i+1})(x_iy_{i+1}-x_{i+1}y_i) \\
175+
A &= \frac{1}{2}\sum_{i=1}^{n-1}(x_iy_{i+1}-x_{i+1}y_i)
176+
\end{align*}
177+
\subsection*{Point to line distance}
178+
\begin{equation*}
179+
d(ax+by+c=0, (x_0, y_0)) = \frac{|ax_0+by_0+c|}{\sqrt{a^2+b^2}}
180+
\end{equation*}
181+
\section{Algorithms}
182+
183+
%PLACEHOLDER%
184+
185+
\end{document}

substitute.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/env python
2+
import sys
3+
from os import listdir
4+
from os.path import isfile, join
5+
6+
# Get files in directory
7+
algorithm_dir = sys.argv[1]
8+
filelist = [f for f in listdir(algorithm_dir) if isfile(join(algorithm_dir, f))]
9+
10+
def get_lang(f):
11+
if f[-3:] == ".py": return "python"
12+
elif f[-5:] == ".java": return "java"
13+
elif f[-4:] == ".cpp": return "cpp"
14+
else: return "java"
15+
16+
inclusion = ""
17+
for f in filelist:
18+
with open(join(algorithm_dir, f)) as file:
19+
data = file.read()
20+
title = data.splitlines()[0][2:].strip()
21+
extra_info = "\n\\\\".join([i.strip()[3:] for i in data.splitlines()[1:] if i.startswith("##")])
22+
inclusion += r"""
23+
\subsection*{%TITLE%}
24+
%EXTRA%
25+
\begin{lstlisting}[language=%LANGUAGE%]
26+
%FILE%
27+
\end{lstlisting}
28+
""".replace("%LANGUAGE%", get_lang(f)).replace("%FILE%", data.partition('\n')[2]).replace("%TITLE%", title).replace("%EXTRA%", extra_info)
29+
30+
with open("main.tex") as infile:
31+
print("Writing to file")
32+
data = infile.read().replace("%PLACEHOLDER%", inclusion)
33+
if "%PLACEHOLDER" in data: print("fail")
34+
with open("main_mod.tex", 'w') as out:
35+
out.write(data)
36+

0 commit comments

Comments
 (0)