Skip to content

Commit bdb7749

Browse files
committed
added mini-challenge materials
1 parent 2cf1318 commit bdb7749

File tree

20 files changed

+73247
-18
lines changed

20 files changed

+73247
-18
lines changed

.github/workflows/pdf.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
root_file: |
1717
2021-11-24/21_11_24_problems.tex
1818
2022-02-16/22_02_16_problems.tex
19+
2022-Mini/mini_problems.tex
1920
work_in_root_file_dir: true
2021

2122
- name: Upload Artifacts
@@ -24,4 +25,5 @@ jobs:
2425
name: UWCS Programming Problem Sets
2526
path: |
2627
2021-11-24/21_11_24_problems.pdf
27-
2022-02-16/22_02_16_problems.pdf
28+
2022-02-16/22_02_16_problems.pdf
29+
2022-Mini/mini_problems.pdf

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,5 @@ TSWLatexianTemp*
276276
*.lpz
277277

278278
# Testing scripts
279-
**/script.py
279+
**/script.py
280+
**/output.txt

2021-11-24/2/sol.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
tests = int(input())
2+
3+
for _ in range(tests):
4+
x1, y1, x2, y2, ax, ay, bx, by = [int(s) for s in input().split()]
5+
blocked = [(ax, ay), (bx, by)]
6+
7+
x_dist = abs(x1 - x2)
8+
y_dist = abs(y1 - y2)
9+
10+
dist = abs(x1 - x2) + abs(y1 - y2) # taxicab distance
11+
12+
if x_dist == 0:
13+
# If a or b in between shortest path
14+
if (ax == x1 and min(y1, y2) < ay < max(y1, y2)) or (bx == x1 and min(y1, y2) < by < max(y1, y2)):
15+
dist += 2 # add 2 to taxicab distance
16+
17+
elif y_dist == 0:
18+
# If a or b in between shortest path
19+
if (ay == y1 and min(x1, x2) < ax < max(x1, x2)) or (by == y1 and min(x1, x2) < bx < max(x1, x2)):
20+
dist += 2 # add 2 to taxicab distance
21+
22+
if x_dist >= 2 and y_dist >= 2:
23+
# only need to check adjacent tiles of start and end
24+
pass
25+
26+
print(dist)
27+
28+
29+

2022-Mini/0/input.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
10
2+
BABA ABBA
3+
ORANGE CHERRY
4+
MOUNTAINEERS ENUMERATIONS
5+
HE EH
6+
FOUR FOAL
7+
SWORD WORDS
8+
BANANA BATMAN
9+
MANKINI COMPANY
10+
SUBTRACTIONS OBSCURANTIST
11+
UNDEMOCRATISE DOCUMENTARIES

2022-Mini/0/problem.tex

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
\addcontentsline{toc}{subsection}{Anagram}
2+
\LARGE \circled{0} \textbf{Example Problem - Anagram} \normalsize
3+
4+
{\itshape A Rag Man.}
5+
6+
This problem is intended to get you familiar with how submission works.
7+
8+
A pair of strings are called anagrams of each other if they share the same letters, but in a different order.
9+
Your task: determine whether given pairs of strings are anagrams.
10+
11+
\vspace{8pt}
12+
\hrule
13+
14+
\textbf{Input}
15+
16+
The first line of the input contains an integer $t$, denoting the number of test cases.
17+
18+
The next $t$ lines of the input consist of two space-separated strings $w_1$ and $w_2$.
19+
20+
\textbf{Constraints}
21+
22+
\begin{itemize}
23+
\item $1 \leq t \leq 10$
24+
\item $1 \leq |w_1| = |w_2| \leq 13$
25+
\item $w_1$ and $w_2$ will be uppercase.
26+
\end{itemize}
27+
28+
\textbf{Output}
29+
30+
$t$ lines each consisting of either "Yes" if the strings are anagrams, or "No" if they're not.
31+
32+
\vspace{8pt}
33+
\hrule
34+
35+
\textbf{Example}
36+
37+
\begin{table}[h]
38+
\centering
39+
\begin{tabular}{|p{0.4\linewidth}|p{0.4\linewidth}|}
40+
\hline
41+
Input & Output \\
42+
\hline
43+
3 \newline BABA ABBA \newline ORANGE CHERRY \newline MOUNTAINEERS ENUMERATIONS &
44+
\text{} \newline Yes \newline No \newline Yes \\
45+
\hline
46+
\end{tabular}
47+
\end{table}
48+
49+
Note that we have one output line for each of the test cases.
50+
51+
Feel free to give the problem a try yourself!
52+
However, the main goal of this is for you to understand the submission system, so I've given some example solutions on the next page, and ways to submit them.
53+
These are given for Python and Java, to show the differences.
54+
55+
Once you feel comfortable, let's move onto the first real problem!
56+
57+
\newpage
58+
59+
\textbf{Solutions and Submission}
60+
61+
\lstset{language=python}
62+
\begin{lstlisting}
63+
#!/usr/bin/env python
64+
65+
t = int(input()) # Get number of test cases
66+
67+
for _ in range(t):
68+
# Get the two words
69+
w1, w2 = input().split()
70+
71+
# Convert to sorted character arrays
72+
s1 = sorted(w1)
73+
s2 = sorted(w2)
74+
75+
# Compare the arrays
76+
if s1 == s2:
77+
print("Yes")
78+
else:
79+
print("No")
80+
81+
\end{lstlisting}
82+
83+
\small
84+
\texttt{./ProgcompCli 0 sol.py} on Mac or Linux, with a shebang. \\
85+
\texttt{.\textbackslash ProgcompCli.exe 0 python.exe -{}-executable-args sol.py} on Windows (remove \texttt{.exe} otherwise).
86+
87+
\vspace{8pt}
88+
\hrule
89+
90+
\lstset{language=java}
91+
\begin{lstlisting}
92+
import java.io.*;
93+
import java.util.*;
94+
95+
public class Solution {
96+
public static void main(String[] args) {
97+
// Allows us to read from stdin
98+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
99+
100+
// Get number of test cases
101+
int t = 0;
102+
try {
103+
t = Integer.parseInt(br.readLine());
104+
} catch (IOException ex) {}
105+
106+
String word1, word2;
107+
for (int i = 0; i < t; i++) { // Repeat for number of test cases
108+
// Get words
109+
try {
110+
String line = br.readLine();
111+
String[] split = line.split(" ");
112+
word1 = split[0];
113+
word2 = split[1];
114+
} catch (IOException ex) { continue; }
115+
116+
// Sort arrays
117+
char[] arr1 = word1.toCharArray();
118+
Arrays.sort(arr1);
119+
char[] arr2 = word2.toCharArray();
120+
Arrays.sort(arr2);
121+
122+
// Compare arrays
123+
if (Arrays.equals(arr1, arr2)) {
124+
System.out.println("Yes");
125+
} else {
126+
System.out.println("No");
127+
}
128+
}
129+
}
130+
}
131+
\end{lstlisting}
132+
133+
\texttt{.\textbackslash ProgcompCli.exe 0 java -{}-executable-args Solution} on Windows (remove \texttt{.exe} otherwise).
134+
\\ Make sure to compile it first with \texttt{javac}!
135+
136+
\normalsize

2022-Mini/0/sol.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env python
2+
3+
t = int(input()) # Get number of test cases
4+
5+
for _ in range(t):
6+
# Get the two words
7+
w1, w2 = input().split()
8+
9+
# Convert to sorted character arrays
10+
s1 = sorted(w1)
11+
s2 = sorted(w2)
12+
13+
# Compare the arrays
14+
if s1 == s2:
15+
print("Yes")
16+
else:
17+
print("No")

2022-Mini/1/example.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
5
2+
READ REED
3+
ZERO HERO
4+
PAID FEED
5+
WORDS SWORD
6+
REDDIT CRINGE

2022-Mini/1/gen.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import random
2+
3+
i = 1
4+
5+
lines = []
6+
for _ in range(30000):
7+
s = input().split()[0]
8+
if s.isascii() and s.isalpha():
9+
lines.append(s.upper())
10+
11+
words = [w.upper() for w in lines]
12+
13+
# print(len(lines))
14+
15+
print(10000)
16+
17+
for k in range(4, 14):
18+
x = list(filter(lambda s: len(s) == k, words))
19+
for _ in range(1000):
20+
w1 = random.choice(x)
21+
w2 = random.choice(x)
22+
print(w1, w2)

0 commit comments

Comments
 (0)