-
Notifications
You must be signed in to change notification settings - Fork 519
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync saddle-point with problem-specifications (#1775)
- Loading branch information
Showing
6 changed files
with
117 additions
and
77 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
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,9 +1,11 @@ | ||
# Introduction | ||
|
||
You are planning on building a tree house in the woods near your house so that you can watch the sun rise and set. | ||
You plan to build a tree house in the woods near your house so that you can watch the sun rise and set. | ||
|
||
You've obtained data from a local survey company that shows the heights of all the trees in each rectangular section of the map. | ||
You need to analyze each grid on the map to find the perfect tree for your tree house. | ||
You've obtained data from a local survey company that show the height of every tree in each rectangular section of the map. | ||
You need to analyze each grid on the map to find good trees for your tree house. | ||
|
||
The best tree will be the tallest tree compared to all the other trees to the east and west, so that you have the best possible view of the sunrises and sunsets. | ||
You don't like climbing too much, so the perfect tree will also be the shortest among all the trees to the north and to the south. | ||
A good tree is both: | ||
|
||
- taller than every tree to the east and west, so that you have the best possible view of the sunrises and sunsets. | ||
- shorter than every tree to the north and south, to minimize the amount of tree climbing. |
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
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 @@ | ||
// We don't care about order | ||
fn find_sorted_saddle_points(input: &[Vec<u64>]) -> Vec<(usize, usize)> { | ||
let mut result = saddle_points::find_saddle_points(input); | ||
result.sort_unstable(); | ||
result | ||
} | ||
{% for test in cases %} | ||
#[test] | ||
{% if loop.index != 1 -%} | ||
#[ignore] | ||
{% endif -%} | ||
fn {{ test.description | slugify | replace(from="-", to="_") }}() { | ||
let input = &[{% for row in test.input.matrix %} | ||
vec!{{ row }}, | ||
{% endfor %}]; | ||
let output = find_sorted_saddle_points(input); | ||
let expected = &[ | ||
{% for p in test.expected | sort(attribute = "column") | sort(attribute = "row") %} | ||
({{ p.row - 1 }}, {{ p.column - 1 }}), | ||
{% endfor %} | ||
]; | ||
assert_eq!(output, expected); | ||
} | ||
{% endfor -%} |
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,3 +1,37 @@ | ||
# This is an auto-generated file. Regular comments will be removed when this | ||
# file is regenerated. Regenerating will not touch any manually added keys, | ||
# so comments can be added in a "comment" key. | ||
# This is an auto-generated file. | ||
# | ||
# Regenerating this file via `configlet sync` will: | ||
# - Recreate every `description` key/value pair | ||
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
# - Preserve any other key/value pair | ||
# | ||
# As user-added comments (using the # character) will be removed when this file | ||
# is regenerated, comments can be added via a `comment` key. | ||
|
||
[3e374e63-a2e0-4530-a39a-d53c560382bd] | ||
description = "Can identify single saddle point" | ||
|
||
[6b501e2b-6c1f-491f-b1bb-7f278f760534] | ||
description = "Can identify that empty matrix has no saddle points" | ||
|
||
[8c27cc64-e573-4fcb-a099-f0ae863fb02f] | ||
description = "Can identify lack of saddle points when there are none" | ||
|
||
[6d1399bd-e105-40fd-a2c9-c6609507d7a3] | ||
description = "Can identify multiple saddle points in a column" | ||
|
||
[3e81dce9-53b3-44e6-bf26-e328885fd5d1] | ||
description = "Can identify multiple saddle points in a row" | ||
|
||
[88868621-b6f4-4837-bb8b-3fad8b25d46b] | ||
description = "Can identify saddle point in bottom right corner" | ||
|
||
[5b9499ca-fcea-4195-830a-9c4584a0ee79] | ||
description = "Can identify saddle points in a non square matrix" | ||
|
||
[ee99ccd2-a1f1-4283-ad39-f8c70f0cf594] | ||
description = "Can identify that saddle points in a single column matrix are those with the minimum value" | ||
|
||
[63abf709-a84b-407f-a1b3-456638689713] | ||
description = "Can identify that saddle points in a single row matrix are those with the maximum value" |
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