-
-
Notifications
You must be signed in to change notification settings - Fork 27
Add prism
#376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BNAndras
wants to merge
3
commits into
exercism:main
Choose a base branch
from
BNAndras:add-prism
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add prism
#376
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,36 @@ | ||
| # Instructions | ||
|
|
||
| Before activating the laser array, you must predict the exact order in which crystals will be hit, identified by their sample IDs. | ||
|
|
||
| ## Example Test Case | ||
|
|
||
| Consider this crystal array configuration: | ||
|
|
||
| ```json | ||
| { | ||
| "start": { "x": 0, "y": 0, "angle": 0 }, | ||
| "prisms": [ | ||
| { "id": 3, "x": 30, "y": 10, "angle": 45 }, | ||
| { "id": 1, "x": 10, "y": 10, "angle": -90 }, | ||
| { "id": 2, "x": 10, "y": 0, "angle": 90 }, | ||
| { "id": 4, "x": 20, "y": 0, "angle": 0 } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| ## What's Happening | ||
|
|
||
| The laser starts at the origin `(0, 0)` and fires horizontally to the right at angle 0°. | ||
| Here's the step-by-step beam path: | ||
|
|
||
| **Step 1**: The beam travels along the x-axis (y = 0) and first encounters **Crystal #2** at position `(10, 0)`. | ||
| This crystal has a refraction angle of 90°, which means it bends the beam perpendicular to its current path. | ||
| The beam, originally traveling at 0°, is now redirected to 90° (straight up). | ||
|
|
||
| **Step 2**: The beam now travels vertically upward from position `(10, 0)` and strikes **Crystal #1** at position `(10, 10)`. | ||
| This crystal has a refraction angle of -90°, bending the beam by -90° relative to its current direction. | ||
| The beam was traveling at 90°, so after refraction it's now at 0° (90° + (-90°) = 0°), traveling horizontally to the right again. | ||
|
|
||
| **Step 3**: From position `(10, 10)`, the beam travels horizontally and encounters **Crystal #3** at position `(30, 10)`. | ||
| This crystal refracts the beam by 45°, changing its direction to 45°. | ||
| The beam continues into empty space beyond the array. |
This file contains hidden or 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,5 @@ | ||
| # Introduction | ||
|
|
||
| You're a researcher at **PRISM** (Precariously Redirected Illumination Safety Management), working with a precision laser calibration system that tests experimental crystal prisms. | ||
| These crystals are being developed for next-generation optical computers, and each one has unique refractive properties based on its molecular structure. | ||
| The lab's laser system can damage crystals if they receive unexpected illumination, so precise path prediction is critical. |
This file contains hidden or 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,19 @@ | ||
| { | ||
| "authors": [ | ||
| "BNAndras" | ||
| ], | ||
| "files": { | ||
| "solution": [ | ||
| "prism.vim" | ||
| ], | ||
| "test": [ | ||
| "prism.vader" | ||
| ], | ||
| "example": [ | ||
| ".meta/example.vim" | ||
| ] | ||
| }, | ||
| "blurb": "Calculate the path of a laser through reflective prisms.", | ||
| "source": "FraSanga", | ||
| "source_url": "https://github.com/exercism/problem-specifications/pull/2625" | ||
| } |
This file contains hidden or 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,63 @@ | ||
| function! FindSequence(prisms, start) abort | ||
| let l:sequence = [] | ||
| let l:x = a:start.x + 0.0 | ||
| let l:y = a:start.y + 0.0 | ||
| let l:angle = a:start.angle + 0.0 | ||
| let l:pi = acos(-1.0) | ||
|
|
||
| while 1 | ||
| let l:rad = l:angle * l:pi / 180.0 | ||
| let l:dirX = cos(l:rad) | ||
| let l:dirY = sin(l:rad) | ||
|
|
||
| let l:nearest = {} | ||
| let l:nearestDist = 1.0 / 0.0 | ||
| let l:found = 0 | ||
|
|
||
| for l:prism in a:prisms | ||
| let l:dx = l:prism.x - l:x | ||
| let l:dy = l:prism.y - l:y | ||
|
|
||
| " how far along the ray is the prism? | ||
| let l:dist = l:dx * l:dirX + l:dy * l:dirY | ||
|
|
||
| " ignore prisms behind us | ||
| if l:dist <= 1.0e-6 | ||
| continue | ||
| endif | ||
|
|
||
| " how far off center is the prism? | ||
| let l:crossX = l:dx - l:dist * l:dirX | ||
| let l:crossY = l:dy - l:dist * l:dirY | ||
| let l:crossSq = l:crossX * l:crossX + l:crossY * l:crossY | ||
|
|
||
| " bail if outside relative tolerance (scale by distance) | ||
| let l:scale = 1.0 | ||
| let l:dist_sq = l:dist * l:dist | ||
| if l:dist_sq > 1.0 | ||
| let l:scale = l:dist_sq | ||
| endif | ||
| if l:crossSq >= 1.0e-6 * l:scale | ||
| continue | ||
| endif | ||
|
|
||
| if l:dist < l:nearestDist | ||
| let l:nearestDist = l:dist | ||
| let l:nearest = l:prism | ||
| let l:found = 1 | ||
| endif | ||
| endfor | ||
|
|
||
| if !l:found | ||
| break | ||
| endif | ||
|
|
||
| call add(l:sequence, l:nearest.id) | ||
| let l:x = l:nearest.x | ||
| let l:y = l:nearest.y | ||
| let l:angle = fmod(l:angle + l:nearest.angle, 360.0) | ||
|
|
||
| endwhile | ||
|
|
||
| return {'sequence': l:sequence} | ||
| endfunction |
This file contains hidden or 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,52 @@ | ||
| # 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. | ||
|
|
||
| [ec65d3b3-f7bf-4015-8156-0609c141c4c4] | ||
| description = "zero prisms" | ||
|
|
||
| [ec0ca17c-0c5f-44fb-89ba-b76395bdaf1c] | ||
| description = "one prism one hit" | ||
|
|
||
| [0db955f2-0a27-4c82-ba67-197bd6202069] | ||
| description = "one prism zero hits" | ||
|
|
||
| [8d92485b-ebc0-4ee9-9b88-cdddb16b52da] | ||
| description = "going up zero hits" | ||
|
|
||
| [78295b3c-7438-492d-8010-9c63f5c223d7] | ||
| description = "going down zero hits" | ||
|
|
||
| [acc723ea-597b-4a50-8d1b-b980fe867d4c] | ||
| description = "going left zero hits" | ||
|
|
||
| [3f19b9df-9eaa-4f18-a2db-76132f466d17] | ||
| description = "negative angle" | ||
|
|
||
| [96dacffb-d821-4cdf-aed8-f152ce063195] | ||
| description = "large angle" | ||
|
|
||
| [513a7caa-957f-4c5d-9820-076842de113c] | ||
| description = "upward refraction two hits" | ||
|
|
||
| [d452b7c7-9761-4ea9-81a9-2de1d73eb9ef] | ||
| description = "downward refraction two hits" | ||
|
|
||
| [be1a2167-bf4c-4834-acc9-e4d68e1a0203] | ||
| description = "same prism twice" | ||
|
|
||
| [df5a60dd-7c7d-4937-ac4f-c832dae79e2e] | ||
| description = "simple path" | ||
|
|
||
| [8d9a3cc8-e846-4a3b-a137-4bfc4aa70bd1] | ||
| description = "multiple prisms floating point precision" | ||
|
|
||
| [e077fc91-4e4a-46b3-a0f5-0ba00321da56] | ||
| description = "complex path with multiple prisms floating point precision" |
This file contains hidden or 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,83 @@ | ||
| Execute (zero prisms): | ||
| let g:prisms = [] | ||
| let g:start = {'angle': 0, 'x': 0, 'y': 0} | ||
| let g:expected = {'sequence': []} | ||
| AssertEqual g:expected, FindSequence(g:prisms, g:start) | ||
|
|
||
| Execute (one prism one hit): | ||
| let g:prisms = [{'id': 1, 'angle': 0, 'x': 10, 'y': 0}] | ||
| let g:start = {'angle': 0, 'x': 0, 'y': 0} | ||
| let g:expected = {'sequence': [1]} | ||
| AssertEqual g:expected, FindSequence(g:prisms, g:start) | ||
|
|
||
| Execute (one prism zero hits): | ||
| let g:prisms = [{'id': 1, 'angle': 0, 'x': -10, 'y': 0}] | ||
| let g:start = {'angle': 0, 'x': 0, 'y': 0} | ||
| let g:expected = {'sequence': []} | ||
| AssertEqual g:expected, FindSequence(g:prisms, g:start) | ||
|
|
||
| Execute (going up zero hits): | ||
| let g:prisms = [{'id': 3, 'angle': 0, 'x': 0, 'y': -10}, {'id': 1, 'angle': 0, 'x': -10, 'y': 0}, {'id': 2, 'angle': 0, 'x': 10, 'y': 0}] | ||
| let g:start = {'angle': 90, 'x': 0, 'y': 0} | ||
| let g:expected = {'sequence': []} | ||
| AssertEqual g:expected, FindSequence(g:prisms, g:start) | ||
|
|
||
| Execute (going down zero hits): | ||
| let g:prisms = [{'id': 1, 'angle': 0, 'x': 10, 'y': 0}, {'id': 2, 'angle': 0, 'x': 0, 'y': 10}, {'id': 3, 'angle': 0, 'x': -10, 'y': 0}] | ||
| let g:start = {'angle': -90, 'x': 0, 'y': 0} | ||
| let g:expected = {'sequence': []} | ||
| AssertEqual g:expected, FindSequence(g:prisms, g:start) | ||
|
|
||
| Execute (going left zero hits): | ||
| let g:prisms = [{'id': 2, 'angle': 0, 'x': 0, 'y': 10}, {'id': 3, 'angle': 0, 'x': 10, 'y': 0}, {'id': 1, 'angle': 0, 'x': 0, 'y': -10}] | ||
| let g:start = {'angle': 180, 'x': 0, 'y': 0} | ||
| let g:expected = {'sequence': []} | ||
| AssertEqual g:expected, FindSequence(g:prisms, g:start) | ||
|
|
||
| Execute (negative angle): | ||
| let g:prisms = [{'id': 1, 'angle': 0, 'x': 0, 'y': -10}, {'id': 2, 'angle': 0, 'x': 0, 'y': 10}, {'id': 3, 'angle': 0, 'x': 10, 'y': 0}] | ||
| let g:start = {'angle': -180, 'x': 0, 'y': 0} | ||
| let g:expected = {'sequence': []} | ||
| AssertEqual g:expected, FindSequence(g:prisms, g:start) | ||
|
|
||
| Execute (large angle): | ||
| let g:prisms = [{'id': 1, 'angle': 0, 'x': 10, 'y': 0}] | ||
| let g:start = {'angle': 2340, 'x': 0, 'y': 0} | ||
| let g:expected = {'sequence': []} | ||
| AssertEqual g:expected, FindSequence(g:prisms, g:start) | ||
|
|
||
| Execute (upward refraction two hits): | ||
| let g:prisms = [{'id': 1, 'angle': 0, 'x': 10, 'y': 10}, {'id': 2, 'angle': 90, 'x': 10, 'y': 0}] | ||
| let g:start = {'angle': 0, 'x': 0, 'y': 0} | ||
| let g:expected = {'sequence': [2, 1]} | ||
| AssertEqual g:expected, FindSequence(g:prisms, g:start) | ||
|
|
||
| Execute (downward refraction two hits): | ||
| let g:prisms = [{'id': 1, 'angle': -90, 'x': 10, 'y': 0}, {'id': 2, 'angle': 0, 'x': 10, 'y': -10}] | ||
| let g:start = {'angle': 0, 'x': 0, 'y': 0} | ||
| let g:expected = {'sequence': [1, 2]} | ||
| AssertEqual g:expected, FindSequence(g:prisms, g:start) | ||
|
|
||
| Execute (same prism twice): | ||
| let g:prisms = [{'id': 2, 'angle': 0, 'x': 10, 'y': 0}, {'id': 1, 'angle': -180, 'x': 20, 'y': 0}] | ||
| let g:start = {'angle': 0, 'x': 0, 'y': 0} | ||
| let g:expected = {'sequence': [2, 1, 2]} | ||
| AssertEqual g:expected, FindSequence(g:prisms, g:start) | ||
|
|
||
| Execute (simple path): | ||
| let g:prisms = [{'id': 3, 'angle': 45, 'x': 30, 'y': 10}, {'id': 1, 'angle': -90, 'x': 10, 'y': 10}, {'id': 2, 'angle': 90, 'x': 10, 'y': 0}, {'id': 4, 'angle': 0, 'x': 20, 'y': 0}] | ||
| let g:start = {'angle': 0, 'x': 0, 'y': 0} | ||
| let g:expected = {'sequence': [2, 1, 3]} | ||
| AssertEqual g:expected, FindSequence(g:prisms, g:start) | ||
|
|
||
| Execute (multiple prisms floating point precision): | ||
| let g:prisms = [{'id': 26, 'angle': 6.555, 'x': 5.8, 'y': 73.4}, {'id': 24, 'angle': -0.304, 'x': 36.2, 'y': 65.2}, {'id': 20, 'angle': 45.17, 'x': 20.4, 'y': 82.8}, {'id': 31, 'angle': 30.615, 'x': -20.2, 'y': 48.8}, {'id': 30, 'angle': 28.771, 'x': 24.0, 'y': 0.6}, {'id': 29, 'angle': 61.327, 'x': 31.4, 'y': 79.4}, {'id': 28, 'angle': -18.157, 'x': 36.4, 'y': 31.4}, {'id': 22, 'angle': 54.745, 'x': 47.0, 'y': 57.8}, {'id': 38, 'angle': 49.05, 'x': 36.4, 'y': 79.2}, {'id': 10, 'angle': 11.978, 'x': 37.8, 'y': 55.2}, {'id': 18, 'angle': 22.661, 'x': -26.0, 'y': 42.6}, {'id': 25, 'angle': 51.958, 'x': 38.8, 'y': 76.2}, {'id': 2, 'angle': -21.817, 'x': 0.0, 'y': 42.4}, {'id': 35, 'angle': -171.579, 'x': 21.4, 'y': 44.8}, {'id': 7, 'angle': 19.081, 'x': 14.2, 'y': -1.6}, {'id': 33, 'angle': -165.941, 'x': 11.2, 'y': 44.4}, {'id': 11, 'angle': 66.262, 'x': 15.4, 'y': 82.6}, {'id': 16, 'angle': 35.852, 'x': 30.8, 'y': 6.6}, {'id': 15, 'angle': 53.782, 'x': -3.0, 'y': 79.2}, {'id': 4, 'angle': 17.016, 'x': 29.0, 'y': 75.4}, {'id': 23, 'angle': 70.763, 'x': 41.6, 'y': 59.8}, {'id': 8, 'angle': -9.24, 'x': -10.0, 'y': 15.8}, {'id': 13, 'angle': 45.812, 'x': 48.6, 'y': 51.8}, {'id': 1, 'angle': 17.937, 'x': 13.2, 'y': 77.0}, {'id': 34, 'angle': -4.199, 'x': -8.8, 'y': 36.8}, {'id': 21, 'angle': 20.783, 'x': 24.4, 'y': 75.8}, {'id': 17, 'angle': 24.709, 'x': -4.4, 'y': 74.6}, {'id': 9, 'angle': -165.413, 'x': 30.8, 'y': 41.8}, {'id': 32, 'angle': 40.892, 'x': 4.2, 'y': 78.6}, {'id': 37, 'angle': 33.29, 'x': -15.8, 'y': 47.0}, {'id': 6, 'angle': 51.295, 'x': 1.0, 'y': 80.6}, {'id': 36, 'angle': 92.52, 'x': -27.0, 'y': 47.8}, {'id': 14, 'angle': -52.001, 'x': -2.0, 'y': 34.4}, {'id': 5, 'angle': 31.866, 'x': 23.2, 'y': 80.2}, {'id': 27, 'angle': -75.303, 'x': -5.6, 'y': 32.8}, {'id': 12, 'angle': 0.0, 'x': -1.0, 'y': 0.2}, {'id': 3, 'angle': 46.72, 'x': -6.6, 'y': 3.2}, {'id': 19, 'angle': -9.205, 'x': -13.8, 'y': 24.2}] | ||
| let g:start = {'angle': -6.429, 'x': 0, 'y': 0} | ||
| let g:expected = {'sequence': [7, 30, 16, 28, 13, 22, 23, 10, 9, 24, 25, 38, 29, 4, 35, 21, 5, 20, 11, 1, 33, 26, 32, 6, 15, 17, 2, 14, 27, 34, 37, 31, 36, 18, 19, 8, 3, 12]} | ||
| AssertEqual g:expected, FindSequence(g:prisms, g:start) | ||
|
|
||
| Execute (complex path with multiple prisms floating point precision): | ||
| let g:prisms = [{'id': 46, 'angle': -88.332, 'x': 37.4, 'y': 20.6}, {'id': 72, 'angle': -90.774, 'x': -24.2, 'y': 23.4}, {'id': 25, 'angle': 98.562, 'x': 78.6, 'y': 7.8}, {'id': 60, 'angle': 115.56, 'x': -58.8, 'y': 31.6}, {'id': 22, 'angle': 63.515, 'x': 75.2, 'y': 28.0}, {'id': 2, 'angle': 91.176, 'x': 89.8, 'y': 27.8}, {'id': 23, 'angle': 30.829, 'x': 9.8, 'y': 30.8}, {'id': 69, 'angle': -88.315, 'x': 22.8, 'y': 20.6}, {'id': 44, 'angle': -116.565, 'x': -0.8, 'y': 15.6}, {'id': 36, 'angle': -90.0, 'x': -24.2, 'y': 8.2}, {'id': 53, 'angle': 0.0, 'x': -1.2, 'y': 0.0}, {'id': 52, 'angle': -143.896, 'x': 14.2, 'y': 24.0}, {'id': 5, 'angle': 93.128, 'x': -65.2, 'y': 21.6}, {'id': 66, 'angle': 31.608, 'x': 5.4, 'y': 15.6}, {'id': 51, 'angle': -100.976, 'x': -72.6, 'y': 21.0}, {'id': 65, 'angle': 87.455, 'x': 48.0, 'y': 10.2}, {'id': 21, 'angle': 68.352, 'x': -41.8, 'y': 0.0}, {'id': 18, 'angle': -128.362, 'x': -46.2, 'y': 19.2}, {'id': 10, 'angle': 90.939, 'x': 74.4, 'y': 0.4}, {'id': 15, 'angle': 84.958, 'x': 67.6, 'y': 0.4}, {'id': 35, 'angle': 89.176, 'x': 14.8, 'y': -0.4}, {'id': 1, 'angle': 89.105, 'x': 83.0, 'y': 0.2}, {'id': 68, 'angle': -29.867, 'x': 14.6, 'y': 28.0}, {'id': 67, 'angle': -136.643, 'x': 79.8, 'y': 18.6}, {'id': 38, 'angle': -90.848, 'x': 53.0, 'y': 14.6}, {'id': 31, 'angle': -61.837, 'x': -58.0, 'y': 6.6}, {'id': 74, 'angle': 85.966, 'x': -30.8, 'y': 0.4}, {'id': 48, 'angle': -161.222, 'x': -4.6, 'y': 10.0}, {'id': 12, 'angle': -91.164, 'x': 59.0, 'y': 5.0}, {'id': 33, 'angle': 90.734, 'x': -16.4, 'y': 18.4}, {'id': 4, 'angle': 71.127, 'x': 82.6, 'y': 27.6}, {'id': 75, 'angle': -1.108, 'x': -10.2, 'y': 30.6}, {'id': 28, 'angle': 86.863, 'x': 38.0, 'y': 0.0}, {'id': 11, 'angle': 92.353, 'x': 64.4, 'y': -0.2}, {'id': 9, 'angle': 67.249, 'x': -51.4, 'y': 31.6}, {'id': 26, 'angle': 61.113, 'x': -39.8, 'y': 30.8}, {'id': 30, 'angle': 111.33, 'x': -34.2, 'y': 0.6}, {'id': 56, 'angle': 70.445, 'x': -51.0, 'y': 0.2}, {'id': 41, 'angle': 91.219, 'x': -12.0, 'y': 0.0}, {'id': 24, 'angle': 86.586, 'x': 63.8, 'y': 14.4}, {'id': 70, 'angle': -87.238, 'x': -72.8, 'y': 13.4}, {'id': 3, 'angle': -91.685, 'x': 22.4, 'y': 7.0}, {'id': 13, 'angle': 90.0, 'x': 34.4, 'y': 7.0}, {'id': 16, 'angle': -136.02, 'x': -47.4, 'y': 11.4}, {'id': 6, 'angle': 90.415, 'x': 90.0, 'y': 0.2}, {'id': 54, 'angle': 85.969, 'x': 44.0, 'y': 27.8}, {'id': 32, 'angle': 91.615, 'x': -9.0, 'y': 0.0}, {'id': 8, 'angle': 0.535, 'x': -31.6, 'y': 30.8}, {'id': 39, 'angle': 90.0, 'x': -12.0, 'y': 8.2}, {'id': 14, 'angle': 92.342, 'x': -79.6, 'y': 32.4}, {'id': 42, 'angle': -85.867, 'x': 65.8, 'y': 20.8}, {'id': 40, 'angle': 87.109, 'x': -65.0, 'y': 14.0}, {'id': 45, 'angle': 23.697, 'x': 10.6, 'y': 18.8}, {'id': 71, 'angle': -88.531, 'x': -24.2, 'y': 18.6}, {'id': 7, 'angle': -89.148, 'x': -72.6, 'y': 6.4}, {'id': 62, 'angle': -140.8, 'x': -32.0, 'y': 24.8}, {'id': 49, 'angle': 89.415, 'x': 34.4, 'y': -0.2}, {'id': 63, 'angle': -138.429, 'x': 74.2, 'y': 12.6}, {'id': 59, 'angle': -140.177, 'x': 82.8, 'y': 13.0}, {'id': 34, 'angle': -88.238, 'x': -9.4, 'y': 23.2}, {'id': 76, 'angle': 1.2, 'x': -57.6, 'y': 0.0}, {'id': 43, 'angle': 116.565, 'x': 7.0, 'y': 0.0}, {'id': 20, 'angle': 1.469, 'x': 45.8, 'y': -0.2}, {'id': 37, 'angle': 84.785, 'x': -16.6, 'y': 13.2}, {'id': 58, 'angle': 89.481, 'x': -79.0, 'y': -0.2}, {'id': 50, 'angle': -86.987, 'x': -24.2, 'y': 12.8}, {'id': 64, 'angle': -92.203, 'x': 59.2, 'y': 10.2}, {'id': 61, 'angle': -83.66, 'x': -72.0, 'y': 26.4}, {'id': 47, 'angle': -82.992, 'x': 45.4, 'y': 5.8}, {'id': 17, 'angle': -52.938, 'x': -52.2, 'y': 17.8}, {'id': 57, 'angle': 84.627, 'x': -61.8, 'y': 32.0}, {'id': 29, 'angle': 92.954, 'x': 47.2, 'y': 28.2}, {'id': 27, 'angle': 87.397, 'x': -4.6, 'y': 0.2}, {'id': 55, 'angle': 94.086, 'x': -61.4, 'y': 26.4}, {'id': 73, 'angle': -62.229, 'x': -40.4, 'y': 13.4}, {'id': 19, 'angle': -87.181, 'x': 53.2, 'y': 20.6}] | ||
| let g:start = {'angle': 0.0, 'x': 0, 'y': 0} | ||
| let g:expected = {'sequence': [43, 44, 66, 45, 52, 35, 49, 13, 3, 69, 46, 28, 20, 11, 24, 38, 19, 42, 15, 10, 63, 25, 59, 1, 6, 2, 4, 67, 22, 29, 65, 64, 12, 47, 54, 68, 23, 75, 8, 26, 18, 9, 60, 17, 31, 7, 70, 40, 5, 51, 61, 55, 57, 14, 58, 76, 56, 16, 21, 30, 73, 62, 74, 41, 39, 36, 50, 37, 33, 71, 72, 34, 32, 27, 48, 53]} | ||
| AssertEqual g:expected, FindSequence(g:prisms, g:start) | ||
This file contains hidden or 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,7 @@ | ||
| " | ||
| " Find the sequence of prisms hit by a laser | ||
| " firing from a given point and angle in a 2D grid | ||
| " | ||
| function! FindSequence(prisms, start) abort | ||
| " your code goes here | ||
| endfunction |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big deal, but I wonder if we should do this instead.
From a readers standpoint this is "kinder". From a machine standpoint, it does not care.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The online editor has text-wrapping so it's less of an issue there. This would though require tweaking the test generator if we want to manually split it across multiple lines. That's not a huge deal (famous last words), but we just need to agree on how long a collection should get before we split it across multiple lines. That in turn means we should probably agree on how to break up a nested collection.
or
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
80 columns, likely the target. Allow for that being a soft limit where it makes sense, 120 is likely the limit where it becomes a nuisance.
Of course, Vim itself allows for wrap or no wrap settings. (For those that know the editor, they know
gj,gkfor transitioning through "visual lines" that are not really lines.)Of course, not a requirement. Just was surprising to see such long lines. Controlling it where it is more easily read separated per the individual items to a line seems like a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I'll take a look at the generator next week.