-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
6 changed files
with
1,175 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"authors": [ | ||
"brocla" | ||
], | ||
"files": { | ||
"solution": [ | ||
"example_walrus_normalization.py" | ||
] | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
test/example-walrus-normalization/example_walrus_normalization.py
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,29 @@ | ||
# Examples of walrus usage in user solutions | ||
|
||
def slices(series, length): | ||
""" | ||
Given a string of digits, output all the contiguous substrings of length `n`, | ||
in that string, in the order that they appear. | ||
""" | ||
return [ | ||
sub_str for i, _ in enumerate(series) | ||
if len(sub_str := series[i:i+length]) == length | ||
] | ||
|
||
|
||
def check_height(grid): | ||
"""check that row count is a multiple of 4""" | ||
if (height := len(grid)) % 3: | ||
raise ValueError("grid rows not a multiple of 4") | ||
return height | ||
|
||
|
||
def nswe_points(self, point): | ||
"""return a set of four adjacent points""" | ||
nswe_offsets = set([(1, 0), (-1, 0), (0, -1), (0, 1)]) | ||
return { | ||
neighbor | ||
for offset in nswe_offsets | ||
if self.on_the_board(neighbor := point + offset) | ||
} | ||
|
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,16 @@ | ||
{ | ||
"placeholder_0": "slices", | ||
"placeholder_1": "series", | ||
"placeholder_2": "length", | ||
"placeholder_3": "i", | ||
"placeholder_4": "_", | ||
"placeholder_5": "sub_str", | ||
"placeholder_6": "check_height", | ||
"placeholder_7": "grid", | ||
"placeholder_8": "height", | ||
"placeholder_9": "nswe_points", | ||
"placeholder_10": "point", | ||
"placeholder_11": "nswe_offsets", | ||
"placeholder_12": "offset", | ||
"placeholder_13": "neighbor" | ||
} |
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,3 @@ | ||
{ | ||
"version": 2 | ||
} |
Oops, something went wrong.