diff --git a/alg2pdf b/alg2pdf deleted file mode 100755 index 8548db0312b28750914cd8ab6cab67a6e45fbbc0..0000000000000000000000000000000000000000 --- a/alg2pdf +++ /dev/null @@ -1,91 +0,0 @@ -#!/bin/bash - -# Random temp file name -tex_file=$(mktemp) - -# Print the tex file header -cat<<EOF >$tex_file -\documentclass{article} -\usepackage{listings} -\usepackage[usenames,dvipsnames]{color} %% Allow color names -\usepackage[letterpaper, portrait, margin=1in]{geometry} - -%\lstdefinestyle{customasm}{ -% belowcaptionskip=1\baselineskip, -% xleftmargin=\parindent, -% language=C++, %% Change this to whatever you write in -% breaklines=true, %% Wrap long lines -% basicstyle=\footnotesize\ttfamily, -% commentstyle=\itshape\color{Gray}, -% stringstyle=\color{Black}, -% numberstyle=\color{Orange}, -% keywordstyle=\bfseries\color{OliveGreen}, -% identifierstyle=\color{blue}, -%} - -\definecolor{darkgreen}{rgb}{0,0.6,0} -\definecolor{darkpink}{rgb}{0.75,0.25,0.5} - -\lstdefinestyle{customasm}{ - language=[ISO]C++, - breaklines=true, %% Wrap long lines - keywordstyle=\color{blue}\bfseries, - commentstyle=\color{darkgreen}\textit, - stringstyle=\color{darkpink}\ttfamily, - basicstyle=\footnotesize\ttfamily\color{red}, - identifierstyle={\color{black}}, -% - literate=* - {;}{{{\color{black};}}}{1} - {.7}{{{\color{red}.7}}}{2},% -% -morekeywords={int32_t} -} - -\usepackage[colorlinks=true,linkcolor=blue]{hyperref} -\begin{document} -\tableofcontents - -EOF -# xleftmargin=-8em, - -past_dir_name="00" - -find . -type f \( -iname \*.cpp -o -iname \*.cu \) | - -# Change ./foo/bar.src to foo/bar.src -sed 's/^\..//' | - -# Loop through each file -while read i; do - - dir_name=`echo $i | awk -F '/' '{print $1}' | sed 's/_/\\\_/g'` - file_name=`echo $i | awk -F '/' '{print $2}' | sed 's/_/\\\_/g'` - - if [ "$dir_name" != "$past_dir_name" ]; then - - # Start new section - echo "\newpage" >> $tex_file - echo "\section{$dir_name}" >> $tex_file - else - echo "\\" >> $tex_file - fi - - # Create a section for each file - echo "\subsection{$file_name}" >> $tex_file - - # This command will include the file in the PDF - echo "\lstinputlisting[style=customasm]{$i}" >>$tex_file - - past_dir_name="$dir_name" - -done && - -echo "\end{document}" >> $tex_file && - -# This needs to be run twice for the TOC to be generated -pdflatex $tex_file -output-directory . && -pdflatex $tex_file -output-directory . - -mv tmp.pdf caderno.pdf -rm tmp.* diff --git a/algorithms/graph/articulations_bridges.cpp b/algorithms/graph/articulations_bridges.cpp index 62b086868b2ce5e02e1a7ca3c36b19ef0a766b45..7ddb90e01159b6481e459324a8ac94cdf3c22b79 100644 --- a/algorithms/graph/articulations_bridges.cpp +++ b/algorithms/graph/articulations_bridges.cpp @@ -1,5 +1,5 @@ /** - * Articulations and Bridges (Tarjan) + * Tarjan - Articulations and Bridges * * Complexity (Time): O(n + m) * Complexity (Space): O(n + m) diff --git a/algorithms/graph/bfs.cpp b/algorithms/graph/bfs.cpp index e57da24dc01301b5923384ea4e69a91483a99c67..6431f2b60f996a4ca6f6114920655a588f2b1fe9 100644 --- a/algorithms/graph/bfs.cpp +++ b/algorithms/graph/bfs.cpp @@ -1,5 +1,5 @@ /** - * Breadth First Search - BFS + * Breadth First Search (BFS) * * Complexity (Time): O(n + m) * Complexity (Space): O(n + m) diff --git a/algorithms/graph/dfs.cpp b/algorithms/graph/dfs.cpp index 46373f84b92b225b26717b358a98eeb16f8b8ebb..6408d40c776db8f9f78b80ed51ff3d9bbc001514 100644 --- a/algorithms/graph/dfs.cpp +++ b/algorithms/graph/dfs.cpp @@ -1,5 +1,5 @@ /** - * Depth First Search - DFS + * Depth First Search (DFS) * * Complexity (Time): O(n + m) * Complexity (Space): O(n + m) diff --git a/algorithms/graph/lca.cpp b/algorithms/graph/lca.cpp index 5f43a335801c694e24bfac6e4083c6cfaa5fe8a4..8919ff737ff75dd66f4c77eedce1c43467aa3be8 100644 --- a/algorithms/graph/lca.cpp +++ b/algorithms/graph/lca.cpp @@ -1,9 +1,9 @@ /** * Lowest Common Ancestor - LCA * - * Complexity (Time): - * preprocess -> O(n log n) - * query -> O(log n) + * Complexity (Time): + * - preprocess: O(n log n) + * - query: O(log n) * Complexity (Space): O(n + m + n log n) * * OBS: * = return sum path to LCA diff --git a/algorithms/paradigm/kadane.cpp b/algorithms/paradigm/kadane.cpp index 46d5b4ee37675be3e46a340b02e76a5062d26d54..dbd4fcdbdb4dfe8d2422ca5d9c709b87345c13b5 100644 --- a/algorithms/paradigm/kadane.cpp +++ b/algorithms/paradigm/kadane.cpp @@ -1,5 +1,5 @@ /** - * Kadane - Largest Sum Contiguous Subarray + * Kadane * * Complexity (Time): O(n + m) * Complexity (Space): O(n + m) diff --git a/algorithms/structure/ball_tree.cpp b/algorithms/structure/ball_tree.cpp index 7cf6ead8278a5cc89e3a2c0f6c94aadda7c855d8..9518ea5a74f7d6d79a8a89c4a5d4ef625cd59a09 100644 --- a/algorithms/structure/ball_tree.cpp +++ b/algorithms/structure/ball_tree.cpp @@ -1,9 +1,9 @@ - /** - * Balltree (k-Nearest Neighbors) - * - * Complexity (Time): O(n log n) - * Complexity (Space): O(n) - */ +/** + * Balltree + * + * Complexity (Time): O(n log n) + * Complexity (Space): O(n) + */ #define x first #define y second diff --git a/notebook/gen_latex.py b/notebook/gen_latex.py new file mode 100644 index 0000000000000000000000000000000000000000..03ffba5e8be8a1bebaf74e05d82dd435b89d86c0 --- /dev/null +++ b/notebook/gen_latex.py @@ -0,0 +1,97 @@ +import os +import sys +import subprocess +import argparse + +from pathlib import Path + +dirs = [ + 'algorithms', + 'misc', +# 'contests', +# 'problems' +] + +parser = argparse.ArgumentParser() +parser.add_argument('--header', action='store', type=str, help='The text to parse.') +parser.add_argument('--output', action='store', type=str, help='The text to parse.') +args = parser.parse_args() + +output = open(args.output, 'w') + +# Read Latex header +with open(args.header) as f: + data = f.readlines() + +# Print header to output +for i in data: + output.write(i) + +last_sections = [None] * 2 + +for di in dirs: + path_list = Path(di).glob('**/*.cpp') + + for path in path_list: + file_name = str(path) + sections = file_name.replace('_', '\_').split('/') + + # Sections[0] is [algorithms, contests, problems, misc] (sections) + if sections[0] != last_sections[0]: + output.write('\\newpage\n') + output.write('\\section{' + sections[0].capitalize() + '}\n') + + # Sections[1] is name of constest or category of algorithm (subsections) + if sections[1] != last_sections[1]: + output.write('\\subsection{' + sections[1].capitalize() + '}\n') + + # Parse source code + with open(file_name) as f: + source = f.readlines() + + # Separate into comment and code, and define title + title = "" + in_comment = False + code, comment = [], [] + for line in source: + if '/**' == line[0:3]: + in_comment = True + + if in_comment: + if len(title) == 0 and len(comment) == 1: + title = line[3:] + comment.append(line) + else: + code.append(line) + + if '*/' in line: + in_comment = False + + in_ctime = False + ctime, cspace = [], [] + for line in comment: + if 'Complexity (time)' in line: + in_ctime = True + if 'Complexity (space)' in line: + in_ctime = False + + if in_ctime: + ctime.append(line) + + + + if len(sections) > 2: + output.write('\\subsubsection{' + title + '}\n') + + # Remove first \n after header comment + code = code[1:] + + #output.write('\\lstinputlisting[style=customcpp]{' + file_name + '}\n') + output.write('\\begin{lstlisting}[style=customcpp]\n') + for i in code: + output.write(i) + output.write('\\end{lstlisting}\n') + output.write('\\\n') + last_sections = sections + +output.write('\\end{document}') diff --git a/notebook/header.tex b/notebook/header.tex new file mode 100644 index 0000000000000000000000000000000000000000..655b998d10210e59a72a90db29b1170b22b82141 --- /dev/null +++ b/notebook/header.tex @@ -0,0 +1,22 @@ +\documentclass{article} +\usepackage{listings} +\usepackage{titlesec} +\usepackage[a4paper, total={6in, 8in}]{geometry} +\geometry{ + a4paper, + left=20mm, + right=10mm, + top=1in, + bottom=1in, +} +\titleformat*{\subsubsection}{\Large\bfseries} +\lstdefinestyle{customcpp}{ + frame=single, + language=C++, + basicstyle=\small, + tabsize=2, + breaklines=true, + morekeywords={int32\_t, ll} +} +\begin{document} +\tableofcontents diff --git a/run b/run new file mode 100755 index 0000000000000000000000000000000000000000..99c4c760c51bd0e9be318c465705a671b5125576 --- /dev/null +++ b/run @@ -0,0 +1,10 @@ +#!/bin/bash + +tex_file=$(mktemp) +python3 notebook/gen_latex.py --header=notebook/header.tex --output=$tex_file + +pdflatex $tex_file -output-directory . && +pdflatex $tex_file -output-directory . + +mv tmp.pdf caderno.pdf +rm tmp*