Compare commits
4 Commits
d0242271dd
...
7ce1aaa26b
Author | SHA1 | Date | |
---|---|---|---|
7ce1aaa26b | |||
781cb86e8c | |||
7c0f811414 | |||
3267f00838 |
@ -91,7 +91,7 @@
|
||||
|
||||
let url = link(
|
||||
"https://betalupi.com/handouts",
|
||||
"betalupi.com/handouts",
|
||||
`betalupi.com/handouts`,
|
||||
)
|
||||
|
||||
make_header(
|
||||
|
@ -1,80 +0,0 @@
|
||||
\documentclass[
|
||||
solutions,
|
||||
singlenumbering,
|
||||
nopagenumber
|
||||
]{../../../lib/tex/ormc_handout}
|
||||
\usepackage{../../../lib/tex/macros}
|
||||
|
||||
\title{Warm-Up: The Painting}
|
||||
\uptitler{\smallurl{}}
|
||||
\subtitle{Prepared by Mark on \today.}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
\problem{}
|
||||
You have a painting on a string. \par
|
||||
Hang the painting on two nails so that if either is removed, the painting falls. \par
|
||||
|
||||
\vspace{2mm}
|
||||
You may detach the string as you hang the painting, but it must be re-attached once you're done.
|
||||
|
||||
\note{The solution to this problem isn't a \say{think outside the box} trick, it's a clever wrapping of the string.}
|
||||
|
||||
|
||||
\begin{center}
|
||||
\begin{tikzpicture}[scale=2.0]
|
||||
\draw[line width = 0.5mm]
|
||||
(0, 1) --
|
||||
(2, 1) --
|
||||
(2, 0) --
|
||||
(0, 0) --
|
||||
cycle
|
||||
;
|
||||
|
||||
\draw[line width = 0.5mm, dotted]
|
||||
(0.1, 1) --
|
||||
(1, 1.5) --
|
||||
(1.9, 1)
|
||||
;
|
||||
|
||||
\fill (1, 1.5) circle[radius = 0.25mm];
|
||||
|
||||
|
||||
\draw[line width = 0.2mm]
|
||||
(0.66, 0.66) --
|
||||
(0.66, 0.35) --
|
||||
(0.60, 0.1)
|
||||
(0.72, 0.1)--(0.66, 0.35)
|
||||
;
|
||||
|
||||
\draw[line width = 0.2mm]
|
||||
(0.66, 0.575) --
|
||||
(0.6, 0.475) --
|
||||
(0.525, 0.575)
|
||||
(0.66, 0.575) --
|
||||
(0.72, 0.475) --
|
||||
(0.795, 0.575)
|
||||
;
|
||||
|
||||
\fill[color=white] (0.66, 0.66) circle[radius = 0.8mm];
|
||||
\draw (0.66, 0.66) circle[radius = 0.8mm];
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
|
||||
\begin{solution}
|
||||
|
||||
Say we have a left nail and a right nail. The path of the string is as follows:
|
||||
\begin{itemize}
|
||||
\item Start on the left
|
||||
\item Move over both nails, wrap right nail cw
|
||||
\item Wrap left nail ccw
|
||||
\item Wrap right nail ccw
|
||||
\item Exit downwards, in between both nails
|
||||
\end{itemize}
|
||||
|
||||
\end{solution}
|
||||
|
||||
\end{document}
|
82
src/Warm-Ups/Painting/main.typ
Normal file
82
src/Warm-Ups/Painting/main.typ
Normal file
@ -0,0 +1,82 @@
|
||||
#import "@local/handout:0.1.0": *
|
||||
#import "@preview/cetz:0.3.1"
|
||||
|
||||
#show: handout.with(
|
||||
title: [Warm-Up: What's an AST?],
|
||||
by: "Mark",
|
||||
subtitle: "Based on a true story.",
|
||||
)
|
||||
|
||||
#problem()
|
||||
Say we have a painting on a string. \
|
||||
Hang the painting on two nails so that if either is removed, the painting falls. \
|
||||
|
||||
#v(2mm)
|
||||
You may detach the string as you hang the painting, but it must be re-attached once you're done. \
|
||||
#hint[The solution to this problem isn't a "think outside the box" trick, it's a clever wrapping of the string.]
|
||||
|
||||
|
||||
#v(2mm)
|
||||
|
||||
#align(
|
||||
center,
|
||||
cetz.canvas({
|
||||
import cetz.draw: *
|
||||
let s = 2.5
|
||||
|
||||
|
||||
line(
|
||||
(0 * s, 1 * s),
|
||||
(2 * s, 1 * s),
|
||||
(2 * s, 0 * s),
|
||||
(0 * s, 0 * s),
|
||||
close: true,
|
||||
stroke: (thickness: 0.8mm),
|
||||
)
|
||||
|
||||
line(
|
||||
(0.1 * s, 1 * s),
|
||||
(0.5 * s, 1.5 * s),
|
||||
(1.5 * s, 1.5 * s),
|
||||
(1.9 * s, 1 * s),
|
||||
stroke: (thickness: 0.5mm, dash: "dotted"),
|
||||
)
|
||||
|
||||
circle((0.5 * s, 1.5 * s), radius: 0.04 * s, fill: black, stroke: none)
|
||||
circle((1.5 * s, 1.5 * s), radius: 0.04 * s, fill: black, stroke: none)
|
||||
|
||||
line(
|
||||
(0.66 * s, 0.66 * s),
|
||||
(0.66 * s, 0.35 * s),
|
||||
(0.60 * s, 0.1 * s),
|
||||
)
|
||||
|
||||
line(
|
||||
(0.72 * s, 0.1 * s),
|
||||
(0.66 * s, 0.35 * s),
|
||||
)
|
||||
|
||||
line(
|
||||
(0.66 * s, 0.575 * s),
|
||||
(0.6 * s, 0.475 * s),
|
||||
(0.525 * s, 0.575 * s),
|
||||
)
|
||||
|
||||
line(
|
||||
(0.66 * s, 0.575 * s),
|
||||
(0.72 * s, 0.475 * s),
|
||||
(0.795 * s, 0.575 * s),
|
||||
)
|
||||
|
||||
circle((0.66 * s, 0.66 * s), radius: 0.07 * s, fill: white)
|
||||
}),
|
||||
)
|
||||
|
||||
#solution([
|
||||
Say we have a left nail and a right nail. The path of the string is as follows:
|
||||
- Start on the left
|
||||
- Move over both nails, wrap right nail cw
|
||||
- Wrap left nail ccw
|
||||
- Wrap right nail ccw
|
||||
- Exit downwards, in between both nails
|
||||
])
|
@ -1,89 +0,0 @@
|
||||
\documentclass[
|
||||
solutions,
|
||||
hidewarning,
|
||||
singlenumbering,
|
||||
nopagenumber
|
||||
]{../../../lib/tex/ormc_handout}
|
||||
\usepackage{../../../lib/tex/macros}
|
||||
|
||||
|
||||
|
||||
\usepackage{tikz}
|
||||
|
||||
|
||||
\title{The Sysadmin's Warm-Up}
|
||||
\uptitler{\smallurl{}}
|
||||
\subtitle{Prepared by Mark on \today}
|
||||
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
|
||||
Most of you have seen a hard drive. Many have touched one, and a lucky few have poked around inside one. These devices have two interesting properties:
|
||||
|
||||
\begin{enumerate}
|
||||
\item They hold valuable data
|
||||
\item They eventually fail
|
||||
\end{enumerate}
|
||||
|
||||
Needless to say, this is a problem. \par
|
||||
We need to design a system that allows hard drives to fail without data loss.
|
||||
|
||||
\definition{}
|
||||
You can think of a hard drive as a long string of bits. \par
|
||||
Assume all hard drives can store 1 TiB of data.
|
||||
|
||||
\begin{center}
|
||||
\begin{tikzpicture}
|
||||
|
||||
\node[above] at (1/2, 0) {Drive A};
|
||||
\draw (0cm, 0cm) -- (0cm, -3cm);
|
||||
\draw (1cm, 0cm) -- (1cm, -3cm);
|
||||
\foreach \i in {0,...,-6} {
|
||||
\draw (0cm,\i cm / 2) -- (1cm ,\i cm / 2);
|
||||
}
|
||||
|
||||
\node at (1/2, - 1 / 4) {1};
|
||||
\node at (1/2, - 3 / 4) {1};
|
||||
\node at (1/2, - 5 / 4) {0};
|
||||
\node at (1/2, - 7 / 4) {...};
|
||||
\node at (1/2, - 9 / 4) {1};
|
||||
\node at (1/2, -11 / 4) {0};
|
||||
|
||||
|
||||
\node[above] at (5/2, 0) {Drive B};
|
||||
\draw (2cm, 0cm) -- (2cm, -3cm);
|
||||
\draw (3cm, 0cm) -- (3cm, -3cm);
|
||||
\foreach \i in {0,...,-6} {
|
||||
\draw (2cm,\i cm / 2) -- (3cm ,\i cm / 2);
|
||||
}
|
||||
|
||||
\node at (5/2, - 1 / 4) {0};
|
||||
\node at (5/2, - 3 / 4) {1};
|
||||
\node at (5/2, - 5 / 4) {0};
|
||||
\node at (5/2, - 7 / 4) {...};
|
||||
\node at (5/2, - 9 / 4) {0};
|
||||
\node at (5/2, -11 / 4) {1};
|
||||
\end{tikzpicture}
|
||||
\end{center}
|
||||
|
||||
\problem{}
|
||||
Suppose we have two hard drives. How can we arrange our data so that...
|
||||
\begin{enumerate}
|
||||
\item We get 1 TiB of usable storage
|
||||
\item We lose no data if any one drive fails
|
||||
\end{enumerate}
|
||||
|
||||
\vfill
|
||||
|
||||
\problem{}
|
||||
Suppose we have three hard drives. How can we arrange our data so that...
|
||||
\begin{enumerate}
|
||||
\item We get 2 TiB of usable storage
|
||||
\item We lose no data if any one drive fails
|
||||
\end{enumerate}
|
||||
|
||||
\vfill
|
||||
\end{document}
|
35
src/Warm-Ups/Sysadmin/main.typ
Normal file
35
src/Warm-Ups/Sysadmin/main.typ
Normal file
@ -0,0 +1,35 @@
|
||||
#import "@local/handout:0.1.0": *
|
||||
|
||||
#show: handout.with(
|
||||
title: [The Sysadmin's Warm-Up],
|
||||
by: "Mark",
|
||||
)
|
||||
|
||||
Most of you have seen a hard drive. \
|
||||
Many have touched one, and a lucky few have taken one apart. \
|
||||
These devices have two interesting properties:
|
||||
- They hold valuable data
|
||||
- They inevitably fail
|
||||
|
||||
Needless to say, this is a problem. \
|
||||
We would like to design a system that tolerates hard drive failures without data loss.
|
||||
|
||||
#definition()
|
||||
You can think of a hard drive as a long string of bits. \
|
||||
Assume all hard drives in the following problems have the same size. \
|
||||
If a hard drive "fails", all data on it is instantly lost.
|
||||
|
||||
#problem()
|
||||
Suppose we have two hard drives. How can we arrange our data so that...
|
||||
- We get 1 TiB of usable storage
|
||||
- We lose no data if any one drive fails
|
||||
|
||||
#v(1fr)
|
||||
|
||||
#problem()
|
||||
Suppose we have three hard drives. How can we arrange our data so that...
|
||||
- We get 2 TiB of usable storage
|
||||
- We lose no data if any one drive fails
|
||||
|
||||
#v(1fr)
|
||||
|
@ -1,43 +0,0 @@
|
||||
\documentclass[
|
||||
solutions,
|
||||
hidewarning,
|
||||
singlenumbering,
|
||||
nopagenumber
|
||||
]{../../../lib/tex/ormc_handout}
|
||||
\usepackage{../../../lib/tex/macros}
|
||||
|
||||
|
||||
\usepackage[linguistics]{forest}
|
||||
|
||||
|
||||
|
||||
\title{Warm-Up: What's an AST?}
|
||||
\uptitler{\smallurl{}}
|
||||
\subtitle{Prepared by Mark on \today. \\ Based on a true story.}
|
||||
|
||||
\begin{document}
|
||||
|
||||
\maketitle
|
||||
|
||||
Say you have a valid string of simple arithmetic that contains no unary operators (like $3!$ or $-4$) and no parenthesis:
|
||||
$$
|
||||
3 + 9 \times 8 \div 5 \land 6
|
||||
$$
|
||||
|
||||
You may assume that all numbers and operators in this string consist of exactly one character. \\
|
||||
|
||||
Devise an algorithm that turns this string into a tree (as shown below), respecting the order of operations $[\land, \times, \div, +, -]$.
|
||||
|
||||
\begin{center}
|
||||
\begin{forest}
|
||||
[$+$
|
||||
[3]
|
||||
[$\div$
|
||||
[$\times$[9][8]]
|
||||
[$\land$[5][6]]
|
||||
]
|
||||
]
|
||||
\end{forest}
|
||||
\end{center}
|
||||
|
||||
\end{document}
|
74
src/Warm-Ups/What's an AST/main.typ
Normal file
74
src/Warm-Ups/What's an AST/main.typ
Normal file
@ -0,0 +1,74 @@
|
||||
#import "@local/handout:0.1.0": *
|
||||
#import "@preview/cetz:0.3.1"
|
||||
|
||||
#show: handout.with(
|
||||
title: [Warm-Up: What's an AST?],
|
||||
by: "Mark",
|
||||
subtitle: "Based on a true story.",
|
||||
)
|
||||
|
||||
#problem()
|
||||
Say we have a valid string of simple arithmetic that contains \
|
||||
no unary operators (like $3!$ or $-4$) and no parenthesis:
|
||||
|
||||
#v(2mm)
|
||||
$
|
||||
3 + 9 times 8 div 5 and 6
|
||||
$
|
||||
#v(2mm)
|
||||
|
||||
You may assume that all numbers and operators in this string consist of exactly one character. \
|
||||
|
||||
Devise an algorithm that turns such strings into a tree (as shown below), \
|
||||
respecting the order of operations $[and, times, div, +, -]$.
|
||||
|
||||
#v(2mm)
|
||||
|
||||
#align(
|
||||
center,
|
||||
cetz.canvas({
|
||||
import cetz.draw: *
|
||||
|
||||
// spell:off
|
||||
content((0, 0), $+$, name: "r")
|
||||
content((-0.5, -1), $3$, name: "a")
|
||||
content((0.5, -1), $div$, name: "b")
|
||||
content((-0.3, -2), $times$, name: "ba")
|
||||
content((1.3, -2), $and$, name: "bb")
|
||||
content((-0.8, -3), $9$, name: "baa")
|
||||
content((0.2, -3), $8$, name: "bab")
|
||||
content((0.8, -3), $5$, name: "bba")
|
||||
content((1.8, -3), $6$, name: "bbb")
|
||||
// spell:on
|
||||
|
||||
// Zero-sized arrows are a hack for offset.
|
||||
set-style(
|
||||
stroke: (thickness: 0.3mm),
|
||||
mark: (
|
||||
start: (
|
||||
symbol: "|",
|
||||
offset: 0.25,
|
||||
width: 0mm,
|
||||
length: 0mm,
|
||||
),
|
||||
end: (
|
||||
symbol: "|",
|
||||
offset: 0.25,
|
||||
width: 0mm,
|
||||
length: 0mm,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
// spell:off
|
||||
line("r", "a")
|
||||
line("r", "b")
|
||||
line("b", "ba")
|
||||
line("b", "bb")
|
||||
line("ba", "baa")
|
||||
line("ba", "bab")
|
||||
line("bb", "bba")
|
||||
line("bb", "bbb")
|
||||
// spell:on
|
||||
}),
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user