-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
2,013 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[{"due": "10/18/24", "link": "lab/lab07/", "name": "Lab 07: Object-Oriented Programming", "piazza_name": "Lab 07", "release": "10/14/24"}, {"due": "10/23/24", "link": "hw/hw07/", "name": "HW 07: Object-Oriented Programming", "piazza_name": "HW 07", "release": "10/16/24"}, {"due": "11/20/24", "link": "proj/ants/", "name": "Ants", "piazza_name": "Ants", "release": "10/16/24"}] | ||
[{"due": "10/23/24", "link": "hw/hw07/", "name": "HW 07: Object-Oriented Programming", "piazza_name": "HW 07", "release": "10/16/24"}, {"due": "10/25/24", "link": "lab/lab08/", "name": "Lab 08: Inheritance, Linked Lists", "piazza_name": "Lab 08", "release": "10/21/24"}, {"due": "11/20/24", "link": "proj/ants/", "name": "Ants", "piazza_name": "Ants", "release": "10/16/24"}] |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "Homework 6", | ||
"endpoint": "cal/c88c/fa24/hw06", | ||
"src": [ | ||
"hw06.py" | ||
], | ||
"tests": { | ||
"hw*.py": "doctest", | ||
"tests/*.py": "ok_test" | ||
}, | ||
"default_tests": [ | ||
"shuffle", | ||
"deep_map" | ||
], | ||
"protocols": [ | ||
"restore", | ||
"file_contents", | ||
"analytics", | ||
"help", | ||
"unlock", | ||
"grading", | ||
"backup" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
def shuffle(s): | ||
"""Return a shuffled list that interleaves the two halves of s. | ||
>>> shuffle(range(6)) | ||
[0, 3, 1, 4, 2, 5] | ||
>>> letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] | ||
>>> shuffle(letters) | ||
['a', 'e', 'b', 'f', 'c', 'g', 'd', 'h'] | ||
>>> shuffle(shuffle(letters)) | ||
['a', 'c', 'e', 'g', 'b', 'd', 'f', 'h'] | ||
>>> letters # Original list should not be modified | ||
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] | ||
""" | ||
assert len(s) % 2 == 0, 'len(seq) must be even' | ||
half = len(s) // 2 | ||
shuffled = [] | ||
for i in range(half): | ||
shuffled.append(s[i]) | ||
shuffled.append(s[half + i]) | ||
return shuffled | ||
|
||
|
||
def deep_map(f, s): | ||
"""Replace all non-list elements x with f(x) in the nested list s. | ||
>>> six = [1, 2, [3, [4], 5], 6] | ||
>>> deep_map(lambda x: x * x, six) | ||
>>> six | ||
[1, 4, [9, [16], 25], 36] | ||
>>> # Check that you're not making new lists | ||
>>> s = [3, [1, [4, [1]]]] | ||
>>> s1 = s[1] | ||
>>> s2 = s1[1] | ||
>>> s3 = s2[1] | ||
>>> deep_map(lambda x: x + 1, s) | ||
>>> s | ||
[4, [2, [5, [2]]]] | ||
>>> s1 is s[1] | ||
True | ||
>>> s2 is s1[1] | ||
True | ||
>>> s3 is s2[1] | ||
True | ||
""" | ||
for i in range(len(s)): | ||
if type(s[i]) == list: | ||
deep_map(f, s[i]) | ||
else: | ||
s[i] = f(s[i]) | ||
|
Binary file not shown.
Oops, something went wrong.