Skip to content

Commit 6f234e8

Browse files
authored
Add flower-field, deprecating minesweeper (#343)
1 parent f1a9db4 commit 6f234e8

File tree

8 files changed

+279
-1
lines changed

8 files changed

+279
-1
lines changed

config.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,14 @@
659659
"prerequisites": [],
660660
"difficulty": 5
661661
},
662+
{
663+
"slug": "flower-field",
664+
"name": "Flower Field",
665+
"uuid": "237d19eb-1045-45d7-95a8-4f33e44b87cc",
666+
"practices": [],
667+
"prerequisites": [],
668+
"difficulty": 5
669+
},
662670
{
663671
"slug": "grade-school",
664672
"name": "Grade School",
@@ -702,7 +710,8 @@
702710
"uuid": "ece26c46-07dc-49ae-bac2-10353fb340b5",
703711
"practices": [],
704712
"prerequisites": [],
705-
"difficulty": 5
713+
"difficulty": 5,
714+
"status": "deprecated"
706715
},
707716
{
708717
"slug": "nucleotide-count",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Instructions
2+
3+
Your task is to add flower counts to empty squares in a completed Flower Field garden.
4+
The garden itself is a rectangle board composed of squares that are either empty (`' '`) or a flower (`'*'`).
5+
6+
For each empty square, count the number of flowers adjacent to it (horizontally, vertically, diagonally).
7+
If the empty square has no adjacent flowers, leave it empty.
8+
Otherwise replace it with the count of adjacent flowers.
9+
10+
For example, you may receive a 5 x 4 board like this (empty spaces are represented here with the '·' character for display on screen):
11+
12+
```text
13+
·*·*·
14+
··*··
15+
··*··
16+
·····
17+
```
18+
19+
Which your code should transform into this:
20+
21+
```text
22+
1*3*1
23+
13*31
24+
·2*2·
25+
·111·
26+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Introduction
2+
3+
[Flower Field][history] is a compassionate reimagining of the popular game Minesweeper.
4+
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.
5+
"Flower Field" shipped in regional versions of Microsoft Windows in Italy, Germany, South Korea, Japan and Taiwan.
6+
7+
[history]: https://web.archive.org/web/20020409051321fw_/http://rcm.usr.dsi.unimi.it/rcmweb/fnm/
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"authors": [
3+
"BNAndras"
4+
],
5+
"files": {
6+
"solution": [
7+
"flower_field.vim"
8+
],
9+
"test": [
10+
"flower_field.vader"
11+
],
12+
"example": [
13+
".meta/example.vim"
14+
]
15+
},
16+
"blurb": "Mark all the flowers in a garden."
17+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
function! Annotate(garden) abort
2+
if empty(a:garden)
3+
return []
4+
endif
5+
6+
let l:rows = len(a:garden)
7+
let l:cols = len(a:garden[0])
8+
9+
let l:result = []
10+
for l:row in range(l:rows)
11+
let l:marked = []
12+
for l:col in range(l:cols)
13+
if a:garden[l:row][l:col] ==# '*'
14+
call add(l:marked, '*')
15+
else
16+
let l:count = 0
17+
let l:minRow = max([0, l:row - 1])
18+
let l:maxRow = min([l:rows - 1, l:row + 1])
19+
let l:minCol = max([0, l:col - 1])
20+
let l:maxCol = min([l:cols - 1, l:col + 1])
21+
for l:newRow in range(l:minRow, l:maxRow)
22+
for l:newCol in range(l:minCol, l:maxCol)
23+
if l:newRow == l:row && l:newCol == l:col
24+
continue
25+
endif
26+
if a:garden[l:newRow][l:newCol] ==# '*'
27+
let l:count += 1
28+
endif
29+
endfor
30+
endfor
31+
if l:count == 0
32+
call add(l:marked, ' ')
33+
else
34+
call add(l:marked, l:count)
35+
endif
36+
endif
37+
endfor
38+
call add(result, join(l:marked, ''))
39+
endfor
40+
return result
41+
endfunction
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# This is an auto-generated file.
2+
#
3+
# Regenerating this file via `configlet sync` will:
4+
# - Recreate every `description` key/value pair
5+
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
6+
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
7+
# - Preserve any other key/value pair
8+
#
9+
# As user-added comments (using the # character) will be removed when this file
10+
# is regenerated, comments can be added via a `comment` key.
11+
12+
[237ff487-467a-47e1-9b01-8a891844f86c]
13+
description = "no rows"
14+
15+
[4b4134ec-e20f-439c-a295-664c38950ba1]
16+
description = "no columns"
17+
18+
[d774d054-bbad-4867-88ae-069cbd1c4f92]
19+
description = "no flowers"
20+
21+
[225176a0-725e-43cd-aa13-9dced501f16e]
22+
description = "garden full of flowers"
23+
24+
[3f345495-f1a5-4132-8411-74bd7ca08c49]
25+
description = "flower surrounded by spaces"
26+
27+
[6cb04070-4199-4ef7-a6fa-92f68c660fca]
28+
description = "space surrounded by flowers"
29+
30+
[272d2306-9f62-44fe-8ab5-6b0f43a26338]
31+
description = "horizontal line"
32+
33+
[c6f0a4b2-58d0-4bf6-ad8d-ccf4144f1f8e]
34+
description = "horizontal line, flowers at edges"
35+
36+
[a54e84b7-3b25-44a8-b8cf-1753c8bb4cf5]
37+
description = "vertical line"
38+
39+
[b40f42f5-dec5-4abc-b167-3f08195189c1]
40+
description = "vertical line, flowers at edges"
41+
42+
[58674965-7b42-4818-b930-0215062d543c]
43+
description = "cross"
44+
45+
[dd9d4ca8-9e68-4f78-a677-a2a70fd7a7b8]
46+
description = "large garden"
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
Execute (no rows):
2+
let g:garden = []
3+
let g:expected = []
4+
AssertEqual g:expected, Annotate(g:garden)
5+
6+
Execute (no columns):
7+
let g:garden = ['']
8+
let g:expected = ['']
9+
AssertEqual g:expected, Annotate(g:garden)
10+
11+
Execute (no flowers):
12+
let g:garden = [
13+
\ ' ',
14+
\ ' ',
15+
\ ' ']
16+
let g:expected = [
17+
\ ' ',
18+
\ ' ',
19+
\ ' ']
20+
AssertEqual g:expected, Annotate(g:garden)
21+
22+
Execute (garden full of flowers):
23+
let g:garden = [
24+
\ '***',
25+
\ '***',
26+
\ '***']
27+
let g:expected = [
28+
\ '***',
29+
\ '***',
30+
\ '***']
31+
AssertEqual g:expected, Annotate(g:garden)
32+
33+
Execute (flower surrounded by spaces):
34+
let g:garden = [
35+
\ ' ',
36+
\ ' * ',
37+
\ ' ']
38+
let g:expected = [
39+
\ '111',
40+
\ '1*1',
41+
\ '111']
42+
AssertEqual g:expected, Annotate(g:garden)
43+
44+
Execute (space surrounded by flowers):
45+
let g:garden = [
46+
\ '***',
47+
\ '* *',
48+
\ '***']
49+
let g:expected = [
50+
\ '***',
51+
\ '*8*',
52+
\ '***']
53+
AssertEqual g:expected, Annotate(g:garden)
54+
55+
Execute (horizontal line):
56+
let g:garden = [' * * ']
57+
let g:expected = ['1*2*1']
58+
AssertEqual g:expected, Annotate(g:garden)
59+
60+
Execute (horizontal line, flowers at edges):
61+
let g:garden = ['* *']
62+
let g:expected = ['*1 1*']
63+
AssertEqual g:expected, Annotate(g:garden)
64+
65+
Execute (vertical line):
66+
let g:garden = [
67+
\ ' ',
68+
\ '*',
69+
\ ' ',
70+
\ '*',
71+
\ ' ']
72+
let g:expected = [
73+
\ '1',
74+
\ '*',
75+
\ '2',
76+
\ '*',
77+
\ '1']
78+
AssertEqual g:expected, Annotate(g:garden)
79+
80+
Execute (vertical line, flowers at edges):
81+
let g:garden = [
82+
\ '*',
83+
\ ' ',
84+
\ ' ',
85+
\ ' ',
86+
\ '*']
87+
let g:expected = [
88+
\ '*',
89+
\ '1',
90+
\ ' ',
91+
\ '1',
92+
\ '*']
93+
AssertEqual g:expected, Annotate(g:garden)
94+
95+
Execute (cross):
96+
let g:garden = [
97+
\ ' * ',
98+
\ ' * ',
99+
\ '*****',
100+
\ ' * ',
101+
\ ' * ']
102+
let g:expected = [
103+
\ ' 2*2 ',
104+
\ '25*52',
105+
\ '*****',
106+
\ '25*52',
107+
\ ' 2*2 ']
108+
AssertEqual g:expected, Annotate(g:garden)
109+
110+
Execute (large garden):
111+
let g:garden = [
112+
\ ' * * ',
113+
\ ' * ',
114+
\ ' * ',
115+
\ ' * *',
116+
\ ' * * ',
117+
\ ' ']
118+
let g:expected = [
119+
\ '1*22*1',
120+
\ '12*322',
121+
\ ' 123*2',
122+
\ '112*4*',
123+
\ '1*22*2',
124+
\ '111111']
125+
AssertEqual g:expected, Annotate(g:garden)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"
2+
" Given a a list of strings representing a garden,
3+
" mark each cell with the number of flowers in the adjacent cells.
4+
"
5+
function Annotate(garden) abort
6+
" your code goes here
7+
endfunction

0 commit comments

Comments
 (0)