diff --git a/config.json b/config.json index 32c30fc..cd7acc8 100644 --- a/config.json +++ b/config.json @@ -659,6 +659,14 @@ "prerequisites": [], "difficulty": 5 }, + { + "slug": "flower-field", + "name": "Flower Field", + "uuid": "237d19eb-1045-45d7-95a8-4f33e44b87cc", + "practices": [], + "prerequisites": [], + "difficulty": 5 + }, { "slug": "grade-school", "name": "Grade School", @@ -702,7 +710,8 @@ "uuid": "ece26c46-07dc-49ae-bac2-10353fb340b5", "practices": [], "prerequisites": [], - "difficulty": 5 + "difficulty": 5, + "status": "deprecated" }, { "slug": "nucleotide-count", diff --git a/exercises/practice/flower-field/.docs/instructions.md b/exercises/practice/flower-field/.docs/instructions.md new file mode 100644 index 0000000..bbdae0c --- /dev/null +++ b/exercises/practice/flower-field/.docs/instructions.md @@ -0,0 +1,26 @@ +# Instructions + +Your task is to add flower counts to empty squares in a completed Flower Field garden. +The garden itself is a rectangle board composed of squares that are either empty (`' '`) or a flower (`'*'`). + +For each empty square, count the number of flowers adjacent to it (horizontally, vertically, diagonally). +If the empty square has no adjacent flowers, leave it empty. +Otherwise replace it with the count of adjacent flowers. + +For example, you may receive a 5 x 4 board like this (empty spaces are represented here with the '·' character for display on screen): + +```text +·*·*· +··*·· +··*·· +····· +``` + +Which your code should transform into this: + +```text +1*3*1 +13*31 +·2*2· +·111· +``` diff --git a/exercises/practice/flower-field/.docs/introduction.md b/exercises/practice/flower-field/.docs/introduction.md new file mode 100644 index 0000000..af9b615 --- /dev/null +++ b/exercises/practice/flower-field/.docs/introduction.md @@ -0,0 +1,7 @@ +# Introduction + +[Flower Field][history] is a compassionate reimagining of the popular game Minesweeper. +The object of the game is to find all the flowers in the garden using numeric hints that indicate how many flowers are directly adjacent (horizontally, vertically, diagonally) to a square. +"Flower Field" shipped in regional versions of Microsoft Windows in Italy, Germany, South Korea, Japan and Taiwan. + +[history]: https://web.archive.org/web/20020409051321fw_/http://rcm.usr.dsi.unimi.it/rcmweb/fnm/ diff --git a/exercises/practice/flower-field/.meta/config.json b/exercises/practice/flower-field/.meta/config.json new file mode 100644 index 0000000..95c1d8e --- /dev/null +++ b/exercises/practice/flower-field/.meta/config.json @@ -0,0 +1,17 @@ +{ + "authors": [ + "BNAndras" + ], + "files": { + "solution": [ + "flower_field.vim" + ], + "test": [ + "flower_field.vader" + ], + "example": [ + ".meta/example.vim" + ] + }, + "blurb": "Mark all the flowers in a garden." +} diff --git a/exercises/practice/flower-field/.meta/example.vim b/exercises/practice/flower-field/.meta/example.vim new file mode 100644 index 0000000..095d534 --- /dev/null +++ b/exercises/practice/flower-field/.meta/example.vim @@ -0,0 +1,41 @@ +function! Annotate(garden) abort + if empty(a:garden) + return [] + endif + + let l:rows = len(a:garden) + let l:cols = len(a:garden[0]) + + let l:result = [] + for l:row in range(l:rows) + let l:marked = [] + for l:col in range(l:cols) + if a:garden[l:row][l:col] ==# '*' + call add(l:marked, '*') + else + let l:count = 0 + let l:minRow = max([0, l:row - 1]) + let l:maxRow = min([l:rows - 1, l:row + 1]) + let l:minCol = max([0, l:col - 1]) + let l:maxCol = min([l:cols - 1, l:col + 1]) + for l:newRow in range(l:minRow, l:maxRow) + for l:newCol in range(l:minCol, l:maxCol) + if l:newRow == l:row && l:newCol == l:col + continue + endif + if a:garden[l:newRow][l:newCol] ==# '*' + let l:count += 1 + endif + endfor + endfor + if l:count == 0 + call add(l:marked, ' ') + else + call add(l:marked, l:count) + endif + endif + endfor + call add(result, join(l:marked, '')) + endfor + return result +endfunction diff --git a/exercises/practice/flower-field/.meta/tests.toml b/exercises/practice/flower-field/.meta/tests.toml new file mode 100644 index 0000000..c2b24fd --- /dev/null +++ b/exercises/practice/flower-field/.meta/tests.toml @@ -0,0 +1,46 @@ +# 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. + +[237ff487-467a-47e1-9b01-8a891844f86c] +description = "no rows" + +[4b4134ec-e20f-439c-a295-664c38950ba1] +description = "no columns" + +[d774d054-bbad-4867-88ae-069cbd1c4f92] +description = "no flowers" + +[225176a0-725e-43cd-aa13-9dced501f16e] +description = "garden full of flowers" + +[3f345495-f1a5-4132-8411-74bd7ca08c49] +description = "flower surrounded by spaces" + +[6cb04070-4199-4ef7-a6fa-92f68c660fca] +description = "space surrounded by flowers" + +[272d2306-9f62-44fe-8ab5-6b0f43a26338] +description = "horizontal line" + +[c6f0a4b2-58d0-4bf6-ad8d-ccf4144f1f8e] +description = "horizontal line, flowers at edges" + +[a54e84b7-3b25-44a8-b8cf-1753c8bb4cf5] +description = "vertical line" + +[b40f42f5-dec5-4abc-b167-3f08195189c1] +description = "vertical line, flowers at edges" + +[58674965-7b42-4818-b930-0215062d543c] +description = "cross" + +[dd9d4ca8-9e68-4f78-a677-a2a70fd7a7b8] +description = "large garden" diff --git a/exercises/practice/flower-field/flower_field.vader b/exercises/practice/flower-field/flower_field.vader new file mode 100644 index 0000000..c3047b8 --- /dev/null +++ b/exercises/practice/flower-field/flower_field.vader @@ -0,0 +1,125 @@ +Execute (no rows): + let g:garden = [] + let g:expected = [] + AssertEqual g:expected, Annotate(g:garden) + +Execute (no columns): + let g:garden = [''] + let g:expected = [''] + AssertEqual g:expected, Annotate(g:garden) + +Execute (no flowers): + let g:garden = [ + \ ' ', + \ ' ', + \ ' '] + let g:expected = [ + \ ' ', + \ ' ', + \ ' '] + AssertEqual g:expected, Annotate(g:garden) + +Execute (garden full of flowers): + let g:garden = [ + \ '***', + \ '***', + \ '***'] + let g:expected = [ + \ '***', + \ '***', + \ '***'] + AssertEqual g:expected, Annotate(g:garden) + +Execute (flower surrounded by spaces): + let g:garden = [ + \ ' ', + \ ' * ', + \ ' '] + let g:expected = [ + \ '111', + \ '1*1', + \ '111'] + AssertEqual g:expected, Annotate(g:garden) + +Execute (space surrounded by flowers): + let g:garden = [ + \ '***', + \ '* *', + \ '***'] + let g:expected = [ + \ '***', + \ '*8*', + \ '***'] + AssertEqual g:expected, Annotate(g:garden) + +Execute (horizontal line): + let g:garden = [' * * '] + let g:expected = ['1*2*1'] + AssertEqual g:expected, Annotate(g:garden) + +Execute (horizontal line, flowers at edges): + let g:garden = ['* *'] + let g:expected = ['*1 1*'] + AssertEqual g:expected, Annotate(g:garden) + +Execute (vertical line): + let g:garden = [ + \ ' ', + \ '*', + \ ' ', + \ '*', + \ ' '] + let g:expected = [ + \ '1', + \ '*', + \ '2', + \ '*', + \ '1'] + AssertEqual g:expected, Annotate(g:garden) + +Execute (vertical line, flowers at edges): + let g:garden = [ + \ '*', + \ ' ', + \ ' ', + \ ' ', + \ '*'] + let g:expected = [ + \ '*', + \ '1', + \ ' ', + \ '1', + \ '*'] + AssertEqual g:expected, Annotate(g:garden) + +Execute (cross): + let g:garden = [ + \ ' * ', + \ ' * ', + \ '*****', + \ ' * ', + \ ' * '] + let g:expected = [ + \ ' 2*2 ', + \ '25*52', + \ '*****', + \ '25*52', + \ ' 2*2 '] + AssertEqual g:expected, Annotate(g:garden) + +Execute (large garden): + let g:garden = [ + \ ' * * ', + \ ' * ', + \ ' * ', + \ ' * *', + \ ' * * ', + \ ' '] + let g:expected = [ + \ '1*22*1', + \ '12*322', + \ ' 123*2', + \ '112*4*', + \ '1*22*2', + \ '111111'] + AssertEqual g:expected, Annotate(g:garden) diff --git a/exercises/practice/flower-field/flower_field.vim b/exercises/practice/flower-field/flower_field.vim new file mode 100644 index 0000000..39f488c --- /dev/null +++ b/exercises/practice/flower-field/flower_field.vim @@ -0,0 +1,7 @@ +" +" Given a a list of strings representing a garden, +" mark each cell with the number of flowers in the adjacent cells. +" +function Annotate(garden) abort + " your code goes here +endfunction