Skip to content

Commit f735eda

Browse files
authored
Add flower-field (#375)
* Deprecate `minesweeper` * Add `flower-field`
1 parent d58142d commit f735eda

File tree

8 files changed

+267
-1
lines changed

8 files changed

+267
-1
lines changed

config.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,13 +830,22 @@
830830
"prerequisites": [],
831831
"difficulty": 5
832832
},
833+
{
834+
"slug": "flower-field",
835+
"name": "Flower Field",
836+
"uuid": "02887f9c-e666-439b-a726-03c35dfb5f2c",
837+
"practices": [],
838+
"prerequisites": [],
839+
"difficulty": 8
840+
},
833841
{
834842
"slug": "minesweeper",
835843
"name": "Minesweeper",
836844
"uuid": "fe341c5e-0292-455f-93be-1ffb8f0b4b3b",
837845
"practices": [],
838846
"prerequisites": [],
839-
"difficulty": 8
847+
"difficulty": 8,
848+
"status": "deprecated"
840849
},
841850
{
842851
"slug": "simple-linked-list",
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.coffee"
8+
],
9+
"test": [
10+
"flower-field.spec.coffee"
11+
],
12+
"example": [
13+
".meta/example.coffee"
14+
]
15+
},
16+
"blurb": "Mark all the flowers in a garden."
17+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class FlowerField
2+
@annotate: (garden) ->
3+
if garden.length < 1
4+
return garden
5+
if garden[0].length < 1
6+
return garden
7+
8+
board = garden.map (row) -> row.split ''
9+
10+
board.map (row, x) ->
11+
r = row.map (cell, y) ->
12+
if cell == '*'
13+
return cell
14+
count = 0
15+
for i in [-1..1]
16+
for j in [-1..1]
17+
if i + x >= 0 && i + x < board.length && j + y >= 0 && j + y < row.length
18+
count += 1 if board[i + x][j + y] == '*'
19+
if count == 0
20+
' '
21+
else
22+
count.toString()
23+
r.join ''
24+
25+
module.exports = FlowerField
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class FlowerField
2+
@annotate: (garden) ->
3+
4+
module.exports = FlowerField
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
FlowerField = require './flower-field'
2+
3+
describe 'Flower Field', ->
4+
it 'no rows', ->
5+
garden = []
6+
expect(FlowerField.annotate garden).toEqual []
7+
8+
xit 'no columns', ->
9+
garden = ['']
10+
expect(FlowerField.annotate garden).toEqual ['']
11+
12+
xit 'no flowers', ->
13+
garden = [
14+
' '
15+
' '
16+
' '
17+
]
18+
expect(FlowerField.annotate garden).toEqual [
19+
' '
20+
' '
21+
' '
22+
]
23+
24+
xit 'garden full of flowers', ->
25+
garden = [
26+
'***'
27+
'***'
28+
'***'
29+
]
30+
expect(FlowerField.annotate garden).toEqual [
31+
'***'
32+
'***'
33+
'***'
34+
]
35+
36+
xit 'flower surrounded by spaces', ->
37+
garden = [
38+
' '
39+
' * '
40+
' '
41+
]
42+
expect(FlowerField.annotate garden).toEqual [
43+
'111'
44+
'1*1'
45+
'111'
46+
]
47+
48+
xit 'space surrounded by flowers', ->
49+
garden = [
50+
'***'
51+
'* *'
52+
'***'
53+
]
54+
expect(FlowerField.annotate garden).toEqual [
55+
'***'
56+
'*8*'
57+
'***'
58+
]
59+
60+
xit 'horizontal line', ->
61+
garden = [' * * ']
62+
expect(FlowerField.annotate garden).toEqual ['1*2*1']
63+
64+
xit 'horizontal line, flowers at edges', ->
65+
garden = ['* *']
66+
expect(FlowerField.annotate garden).toEqual ['*1 1*']
67+
68+
xit 'vertical line', ->
69+
garden = [
70+
' '
71+
'*'
72+
' '
73+
'*'
74+
' '
75+
]
76+
expect(FlowerField.annotate garden).toEqual [
77+
'1'
78+
'*'
79+
'2'
80+
'*'
81+
'1'
82+
]
83+
84+
xit 'vertical line, flowers at edges', ->
85+
garden = [
86+
'*'
87+
' '
88+
' '
89+
' '
90+
'*'
91+
]
92+
expect(FlowerField.annotate garden).toEqual [
93+
'*'
94+
'1'
95+
' '
96+
'1'
97+
'*'
98+
]
99+
100+
xit 'cross', ->
101+
garden = [
102+
' * '
103+
' * '
104+
'*****'
105+
' * '
106+
' * '
107+
]
108+
expect(FlowerField.annotate garden).toEqual [
109+
' 2*2 '
110+
'25*52'
111+
'*****'
112+
'25*52'
113+
' 2*2 '
114+
]
115+
116+
xit 'large garden', ->
117+
garden = [
118+
' * * '
119+
' * '
120+
' * '
121+
' * *'
122+
' * * '
123+
' '
124+
]
125+
expect(FlowerField.annotate garden).toEqual [
126+
'1*22*1'
127+
'12*322'
128+
' 123*2'
129+
'112*4*'
130+
'1*22*2'
131+
'111111'
132+
]

0 commit comments

Comments
 (0)