From 942a374224d1ba89eba4db1702c5176518f8dc7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Sun, 15 Feb 2026 22:27:15 -0800 Subject: [PATCH 1/3] Add `prism` --- config.json | 8 ++ .../practice/prism/.docs/instructions.md | 36 ++++++++ .../practice/prism/.docs/introduction.md | 5 ++ exercises/practice/prism/.meta/config.json | 19 +++++ exercises/practice/prism/.meta/example.vim | 59 +++++++++++++ exercises/practice/prism/.meta/tests.toml | 52 ++++++++++++ exercises/practice/prism/prism.vader | 83 +++++++++++++++++++ exercises/practice/prism/prism.vim | 7 ++ 8 files changed, 269 insertions(+) create mode 100644 exercises/practice/prism/.docs/instructions.md create mode 100644 exercises/practice/prism/.docs/introduction.md create mode 100644 exercises/practice/prism/.meta/config.json create mode 100644 exercises/practice/prism/.meta/example.vim create mode 100644 exercises/practice/prism/.meta/tests.toml create mode 100644 exercises/practice/prism/prism.vader create mode 100644 exercises/practice/prism/prism.vim diff --git a/config.json b/config.json index 0af6623..e51f5ed 100644 --- a/config.json +++ b/config.json @@ -790,6 +790,14 @@ "prerequisites": [], "difficulty": 5 }, + { + "slug": "prism", + "name": "Prism", + "uuid": "4a8f6569-71cc-437d-9bda-e297e275f4f9", + "practices": [], + "prerequisites": [], + "difficulty": 5 + }, { "slug": "relative-distance", "name": "Relative Distance", diff --git a/exercises/practice/prism/.docs/instructions.md b/exercises/practice/prism/.docs/instructions.md new file mode 100644 index 0000000..a68c80d --- /dev/null +++ b/exercises/practice/prism/.docs/instructions.md @@ -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. diff --git a/exercises/practice/prism/.docs/introduction.md b/exercises/practice/prism/.docs/introduction.md new file mode 100644 index 0000000..bfa7ed7 --- /dev/null +++ b/exercises/practice/prism/.docs/introduction.md @@ -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. diff --git a/exercises/practice/prism/.meta/config.json b/exercises/practice/prism/.meta/config.json new file mode 100644 index 0000000..c6a3c42 --- /dev/null +++ b/exercises/practice/prism/.meta/config.json @@ -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" +} diff --git a/exercises/practice/prism/.meta/example.vim b/exercises/practice/prism/.meta/example.vim new file mode 100644 index 0000000..03c3a53 --- /dev/null +++ b/exercises/practice/prism/.meta/example.vim @@ -0,0 +1,59 @@ +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 = max([1.0, l:dist * l:dist]) + 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 diff --git a/exercises/practice/prism/.meta/tests.toml b/exercises/practice/prism/.meta/tests.toml new file mode 100644 index 0000000..b002223 --- /dev/null +++ b/exercises/practice/prism/.meta/tests.toml @@ -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" diff --git a/exercises/practice/prism/prism.vader b/exercises/practice/prism/prism.vader new file mode 100644 index 0000000..1758598 --- /dev/null +++ b/exercises/practice/prism/prism.vader @@ -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) diff --git a/exercises/practice/prism/prism.vim b/exercises/practice/prism/prism.vim new file mode 100644 index 0000000..692db03 --- /dev/null +++ b/exercises/practice/prism/prism.vim @@ -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 From a057aa673527e787cb0145e7d17f42d00e64e73c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Sun, 15 Feb 2026 22:30:39 -0800 Subject: [PATCH 2/3] Test removing `max` call --- exercises/practice/prism/.meta/example.vim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/exercises/practice/prism/.meta/example.vim b/exercises/practice/prism/.meta/example.vim index 03c3a53..0a70231 100644 --- a/exercises/practice/prism/.meta/example.vim +++ b/exercises/practice/prism/.meta/example.vim @@ -32,7 +32,10 @@ function! FindSequence(prisms, start) abort let l:crossSq = l:crossX * l:crossX + l:crossY * l:crossY " bail if outside relative tolerance (scale by distance) - let l:scale = max([1.0, l:dist * l:dist]) + let l:scale = 1.0 + if (l:dist * l:dist) > 1.0 + let l:scale = l:dist * l:dist + endif if l:crossSq >= 1.0e-6 * l:scale continue endif From 7a6818f8eeb4acb93ed0c6b0555dbc57be832702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Sun, 15 Feb 2026 22:31:54 -0800 Subject: [PATCH 3/3] Don't square dist twice --- exercises/practice/prism/.meta/example.vim | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/exercises/practice/prism/.meta/example.vim b/exercises/practice/prism/.meta/example.vim index 0a70231..491db5a 100644 --- a/exercises/practice/prism/.meta/example.vim +++ b/exercises/practice/prism/.meta/example.vim @@ -33,8 +33,9 @@ function! FindSequence(prisms, start) abort " bail if outside relative tolerance (scale by distance) let l:scale = 1.0 - if (l:dist * l:dist) > 1.0 - let l:scale = l:dist * l:dist + 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