Skip to content

Commit 7d4c9bf

Browse files
Add flower-field exercise (#54)
1 parent dda7ef3 commit 7d4c9bf

File tree

8 files changed

+193
-0
lines changed

8 files changed

+193
-0
lines changed

config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,14 @@
358358
"prerequisites": [],
359359
"difficulty": 5
360360
},
361+
{
362+
"slug": "flower-field",
363+
"name": "Flower Field",
364+
"uuid": "f0ba257c-3432-439e-b2b7-706e7f4ad87d",
365+
"practices": [],
366+
"prerequisites": [],
367+
"difficulty": 6
368+
},
361369
{
362370
"slug": "intergalactic-transmission",
363371
"name": "Intergalactic Transmission",
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+
"keiravillekode"
4+
],
5+
"files": {
6+
"solution": [
7+
"flower_field.fut"
8+
],
9+
"test": [
10+
"test.fut"
11+
],
12+
"example": [
13+
".meta/example.fut"
14+
]
15+
},
16+
"blurb": "Mark all the flowers in a garden."
17+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
def annotate_square [m] [n] (garden: [m][n]u8) (i: i64) (j: i64): u8 =
3+
if garden[i][j] == '*' then '*' else
4+
let count = loop count = 0u8 for k in 0..<9 do
5+
let i2 = i + (k / 3) - 1
6+
let j2 = j + (k % 3) - 1
7+
in
8+
if i2 < 0 || i2 >= m || j2 < 0 || j2 >= n || garden[i2][j2] != '*' then count else
9+
count + 1
10+
in
11+
if count == 0 then ' ' else
12+
'0' + count
13+
14+
def annotate_row [m] [n] (garden: [m][n]u8) (i: i64): [n]u8 =
15+
let b = loop b = copy garden[i] for j in 0..<n do
16+
b with [j] = annotate_square garden i j
17+
in
18+
b
19+
20+
def annotate [m] [n] (garden: [m][n]u8): [m][n]u8 =
21+
let a = loop a = copy garden for i in 0..<m do
22+
a with [i] = annotate_row garden i
23+
in
24+
a
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def annotate [m] [n] (garden: [m][n]u8): [m][n]u8 = ???
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import "flower_field"
2+
3+
-- no rows
4+
-- ==
5+
-- input { empty([0][0]u8) }
6+
-- output { empty([0][0]u8) }
7+
8+
-- no columns
9+
-- ==
10+
-- input { [""] }
11+
-- output { [""] }
12+
13+
-- no flowers
14+
-- ==
15+
-- input { [" ", " ", " "] }
16+
-- output { [" ", " ", " "] }
17+
18+
-- garden full of flowers
19+
-- ==
20+
-- input { ["***", "***", "***"] }
21+
-- output { ["***", "***", "***"] }
22+
23+
-- flower surrounded by spaces
24+
-- ==
25+
-- input { [" ", " * ", " "] }
26+
-- output { ["111", "1*1", "111"] }
27+
28+
-- space surrounded by flowers
29+
-- ==
30+
-- input { ["***", "* *", "***"] }
31+
-- output { ["***", "*8*", "***"] }
32+
33+
-- horizontal line
34+
-- ==
35+
-- input { [" * * "] }
36+
-- output { ["1*2*1"] }
37+
38+
-- horizontal line, flowers at edges
39+
-- ==
40+
-- input { ["* *"] }
41+
-- output { ["*1 1*"] }
42+
43+
-- vertical line
44+
-- ==
45+
-- input { [" ", "*", " ", "*", " "] }
46+
-- output { ["1", "*", "2", "*", "1"] }
47+
48+
-- vertical line, flowers at edges
49+
-- ==
50+
-- input { ["*", " ", " ", " ", "*"] }
51+
-- output { ["*", "1", " ", "1", "*"] }
52+
53+
-- cross
54+
-- ==
55+
-- input { [" * ", " * ", "*****", " * ", " * "] }
56+
-- output { [" 2*2 ", "25*52", "*****", "25*52", " 2*2 "] }
57+
58+
-- large garden
59+
-- ==
60+
-- input { [" * * ", " * ", " * ", " * *", " * * ", " "] }
61+
-- output { ["1*22*1", "12*322", " 123*2", "112*4*", "1*22*2", "111111"] }
62+
63+
let main [m] [n] (garden: [m][n]u8): [m][n]u8 =
64+
annotate garden

0 commit comments

Comments
 (0)