Skip to content

Commit

Permalink
added mini-challenge materials
Browse files Browse the repository at this point in the history
  • Loading branch information
Levelent committed Apr 29, 2022
1 parent 2cf1318 commit bdb7749
Show file tree
Hide file tree
Showing 20 changed files with 73,247 additions and 18 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/pdf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
root_file: |
2021-11-24/21_11_24_problems.tex
2022-02-16/22_02_16_problems.tex
2022-Mini/mini_problems.tex
work_in_root_file_dir: true

- name: Upload Artifacts
Expand All @@ -24,4 +25,5 @@ jobs:
name: UWCS Programming Problem Sets
path: |
2021-11-24/21_11_24_problems.pdf
2022-02-16/22_02_16_problems.pdf
2022-02-16/22_02_16_problems.pdf
2022-Mini/mini_problems.pdf
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,5 @@ TSWLatexianTemp*
*.lpz

# Testing scripts
**/script.py
**/script.py
**/output.txt
29 changes: 29 additions & 0 deletions 2021-11-24/2/sol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
tests = int(input())

for _ in range(tests):
x1, y1, x2, y2, ax, ay, bx, by = [int(s) for s in input().split()]
blocked = [(ax, ay), (bx, by)]

x_dist = abs(x1 - x2)
y_dist = abs(y1 - y2)

dist = abs(x1 - x2) + abs(y1 - y2) # taxicab distance

if x_dist == 0:
# If a or b in between shortest path
if (ax == x1 and min(y1, y2) < ay < max(y1, y2)) or (bx == x1 and min(y1, y2) < by < max(y1, y2)):
dist += 2 # add 2 to taxicab distance

elif y_dist == 0:
# If a or b in between shortest path
if (ay == y1 and min(x1, x2) < ax < max(x1, x2)) or (by == y1 and min(x1, x2) < bx < max(x1, x2)):
dist += 2 # add 2 to taxicab distance

if x_dist >= 2 and y_dist >= 2:
# only need to check adjacent tiles of start and end
pass

print(dist)



11 changes: 11 additions & 0 deletions 2022-Mini/0/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
10
BABA ABBA
ORANGE CHERRY
MOUNTAINEERS ENUMERATIONS
HE EH
FOUR FOAL
SWORD WORDS
BANANA BATMAN
MANKINI COMPANY
SUBTRACTIONS OBSCURANTIST
UNDEMOCRATISE DOCUMENTARIES
136 changes: 136 additions & 0 deletions 2022-Mini/0/problem.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
\addcontentsline{toc}{subsection}{Anagram}
\LARGE \circled{0} \textbf{Example Problem - Anagram} \normalsize

{\itshape A Rag Man.}

This problem is intended to get you familiar with how submission works.

A pair of strings are called anagrams of each other if they share the same letters, but in a different order.
Your task: determine whether given pairs of strings are anagrams.

\vspace{8pt}
\hrule

\textbf{Input}

The first line of the input contains an integer $t$, denoting the number of test cases.

The next $t$ lines of the input consist of two space-separated strings $w_1$ and $w_2$.

\textbf{Constraints}

\begin{itemize}
\item $1 \leq t \leq 10$
\item $1 \leq |w_1| = |w_2| \leq 13$
\item $w_1$ and $w_2$ will be uppercase.
\end{itemize}

\textbf{Output}

$t$ lines each consisting of either "Yes" if the strings are anagrams, or "No" if they're not.

\vspace{8pt}
\hrule

\textbf{Example}

\begin{table}[h]
\centering
\begin{tabular}{|p{0.4\linewidth}|p{0.4\linewidth}|}
\hline
Input & Output \\
\hline
3 \newline BABA ABBA \newline ORANGE CHERRY \newline MOUNTAINEERS ENUMERATIONS &
\text{} \newline Yes \newline No \newline Yes \\
\hline
\end{tabular}
\end{table}

Note that we have one output line for each of the test cases.

Feel free to give the problem a try yourself!
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.
These are given for Python and Java, to show the differences.

Once you feel comfortable, let's move onto the first real problem!

\newpage

\textbf{Solutions and Submission}

\lstset{language=python}
\begin{lstlisting}
#!/usr/bin/env python

t = int(input()) # Get number of test cases

for _ in range(t):
# Get the two words
w1, w2 = input().split()

# Convert to sorted character arrays
s1 = sorted(w1)
s2 = sorted(w2)

# Compare the arrays
if s1 == s2:
print("Yes")
else:
print("No")

\end{lstlisting}

\small
\texttt{./ProgcompCli 0 sol.py} on Mac or Linux, with a shebang. \\
\texttt{.\textbackslash ProgcompCli.exe 0 python.exe -{}-executable-args sol.py} on Windows (remove \texttt{.exe} otherwise).

\vspace{8pt}
\hrule

\lstset{language=java}
\begin{lstlisting}
import java.io.*;
import java.util.*;

public class Solution {
public static void main(String[] args) {
// Allows us to read from stdin
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

// Get number of test cases
int t = 0;
try {
t = Integer.parseInt(br.readLine());
} catch (IOException ex) {}

String word1, word2;
for (int i = 0; i < t; i++) { // Repeat for number of test cases
// Get words
try {
String line = br.readLine();
String[] split = line.split(" ");
word1 = split[0];
word2 = split[1];
} catch (IOException ex) { continue; }

// Sort arrays
char[] arr1 = word1.toCharArray();
Arrays.sort(arr1);
char[] arr2 = word2.toCharArray();
Arrays.sort(arr2);

// Compare arrays
if (Arrays.equals(arr1, arr2)) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
}
}
\end{lstlisting}

\texttt{.\textbackslash ProgcompCli.exe 0 java -{}-executable-args Solution} on Windows (remove \texttt{.exe} otherwise).
\\ Make sure to compile it first with \texttt{javac}!

\normalsize
17 changes: 17 additions & 0 deletions 2022-Mini/0/sol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python

t = int(input()) # Get number of test cases

for _ in range(t):
# Get the two words
w1, w2 = input().split()

# Convert to sorted character arrays
s1 = sorted(w1)
s2 = sorted(w2)

# Compare the arrays
if s1 == s2:
print("Yes")
else:
print("No")
6 changes: 6 additions & 0 deletions 2022-Mini/1/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
5
READ REED
ZERO HERO
PAID FEED
WORDS SWORD
REDDIT CRINGE
22 changes: 22 additions & 0 deletions 2022-Mini/1/gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import random

i = 1

lines = []
for _ in range(30000):
s = input().split()[0]
if s.isascii() and s.isalpha():
lines.append(s.upper())

words = [w.upper() for w in lines]

# print(len(lines))

print(10000)

for k in range(4, 14):
x = list(filter(lambda s: len(s) == k, words))
for _ in range(1000):
w1 = random.choice(x)
w2 = random.choice(x)
print(w1, w2)
Loading

0 comments on commit bdb7749

Please sign in to comment.