4 kyu
Spidey Swings Across Town
25 of 41docgunthrop
Description:
Spider-Man ("Spidey") needs to get across town for a date with Mary Jane and his web-shooter is low on web fluid. He travels by slinging his web rope to latch onto a building rooftop, allowing him to swing to the opposite end of the latch point.
Write a function that, when given a list of buildings, returns a list of optimal rooftop latch points for minimal web expenditure.
Input
Your function will receive an array whose elements are subarrays in the form [h,w]
where h
and w
represent the height and width, respectively, of each building in sequence
Output
An array of latch points (integers) to get from 0
to the end of the last building in the input list
Technical Details
- An optimal latch point is one that yields the greatest horizontal distance gain relative to length of web rope used. Specifically, the highest horizontal distance yield per length unit of web rope used. Give this value rounded down to the nearest integer as a distance from Spidey's origin point (
0
) - At the start of each swing, Spidey selects a latch point based on his current position.
- At the end of each swing, Spidey ends up on the opposite side of the latch point equal to his distance from the latch point before swing.
- Spidey's initial altitude is
50
, and will always be the same at the start and end of each swing. His initial horizontal position is0
. - To avoid collision with people/traffic below, Spidey must maintain a minimum altitude of
20
at all times. - Building height (
h
) range limits:125 <= h < 250
- Building width (
w
) range limits:50 <= w <= 100
- Inputs will always be valid.
Test Example
- Spidey's initial position is at
0
, marked by the Spidey icon on the left. His first latch point is marked by the green circle at76
(horizontal position) onbuildings[0]
. - At the end of the swing, Spidey's position is at the point marked
B
with a horizontal position of152
. The green arc represents Spidey's path during swing. - The orange circle on the 3rd building and the orange arc going from point
B
to pointC
represent the latch point (258
) and arc path for the next swing.
buildings = [[162,76], [205,96], [244,86], [212,68], [174,57], [180,89], [208,70], [214,82], [181,69], [203,67]]
spidey_swings(buildings)# [76,258,457,643,748]
If you enjoyed this kata, be sure to check out my other katas.
Mathematics
Algorithms
Similar Kata:
Stats:
Created | Sep 29, 2017 |
Published | Sep 30, 2017 |
Warriors Trained | 288 |
Total Skips | 27 |
Total Code Submissions | 1795 |
Total Times Completed | 41 |
JavaScript Completions | 20 |
Python Completions | 25 |
Total Stars | 41 |
% of votes with a positive feedback rating | 73% of 11 |
Total "Very Satisfied" Votes | 6 |
Total "Somewhat Satisfied" Votes | 4 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 2 |
Average Assessed Rank | 4 kyu |
Highest Assessed Rank | 3 kyu |
Lowest Assessed Rank | 5 kyu |