Compare commits
9 Commits
ed3339829d
...
d107fe018d
Author | SHA1 | Date | |
---|---|---|---|
d107fe018d | |||
c3757de491 | |||
0e9a4198ce | |||
6776710a3e | |||
a7d869cc68 | |||
285ccaad01 | |||
a95ef812bb | |||
f98df100ae | |||
1b5826baf4 |
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -1,4 +1,5 @@
|
||||
{
|
||||
"latex-workshop.latex.recipe.default": "latexmk (xelatex)",
|
||||
"tinymist.formatterPrintWidth": 80
|
||||
"tinymist.formatterPrintWidth": 80,
|
||||
"tinymist.typstExtraArgs": ["--package-path=./lib/typst"]
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
/// Typst handout library, used for all documents in this repository.
|
||||
|
||||
|
||||
/// If false, hide instructor info.
|
||||
///
|
||||
@ -238,8 +240,8 @@
|
||||
|
||||
set page(
|
||||
margin: 20mm,
|
||||
width: 8.5in,
|
||||
height: 11in,
|
||||
width: 8in,
|
||||
height: 11.5in,
|
||||
footer: align(
|
||||
center,
|
||||
context counter(page).display(),
|
6
lib/typst/local/handout/0.1.0/typst.toml
Normal file
6
lib/typst/local/handout/0.1.0/typst.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "handout"
|
||||
version = "0.1.0"
|
||||
entrypoint = "handout.typ"
|
||||
authors = []
|
||||
license = "GPL"
|
@ -1,4 +1,4 @@
|
||||
#import "./handout.typ": *
|
||||
#import "@local/handout:0.1.0": *
|
||||
#import "@preview/cetz:0.3.1"
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#import "./handout.typ": *
|
||||
#import "@local/handout:0.1.0": *
|
||||
|
||||
#show: doc => handout(
|
||||
doc,
|
||||
|
@ -1,4 +1,4 @@
|
||||
#import "../handout.typ": *
|
||||
#import "@local/handout:0.1.0": *
|
||||
#import "../macros.typ": *
|
||||
|
||||
= Tropical Arithmetic
|
||||
|
@ -1,4 +1,4 @@
|
||||
#import "../handout.typ": *
|
||||
#import "@local/handout:0.1.0": *
|
||||
#import "../macros.typ": *
|
||||
#import "@preview/cetz:0.3.1"
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#import "../handout.typ": *
|
||||
#import "@local/handout:0.1.0": *
|
||||
#import "../macros.typ": *
|
||||
#import "@preview/cetz:0.3.1"
|
||||
|
||||
|
@ -1,35 +0,0 @@
|
||||
\documentclass[
|
||||
solutions,
|
||||
hidewarning,
|
||||
singlenumbering,
|
||||
nopagenumber
|
||||
]{../../../lib/tex/ormc_handout}
|
||||
\usepackage{../../../lib/tex/macros}
|
||||
|
||||
|
||||
|
||||
\title{Warm-Up: A Familiar Concept}
|
||||
\uptitler{\smallurl{}}
|
||||
\subtitle{Prepared by Mark on \today}
|
||||
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
|
||||
\problem{}<one>
|
||||
Let $v = [-5, -2, 0, 1, 4, 1000]$. Find all $x$ that minimize the following metric. \par
|
||||
$$
|
||||
\sum_{\forall i} |v_i - x| = |v_1 - x| + |v_2 - x| + ... + |v_6 - x|
|
||||
$$
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Let $v = [-5, -2, 0, 1, 4, 1000, 1001]$. Find all $x$ that minimize the metric in \ref{one}.
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
What is this metric usually called?
|
||||
|
||||
\end{document}
|
39
src/Warm-Ups/A Familiar Concept/main.typ
Normal file
39
src/Warm-Ups/A Familiar Concept/main.typ
Normal file
@ -0,0 +1,39 @@
|
||||
#import "@local/handout:0.1.0": *
|
||||
|
||||
#show: doc => handout(
|
||||
doc,
|
||||
quarter: link(
|
||||
"https://betalupi.com/handouts",
|
||||
"betalupi.com/handouts",
|
||||
),
|
||||
|
||||
title: [Warm-Up: A Familiar Concept],
|
||||
by: "Mark",
|
||||
)
|
||||
|
||||
#problem()
|
||||
Let $v = [-5, -2, 0, 1, 4, 1000]$. Find all $x$ that minimize the following metric:
|
||||
|
||||
#align(
|
||||
center,
|
||||
box(
|
||||
inset: 3mm,
|
||||
$
|
||||
sum_(#sym.forall i) |v_i - x| = |v_1 - x| + |v_2 - x| + ... + |v_6 - x|
|
||||
$,
|
||||
),
|
||||
)
|
||||
|
||||
#v(1fr)
|
||||
|
||||
#problem()
|
||||
Let $v = [-5, -2, 0, 1, 4, 1000, 1001]$. Find all $x$ that minimize the metric in the previous problem.
|
||||
|
||||
#v(1fr)
|
||||
|
||||
|
||||
#problem()
|
||||
What is this metric usually called?
|
||||
|
||||
|
||||
#v(0.25fr)
|
@ -1,31 +0,0 @@
|
||||
\documentclass[
|
||||
solutions,
|
||||
hidewarning,
|
||||
singlenumbering,
|
||||
nopagenumber
|
||||
]{../../../lib/tex/ormc_handout}
|
||||
\usepackage{../../../lib/tex/macros}
|
||||
|
||||
|
||||
|
||||
\title{Warm-Up: Fuse Timers}
|
||||
\uptitler{\smallurl{}}
|
||||
\subtitle{Prepared by Mark on \today.}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
|
||||
\problem{}
|
||||
Suppose we have two strings and a lighter. Each string takes an hour to fully burn. \par
|
||||
However, we do not know how fast each part of the string burns:
|
||||
half might burn in 1 minute, and the rest could take 59.
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
How would we measure exactly 45 minutes using these strings?
|
||||
|
||||
\vfill
|
||||
|
||||
\end{document}
|
21
src/Warm-Ups/Fuse Timers/main.typ
Normal file
21
src/Warm-Ups/Fuse Timers/main.typ
Normal file
@ -0,0 +1,21 @@
|
||||
#import "@local/handout:0.1.0": *
|
||||
|
||||
#show: doc => handout(
|
||||
doc,
|
||||
quarter: link(
|
||||
"https://betalupi.com/handouts",
|
||||
"betalupi.com/handouts",
|
||||
),
|
||||
|
||||
title: [Warm-Up: Fuse Timers],
|
||||
by: "Mark",
|
||||
)
|
||||
|
||||
#problem()
|
||||
Suppose we have two strings and a lighter. Each string takes exactly an hour to fully burn. \
|
||||
However, we do not know how fast each part of the string burns:
|
||||
half might burn in 1 minute, and the rest could take 59.
|
||||
|
||||
#v(2mm)
|
||||
|
||||
How can we measure exactly 45 minutes using these two strings?
|
@ -1,54 +0,0 @@
|
||||
\documentclass[
|
||||
solutions,
|
||||
hidewarning,
|
||||
singlenumbering,
|
||||
nopagenumber
|
||||
]{../../../lib/tex/ormc_handout}
|
||||
\usepackage{../../../lib/tex/macros}
|
||||
|
||||
|
||||
\title{Warm-Up: Mario Kart}
|
||||
\uptitler{\smallurl{}}
|
||||
\subtitle{Prepared by Mark on \today}
|
||||
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
\problem{}
|
||||
A standard Mario Kart cup consists of 12 players and four races. \par
|
||||
Each race is scored as follows:
|
||||
\begin{itemize}
|
||||
\item 15 points are awarded for first place;
|
||||
\item 12 for second;
|
||||
\item and $(13 - \text{place})$ otherwise.
|
||||
\end{itemize}
|
||||
In any one race, no players may tie.
|
||||
A player's score at the end of a cup is the sum of their scores for each of the four races.
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
An $n$-way tie occurs when the top $n$ players have the same score at the end of a round. \par
|
||||
What is the largest possible $n$, and how is it achieved?
|
||||
|
||||
\begin{solution}
|
||||
A 12-way tie is impossible, since the total number of point is not divisible by 12.
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
A 11-way tie is possible, with a top score of 28:
|
||||
\begin{itemize}
|
||||
\item Four players finish $1^\text{st}$, $3^\text{ed}$, $11^\text{th}$, and $12^\text{th}$;
|
||||
|
||||
% spell:off
|
||||
\item Four players finish $2^\text{nd}$, $4^\text{th}$, $9^\text{th}$, and $10^\text{th}$;
|
||||
% spell:on
|
||||
|
||||
\item Two players finish fifth twice and seventh twice,
|
||||
\item One player finishes sixth in each race.
|
||||
\end{itemize}
|
||||
The final player always finishes eighth, with a non-tie score of 20.
|
||||
\end{solution}
|
||||
|
||||
\end{document}
|
41
src/Warm-Ups/Mario Kart/main.typ
Normal file
41
src/Warm-Ups/Mario Kart/main.typ
Normal file
@ -0,0 +1,41 @@
|
||||
#import "@local/handout:0.1.0": *
|
||||
|
||||
#show: doc => handout(
|
||||
doc,
|
||||
quarter: link(
|
||||
"https://betalupi.com/handouts",
|
||||
"betalupi.com/handouts",
|
||||
),
|
||||
|
||||
title: [Warm-Up: Mario Kart],
|
||||
by: "Mark",
|
||||
)
|
||||
|
||||
#problem()
|
||||
A standard Mario Kart cup consists of 12 players and four races. \
|
||||
Each race is scored as follows:
|
||||
- 15 points are awarded for first place;
|
||||
- 12 for second;
|
||||
- and $(13 - #text("place"))$ otherwise.
|
||||
|
||||
In any one race, no players may tie. \
|
||||
A player's score at the end of a cup is the sum of their scores for each of the four races.
|
||||
|
||||
#v(2mm)
|
||||
|
||||
An $n$-way tie occurs when the top $n$ players have the same score at the end of a round. \
|
||||
What is the largest possible $n$, and how is it achieved?
|
||||
|
||||
#solution([
|
||||
A 12-way tie is impossible, since the total number of point is not divisible by 12.
|
||||
|
||||
#v(2mm)
|
||||
|
||||
A 11-way tie is possible, with a top score of 28:
|
||||
- Four players finish $1^#text("st")$, $3^#text("ed")$, $11^#text("th")$, and $12^#text("th")$;
|
||||
- Four players finish $2^#text("nd")$, $4^#text("th")$, $9^#text("th")$, and $10^#text("th")$;
|
||||
- Two players finish fifth twice and seventh twice,
|
||||
- One player finishes sixth in each race.
|
||||
The final player always finishes eighth, with a non-tie score of 20.
|
||||
|
||||
])
|
@ -1,57 +0,0 @@
|
||||
\documentclass[
|
||||
solutions,
|
||||
singlenumbering,
|
||||
nopagenumber
|
||||
]{../../../lib/tex/ormc_handout}
|
||||
\usepackage{../../../lib/tex/macros}
|
||||
|
||||
|
||||
\title{Warm-Up: Partition Products}
|
||||
\uptitler{\smallurl{}}
|
||||
\subtitle{Prepared by Mark on \today.}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
\problem{}
|
||||
Take any positive integer $n$. \par
|
||||
Now, write it as sum of smaller positive integers: $n = a_1 + a_2 + ... + a_k$ \par
|
||||
Maximize the product $a_1 \times a_2 \times ... \times a_k$
|
||||
|
||||
|
||||
|
||||
\begin{solution}
|
||||
|
||||
\textbf{Interesting Solution:}
|
||||
|
||||
Of course, all $a_i$ should be greater than $1$. \par
|
||||
Also, all $a_i$ should be smaller than four, since $x \leq x(x-2)$ if $x \geq 4$. \par
|
||||
Thus, we're left with sequences that only contain 2 and 3. \par
|
||||
\note{Note that two twos are the same as one four, but we exclude fours for simplicity.}
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
Finally, we see that $3^2 > 2^3$, so any three twos are better repackaged as two threes. \par
|
||||
The best sequence $a_i$ thus consists of a maximal number of threes followed by 0, 1, or 2 twos.
|
||||
|
||||
\linehack{}
|
||||
|
||||
|
||||
|
||||
\textbf{Calculus Solution:}
|
||||
|
||||
First, solve this problem for equal, non-integer $a_i$:
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
We know $n = \prod{a_i}$, thus $\ln(n) = \sum{\ln(a_i)}$. \par
|
||||
If all $a_i$ are equal, we get $\ln(n) = k \times \ln(n / k)$. \par
|
||||
Derive wrt $k$ and set to zero to get $\ln(n / k) = 1$ \par
|
||||
So $k = n / e$ and $n / k = e \approx 2.7$
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
If we try to approximate this with integers, we get the same solution as above.
|
||||
\end{solution}
|
||||
\end{document}
|
47
src/Warm-Ups/Partition Products/main.typ
Normal file
47
src/Warm-Ups/Partition Products/main.typ
Normal file
@ -0,0 +1,47 @@
|
||||
#import "@local/handout:0.1.0": *
|
||||
|
||||
#show: doc => handout(
|
||||
doc,
|
||||
quarter: link(
|
||||
"https://betalupi.com/handouts",
|
||||
"betalupi.com/handouts",
|
||||
),
|
||||
|
||||
title: [Warm-Up: Partition Products],
|
||||
by: "Mark",
|
||||
)
|
||||
|
||||
#problem()
|
||||
Take any positive integer $n$. \
|
||||
Now, write it as sum of smaller positive integers: $n = a_1 + a_2 + ... a_k$ \
|
||||
Maximize the product $a_1 #sym.times a_2 #sym.times ... #sym.times a_k$
|
||||
|
||||
|
||||
#solution([
|
||||
*Interesting Solution:*
|
||||
|
||||
Of course, all $a_i$ should be greater than $1$. \
|
||||
Also, all $a_i$ should be smaller than four, since $x <= x(x-2)$ if $x >= 4$. \
|
||||
Thus, we're left with sequences that only contain 2 and 3. \
|
||||
#note([Note that two twos are the same as one four, but we exclude fours for simplicity.])
|
||||
|
||||
#v(2mm)
|
||||
|
||||
Finally, we see that $3^2 > 2^3$, so any three twos are better repackaged as two threes. \
|
||||
The best sequence $a_i$ thus consists of a maximal number of threes followed by 0, 1, or 2 twos.
|
||||
|
||||
#v(8mm)
|
||||
|
||||
*Calculus Solution:*
|
||||
|
||||
First, solve this problem for equal, real $a_i$:
|
||||
#v(2mm)
|
||||
We know $n = product(a_i)$, thus $ln(n) = sum(ln(a_i))$. \
|
||||
If all $a_i$ are equal, we get $ln(n) = k #sym.times ln(n / k)$. \
|
||||
Derive wrt $k$ and set to zero to get $ln(n / k) = 1$ \
|
||||
So $k = n / e$ and $n / k = e #sym.approx 2.7$
|
||||
|
||||
#v(2mm)
|
||||
|
||||
If we try to approximate this with integers, we get the same solution as above.
|
||||
])
|
@ -1,34 +0,0 @@
|
||||
\documentclass[
|
||||
solutions,
|
||||
singlenumbering,
|
||||
nopagenumber,
|
||||
hidewarning
|
||||
]{../../../lib/tex/ormc_handout}
|
||||
\usepackage{../../../lib/tex/macros}
|
||||
|
||||
\title{Warm-Up: Prime Factors}
|
||||
\uptitler{\smallurl{}}
|
||||
\subtitle{Prepared by Mark on \today.}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
\problem{}
|
||||
What proportion of integers have $2$ as their smallest prime factor?
|
||||
% 1^2
|
||||
\vfill
|
||||
|
||||
|
||||
\problem{}
|
||||
What proportion of integers have $3$ as their second-smallest prime factor?
|
||||
% 1/6
|
||||
\vfill
|
||||
|
||||
|
||||
\problem{}
|
||||
What is the median second-smallest prime factor?
|
||||
% 37
|
||||
\vfill
|
||||
|
||||
\end{document}
|
29
src/Warm-Ups/Prime Factors/main.typ
Normal file
29
src/Warm-Ups/Prime Factors/main.typ
Normal file
@ -0,0 +1,29 @@
|
||||
#import "@local/handout:0.1.0": *
|
||||
|
||||
#show: doc => handout(
|
||||
doc,
|
||||
quarter: link(
|
||||
"https://betalupi.com/handouts",
|
||||
"betalupi.com/handouts",
|
||||
),
|
||||
|
||||
title: [Warm-Up: Prime Factors],
|
||||
by: "Mark",
|
||||
)
|
||||
|
||||
#problem()
|
||||
What proportion of integers have $2$ as their smallest prime factor?
|
||||
#solution([$1 div 2$])
|
||||
#v(1fr)
|
||||
|
||||
|
||||
#problem()
|
||||
What proportion of integers have $3$ as their second-smallest prime factor?
|
||||
#solution([$1 div 6$])
|
||||
#v(1fr)
|
||||
|
||||
|
||||
#problem()
|
||||
What is the median second-smallest prime factor?
|
||||
#solution([37])
|
||||
#v(1fr)
|
@ -1,153 +0,0 @@
|
||||
\documentclass[
|
||||
solutions,
|
||||
hidewarning,
|
||||
]{../../../lib/tex/ormc_handout}
|
||||
\usepackage{../../../lib/tex/macros}
|
||||
|
||||
|
||||
\usepackage{xcolor}
|
||||
\usepackage{soul}
|
||||
\usepackage{hyperref}
|
||||
|
||||
\definecolor{Light}{gray}{.90}
|
||||
\sethlcolor{Light}
|
||||
\newcommand{\htexttt}[1]{\texttt{\hl{#1}}}
|
||||
|
||||
|
||||
\title{The Regex Warm-Up}
|
||||
\uptitler{\smallurl{}}
|
||||
\subtitle{Prepared by Mark on \today}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
|
||||
Last time, we discussed Deterministic Finite Automata. One interesting application of these mathematical objects is found in computer science: Regular Expressions. \par
|
||||
This is often abbreviated \say{regex}, which is pronounced like \say{gif.}
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
Regex is a language used to specify patterns in a string. You can think of it as a concise way to define a DFA, using text instead of a huge graph. \par
|
||||
|
||||
Often enough, a clever regex pattern can do the work of a few hundred lines of code.
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
Like the DFAs we've studied, a regex pattern \textit{accepts} or \textit{rejects} a string. However, we don't usually use this terminology with regex, and instead say that a string \textit{matches} or \textit{doesn't match} a pattern.
|
||||
|
||||
\vspace{5mm}
|
||||
|
||||
Regex strings consist of characters, quantifiers, sets, and groups.
|
||||
|
||||
\vspace{5mm}
|
||||
|
||||
\textbf{Quantifiers} \par
|
||||
Quantifiers specify how many of a character to match. \par
|
||||
There are four of these: \htexttt{+}, \htexttt{*}, \htexttt{?}, and \htexttt{\{ \}}
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
\htexttt{+} means \say{match one or more of the preceding token} \par
|
||||
\htexttt{*} means \say{match zero or more of the preceding token}
|
||||
|
||||
For example, the pattern \htexttt{ca+t} will match the following strings:
|
||||
\begin{itemize}
|
||||
\item \texttt{cat}
|
||||
\item \texttt{caat}
|
||||
\item \texttt{caaaaaaaat}
|
||||
\end{itemize}
|
||||
\htexttt{ca+t} will \textbf{not} match the string \texttt{ct}. \par
|
||||
The pattern \htexttt{ca*t} will match all the strings above, including \texttt{ct}.
|
||||
\vspace{2mm}
|
||||
|
||||
|
||||
\htexttt{?} means \say{match one or none of the preceding token} \par
|
||||
The pattern \htexttt{linea?r} will match only \texttt{linear} and \texttt{liner}.
|
||||
\vspace{2mm}
|
||||
|
||||
Brackets \htexttt{\{min, max\}} are the most flexible quantifier. \par
|
||||
They specify exactly how many tokens to match: \par
|
||||
\htexttt{ab\{2\}a} will match only \texttt{abba}. \par
|
||||
\htexttt{ab\{1,3\}a} will match only \texttt{aba}, \texttt{abba}, and \texttt{abbba}. \par
|
||||
% spell:off
|
||||
\htexttt{ab\{2,\}a} will match any \texttt{ab...ba} with at least two \texttt{b}s.
|
||||
% spell:on
|
||||
|
||||
\vspace{5mm}
|
||||
|
||||
\problem{}
|
||||
Write the patterns \htexttt{a*} and \htexttt{a+} using only \htexttt{\{ \}}.
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Draw a DFA equivalent to the regex pattern \htexttt{01*0}.
|
||||
\vfill
|
||||
|
||||
\pagebreak
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
\textbf{Characters, Sets, and Groups} \par
|
||||
In the previous section, we saw how we can specify characters literally: \par
|
||||
\texttt{a+} means \say{one or more \texttt{a} character}
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
There are, of course, other ways we can specify characters.
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
The first such way is the \textit{set}, denoted \htexttt{[ ]}. A set can pretend to be any character inside it. \par
|
||||
For example, \htexttt{m[aoy]th} will match \texttt{math}, \texttt{moth}, or \texttt{myth}. \par
|
||||
\htexttt{a[01]+b} will match \texttt{a0b}, \texttt{a111b}, \texttt{a1100110b}, and any other similar string. \par
|
||||
You may negate a set with a \htexttt{\textasciicircum}. \par
|
||||
\htexttt{[\textasciicircum abc]} will match any character except \texttt{a}, \texttt{b}, or \texttt{c}, including symbols and spaces.
|
||||
|
||||
\vspace{2mm}
|
||||
|
||||
If we want to keep characters together, we can use the \textit{group}, denoted \htexttt{( )}. \par
|
||||
|
||||
Groups work exactly as you'd expect, representing an atomic\footnotemark{} group of characters. \par
|
||||
\htexttt{a(01)+b} will match \texttt{a01b} and \texttt{a010101b}, but will \textbf{not} match \texttt{a0b}, \texttt{a1b}, or \texttt{a1100110b}.
|
||||
|
||||
\footnotetext{In other words, \say{unbreakable}}
|
||||
|
||||
|
||||
\problem{}<regex>
|
||||
You are now familiar with most of the tools regex has to offer. \par
|
||||
Write patterns that match the following strings:
|
||||
\begin{enumerate}[itemsep=1mm]
|
||||
\item An ISO-8601 date, like \texttt{2022-10-29}. \par
|
||||
\hint{Invalid dates like \texttt{2022-13-29} should also be matched.}
|
||||
|
||||
\item An email address. \par
|
||||
\hint{Don't forget about subdomains, like \texttt{math.ucla.edu}.}
|
||||
|
||||
\item A UCLA room number, like \texttt{MS 5118} or \texttt{Kinsey 1220B}.
|
||||
|
||||
\item Any ISBN-10 of the form \texttt{0-316-00395-7}. \par
|
||||
\hint{Remember that the check digit may be an \texttt{X}. Dashes are optional.}
|
||||
|
||||
\item A word of even length. \par
|
||||
\hint{The set \texttt{[A-z]} contains every english letter, capitalized and lowercase. \\
|
||||
\texttt{[a-z]} will only match lowercase letters.}
|
||||
|
||||
\item A word with exactly 3 vowels. \par
|
||||
\hint{The special token \texttt{\textbackslash w} will match any word character. It is equivalent to \texttt{[A-z0-9\_]} \\ \texttt{\_} stands for a literal underscore.}
|
||||
|
||||
\item A word that has even length and exactly 3 vowels.
|
||||
|
||||
\item A sentence that does not start with a capital letter.
|
||||
\end{enumerate}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
If you'd like to know more, check out \url{https://regexr.com}. It offers an interactive regex prompt, as well as a cheatsheet that explains every other regex token there is. \par
|
||||
You will find a nice set of challenges at \url{https://alf.nu/RegexGolf}.
|
||||
I especially encourage you to look into this if you are interested in computer science.
|
||||
\end{document}
|
138
src/Warm-Ups/Regex/main.typ
Normal file
138
src/Warm-Ups/Regex/main.typ
Normal file
@ -0,0 +1,138 @@
|
||||
#import "@local/handout:0.1.0": *
|
||||
|
||||
#show: doc => handout(
|
||||
doc,
|
||||
quarter: link(
|
||||
"https://betalupi.com/handouts",
|
||||
"betalupi.com/handouts",
|
||||
),
|
||||
|
||||
title: [The Regex Warm-Up],
|
||||
by: "Mark",
|
||||
)
|
||||
|
||||
|
||||
Last time, we discussed Deterministic Finite Automata. One interesting application of these mathematical objects is found in computer science: Regular Expressions. \
|
||||
This is often abbreviated "regex," which is pronounced like "gif."
|
||||
|
||||
#v(2mm)
|
||||
|
||||
Regex is a language used to specify patterns in a string. You can think of it as a concise way to define a DFA, using text instead of a huge graph. \
|
||||
|
||||
Often enough, a clever regex pattern can do the work of a few hundred lines of code.
|
||||
|
||||
#v(2mm)
|
||||
|
||||
Like the DFAs we've studied, a regex pattern _accepts_ or _rejects_ a string. However, we don't usually use this terminology with regex, and instead say that a string _matches_ or _doesn't match_ a pattern.
|
||||
|
||||
#v(5mm)
|
||||
|
||||
Regex strings consist of characters, quantifiers, sets, and groups.
|
||||
|
||||
#v(5mm)
|
||||
|
||||
|
||||
|
||||
*Quantifiers* \
|
||||
Quantifiers specify how many of a character to match. \
|
||||
There are four of these: `+`, `*`, `?`, and `{ }`.
|
||||
|
||||
#v(4mm)
|
||||
|
||||
`+` means "match one or more of the preceding token" \
|
||||
`*` means "match zero or more of the preceding token"
|
||||
|
||||
For example, the pattern `ca+t` will match the following strings:
|
||||
- `cat`
|
||||
- `caat`
|
||||
- `caaaaaaaat`
|
||||
`ca+t` will *not* match the string `ct`. \
|
||||
The pattern `ca*t` will match all the strings above, including `ct`.
|
||||
|
||||
|
||||
#v(4mm)
|
||||
|
||||
|
||||
`?` means "match one or none of the preceding token" \
|
||||
The pattern `linea?r` will match only `linear` and `liner`.
|
||||
|
||||
#v(4mm)
|
||||
|
||||
Brackets `{min, max}` are the most flexible quantifier. \
|
||||
They specify exactly how many tokens to match: \
|
||||
`ab{2}a` will match only `abba`. \
|
||||
`ab{1,3}a` will match only `aba`, `abba`, and `abbba`. \
|
||||
`ab{2,}a` will match any `ab...ba` with at least two `b`s.
|
||||
|
||||
#problem()
|
||||
Write the patterns `a*` and `a+` using only `{ }`.
|
||||
#v(1fr)
|
||||
|
||||
#problem()
|
||||
Draw a DFA equivalent to the regex pattern `01*0`.
|
||||
#v(1fr)
|
||||
|
||||
#pagebreak()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
*Characters, Sets, and Groups* \
|
||||
In the previous section, we saw how we can specify characters literally: \
|
||||
`a+` means "one or more `a` characters" \
|
||||
There are, of course, other ways we can specify characters.
|
||||
|
||||
#v(4mm)
|
||||
|
||||
The first such way is the _set_, denoted `[ ]`. A set can pretend to be any character inside it. \
|
||||
For example, `m[aoy]th` will match `math`, `moth`, or `myth`. \
|
||||
`a[01]+b` will match `a0b`, `a111b`, `a1100110b`, and any other similar string. \
|
||||
|
||||
#v(4mm)
|
||||
|
||||
We can negate a set with a `^`. \
|
||||
`[^abc]` will match any single character except `a`, `b`, or `c`, including symbols and spaces.
|
||||
|
||||
#v(4mm)
|
||||
|
||||
If we want to keep characters together, we can use the _group_, denoted `( )`. \
|
||||
|
||||
Groups work exactly as you'd expect, representing an atomic#footnote([In other words, "unbreakable"]) group of characters. \
|
||||
`a(01)+b` will match `a01b` and `a010101b`, but will *not* match `a0b`, `a1b`, or `a1100110b`.
|
||||
|
||||
#problem()
|
||||
You are now familiar with most of the tools regex has to offer. \
|
||||
Write patterns that match the following strings:
|
||||
|
||||
- An ISO-8601 date, like `2022-10-29`. \
|
||||
#hint([Invalid dates like `2022-13-29` should also be matched.])
|
||||
|
||||
- An email address. \
|
||||
#hint([Don't forget about subdomains, like `math.ucla.edu`.])
|
||||
|
||||
- A UCLA room number, like `MS 5118` or `Kinsey 1220B`.
|
||||
|
||||
- Any ISBN-10 of the form `0-316-00395-7`. \
|
||||
#hint([Remember that the check digit may be an `X`. Dashes are optional.])
|
||||
|
||||
- A word of even length. \
|
||||
#hint([The set `[A-z]` contains every english letter, capitalized and lowercase. \
|
||||
`[a-z]` will only match lowercase letters.])
|
||||
|
||||
- A word with exactly 3 vowels. \
|
||||
#hint([The special token `\w` will match any word character. \
|
||||
It is equivalent to `[A-z0-9_]`. `_` represents a literal underscore.
|
||||
])
|
||||
|
||||
- A word that has even length and exactly 3 vowels.
|
||||
|
||||
- A sentence that does not start with a capital letter.
|
||||
#v(1fr)
|
||||
|
||||
#problem()
|
||||
If you'd like to know more, check out `https://regexr.com`.
|
||||
It offers an interactive regex prompt,
|
||||
as well as a cheatsheet that explains every other regex token there is. \
|
||||
You can find a nice set of challenges at `https://alf.nu/RegexGolf`.
|
@ -1,30 +0,0 @@
|
||||
\documentclass[
|
||||
solutions,
|
||||
singlenumbering,
|
||||
nopagenumber
|
||||
]{../../../lib/tex/ormc_handout}
|
||||
\usepackage{../../../lib/tex/macros}
|
||||
|
||||
\title{Warm-Up: Travellers}
|
||||
\uptitler{\smallurl{}}
|
||||
\subtitle{Prepared by Mark on \today}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
\problem{}
|
||||
Four travellers are on a plane, each moving along a straight line at an arbitrary constant speed. \par
|
||||
No two of their paths are parallel, and no three intersect at the same point. \par
|
||||
We know that traveller A has met travelers B, C, and D, \par
|
||||
and that traveller B has met C and D (and A). Show that C and D must also have met. \par
|
||||
|
||||
\begin{solution}
|
||||
When a body travels at a constant speed, its graph with respect to time is a straight line. \par
|
||||
So, we add time axis in the third dimension, perpendicular to our plane. \par
|
||||
Naturally, the projection of each of these onto the plane corresponds to a road.
|
||||
|
||||
Now, note that two intersecting lines define a plane and use the conditions in the problem to show that no two lines are parallel.
|
||||
\end{solution}
|
||||
|
||||
\end{document}
|
26
src/Warm-Ups/Travellers/main.typ
Normal file
26
src/Warm-Ups/Travellers/main.typ
Normal file
@ -0,0 +1,26 @@
|
||||
#import "@local/handout:0.1.0": *
|
||||
|
||||
#show: doc => handout(
|
||||
doc,
|
||||
quarter: link(
|
||||
"https://betalupi.com/handouts",
|
||||
"betalupi.com/handouts",
|
||||
),
|
||||
|
||||
title: [Warm-Up: Travellers],
|
||||
by: "Mark",
|
||||
)
|
||||
|
||||
#problem()
|
||||
Four travellers are on a plane, each moving along a straight line at an arbitrary constant speed. \
|
||||
No two of their paths are parallel, and no three intersect at the same point. \
|
||||
We know that traveller A has met travelers B, C, and D, \
|
||||
and that traveller B has met C and D (and A). Show that C and D must also have met.
|
||||
|
||||
#solution([
|
||||
When a body travels at a constant speed, its graph with respect to time is a straight line. \
|
||||
So, we add time axis in the third dimension, perpendicular to our plane. \
|
||||
Naturally, the projection of each of these onto the plane corresponds to a road.
|
||||
|
||||
Now, note that two intersecting lines define a plane and use the conditions in the problem to show that no two lines are parallel.
|
||||
])
|
@ -1,22 +0,0 @@
|
||||
\documentclass[
|
||||
solutions,
|
||||
hidewarning,
|
||||
singlenumbering,
|
||||
nopagenumber
|
||||
]{../../../lib/tex/ormc_handout}
|
||||
\usepackage{../../../lib/tex/macros}
|
||||
|
||||
|
||||
\title{Warm-Up: \texttt{fmod}}
|
||||
\uptitler{\smallurl{}}
|
||||
\subtitle{Prepared by Mark on \today.}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
\problem{}
|
||||
I'm sure you're all familiar with how \texttt{mod(a, b)} and \texttt{remainder(a, b)} work with integers. \par
|
||||
Devise an equivalent for floats (i.e, real numbers).
|
||||
|
||||
\end{document}
|
16
src/Warm-Ups/fmod/main.typ
Normal file
16
src/Warm-Ups/fmod/main.typ
Normal file
@ -0,0 +1,16 @@
|
||||
#import "@local/handout:0.1.0": *
|
||||
|
||||
#show: doc => handout(
|
||||
doc,
|
||||
quarter: link(
|
||||
"https://betalupi.com/handouts",
|
||||
"betalupi.com/handouts",
|
||||
),
|
||||
|
||||
title: [Warm-Up: `fmod`],
|
||||
by: "Mark",
|
||||
)
|
||||
|
||||
#problem()
|
||||
I'm sure you're all familiar with how `mod(a, b)` and `remainder(a, b)` \ work when `a` and `b` are integers.
|
||||
Devise an equivalent for floats (i.e, real numbers).
|
@ -143,10 +143,12 @@ def build_typst(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
||||
[
|
||||
TYPST_PATH,
|
||||
"compile",
|
||||
"--package-path",
|
||||
f"{ROOT}/lib/typst",
|
||||
"--ignore-system-fonts",
|
||||
"main.typ",
|
||||
"--input",
|
||||
"show_solutions=false",
|
||||
"main.typ",
|
||||
f"{out}/{handout_file}",
|
||||
],
|
||||
cwd=source_dir,
|
||||
@ -164,6 +166,8 @@ def build_typst(source_dir: Path, out_subdir: Path) -> IndexEntry | None:
|
||||
[
|
||||
TYPST_PATH,
|
||||
"compile",
|
||||
"--package-path",
|
||||
f"{ROOT}/lib/typst",
|
||||
"--ignore-system-fonts",
|
||||
"main.typ",
|
||||
f"{out}/{solutions_file}",
|
||||
|
Loading…
x
Reference in New Issue
Block a user