Skip to content

Commit 8629c8a

Browse files
committed
Add assignment 2
1 parent e856743 commit 8629c8a

23 files changed

+774
-0
lines changed

assign2/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Assignment 2: Quest for the 🦄
2+
**Due Midnight, Friday of Week 7**
3+
4+
## Overview
5+
As you likely recall, in dramatic fashion, the brand new course mascot was stolen during Monday's lecture! The kidnappers have hidden the unicorn at a location on-campus. In this assignment, you will undertake a quest to recover the unicorn.
6+
7+
In this assignment, the first person (or team) to find the unicorn gets **free late night on the staff** and **a perfect score for this assignment**!
8+
9+
* *Expected time: 6 hours*
10+
* *Max time: 8 hours*
11+
12+
Note: It's always a good idea to get started early! We want you to enjoy the beautiful Stanford weather, as a nice break from midterms, and have some fun solving small puzzles.
13+
14+
A few notes before we begin!
15+
16+
1. The unicorn is hidden **in a bush**. You'll likely only get a rough estimation of where the unicorn is, so you'll need to dig around a bit! If you think you're very close and have looked but haven't found the unicorn, you can call Parth.
17+
2. TAKE PICTURES! Take lots of pictures throughout the assignment but, in particular, take pictures once you've found the unicorn / where the unicorn used to be :)
18+
19+
There are multiple ways to find the unicorn, which are detailed below.
20+
21+
## Paths to the Unicorn
22+
There are several ways to obtain the location of the unicorn, described by the image below:
23+
24+
<p style="align: center; max-width: 100%;">
25+
<img src="md_img/unicorn_paths.png" style="max-width: 100%" alt="The different paths to the unicorn." />
26+
</p>
27+
28+
Here's a text-based description of the image above, with more information about each piece:
29+
30+
One place to start is the `Pillow` (image) problem. This problem is more like a puzzle hunt than any of the other options, which means that it doesn't have a clear set of instructions to solve the puzzle. You'll have to use clues to figure out how to progress through this problem. The problem involves using the `Pillow` library to manipulate images (you also have to download those images and process them, so `requests` and `numpy` might be useful). *Note: This problem involves traveling around campus. If that poses any difficulties for you, please get in touch with us and we can help. Additionally, if viewing images poses any difficulties for you, let us know and we can help with that as well.* **The assignment spec for this problem is [img.md](img.md)**.
31+
32+
Another option to start out is with the `requests` problem. For this problem, you'll be put in the middle of a maze and you'll have to implement a search algorithm in Python to navigate the maze. The maze is hosted on our website, [https://stanfordpython.com](https://stanfordpython.com). You're only ever given information about the location that you're currently standing at, so you'll have to use `requests` and CS 106B knowledge to explore the entire maze. Periodically, at various points in the maze, you'll obtain information about the location of the unicorn. **The assignment spec for this problem is [requests.md](requests.md)**.
33+
34+
Both `Pillow` and `requests` "feed into" the `numpy` problem, which is the first data science/machine learning style problem of the quarter. To be more precise, once you finish either `Pillow` or `requests`, you should end up with a file called `unicorndata.pickle`. In the `numpy` problem, you'll analyze that data to find the latitude/longitude coordinates of the unicorn. Essentially, we have a bunch of data points with information about the unicorn's distance and we're trying to find a point that minimizes that distance. *Note: This is a mathematically non-trivial problem! It'll take some time to understand how it works. That said, there are detailed instructions on how to implement the assignment that should help you through it and try to explain the mathematics, even if you don't fully understand the math. Of course, we want you to have a productive learning experience, so we're always welcome to help out with this during office hours or on Piazza.* If you're interested in `Pillow` or `requests`, we'd recommend skimming through this assignment spec before you get too far into either of those, since we don't want anybody to get stuck on this portion. **The assignment spec for this problem is [triangulate.md](triangulate.md)**.
35+
36+
An entirely separate path to the unicorn is through the Row of Puzzles. This is designed to be easier, but longer. If you choose this path, you won't be doing as many technically advanced things, but you'll still be using most of the libraries that are used in the other portions of the assignment, namely `requests` and `numpy`, which we've been focusing on in class. In this problem, you'll have to solve some Python puzzle, which will lead you to another one, and to another one, on and on until you get a clue which leads you to the unicorn's location. We won't tell you how many puzzles there are in the Row of Puzzles, but we've designed this to be the slowest path to the unicorn (we expect this will take 6 hours). **The assignment spec for this problem is [row-of-puzzles.md](row-of-puzzles.md)**.
37+
38+
Finally, once you think you know the location of the unicorn, go and find it! The unicorn will have instructions about how to claim your winnings, if you're the first team to reach it. The unicorn is hidden **in a bush outside of a building**. *Note: Again, if this part of the assignment poses difficulties for you, let us know and we can help.*
39+
40+
## Submitting
41+
One person from your team should submit *all of the files you've created or modified* during the course of completing this assignment. First, give us a list of who's in your team and who'll be submitting the assignment on Paperless by filling out [this form](https://forms.gle/iQrmkX1SSJPSvQDd6).
42+
43+
Next, have one person submit the assignment on Paperless. See our [Paperless Submission Instructions](https://github.com/stanfordpython/python-handouts/blob/master/submitting-assignments.md) for more.
44+
45+
## Credit
46+
@psarin wrote `requests`, `triangulate`, and `img`. @coopermj and @antoniof provided invaluable feedback on `requests` and `img`. @psarin and @coopermj wrote `row-of-puzzles`. @theoculhane gave incredible feedback on one of the `row-of-puzzles`.
47+
48+
> With &#129412;s (although hopefully you'll win your own) by @psarin and @coopermj

assign2/img.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Path (b): Image Manipulation
2+
This path is more like a puzzle hunt than the others. The clues are going to be a little more vague.
3+
4+
First you need to download 150 images from our website. The images are hosted at the urls [https://stanfordpython.com/img/0.png](https://stanfordpython.com/img/0.png) through [https://stanfordpython.com/img/149.png](https://stanfordpython.com/img/0.png). For example, [https://stanfordpython.com/img/29.png](https://stanfordpython.com/img/29.png) hosts the thirtieth image:
5+
6+
<p style="align: center; max-width: 100%;">
7+
<img src="https://stanfordpython.com/img/29.png" style="max-width: 100%" alt="The thirtieth image in the image manipulation puzzle." />
8+
</p>
9+
10+
*Hint*: if you're trying to manually download each of the images, rethink your strategy.
11+
12+
The data you just downloaded contain almost all of the information needed to solve this problem. Each of the images, individually, will not help you, but the sum of their information will. I'll just outline **some** useful tips.
13+
14+
* If you want to do **some** image manipulation, `Pillow` is a useful library. We didn't talk about this much in class, but the documentation is here: [https://pillow.readthedocs.io/](https://pillow.readthedocs.io/).
15+
* Make sure you have `Pillow`, and not `PIL` installed. You install `Pillow` by running `pip install Pillow` at a command line. But, you import it in a script with `import PIL`. (*Note for the curious*: This is because `Pillow` is the fork of `PIL` that is still maintained, while `PIL` is no longer being maintaned).
16+
* Your development environment should be set up like this automatically if you followed our instructions at the beginning of the quarter.
17+
* **Some**times it's useful to interface between `Pillow` and `numpy` because images are really just arrays of pixels where each pixel has R, G, and B values. That makes them an `m x n x 3` array for an image of dimension `m x n`.
18+
* `np.asarray(im)` converts an image to a numpy array.
19+
* `Image.fromarray(a)` converts a numpy array to an image.
20+
* Beware! `Pillow` images can only come from `numpy` arrays that have data type `uint8`. You can convert any `numpy` array to have that data type with `a.astype(np.uint8)`.
21+
* There are a bunch of ways to convert characters to integers. One of the easiest ways is built into Python: `ord(ch)` returns an integer representing the Unicode code point of that character and `chr(i)` is the inverse. `chr(i)` returns the string representing a character whose Unicode code point is the integer `i`.
22+
23+
## Submitting
24+
25+
Put all of the code you used to solve this assignment into one file called `img.py`. It doesn't really have to be clean, since we expect you'll be doing most of your work in the interactive interpreter, but the code should be runnable. If you need to write different functions, each of which solves a piece of the assignment, please do that.
26+
27+
*Note*: Your code will still be graded on Pythonic style practices, but we'll be more lenient on the parts of Pythonic style that don't apply to code that you're writing in the interactive interpreter.

assign2/md_img/.ipynb_checkpoints/triangulation_plots-checkpoint.ipynb

Lines changed: 176 additions & 0 deletions
Large diffs are not rendered by default.

assign2/md_img/maze_vis.png

544 KB
Loading

assign2/md_img/p_3d.png

91.3 KB
Loading

assign2/md_img/p_alpha.png

2.38 KB
Loading

assign2/md_img/p_contour.png

58.1 KB
Loading

assign2/md_img/p_features.png

3.95 KB
Loading

assign2/md_img/p_general.png

2.38 KB
Loading

assign2/md_img/p_simplified.png

3.83 KB
Loading

0 commit comments

Comments
 (0)