Skip to content

Commit 7d48fd6

Browse files
authored
Add flower-field, deprecating minesweeper (#425)
1 parent a6e636e commit 7d48fd6

File tree

8 files changed

+271
-1
lines changed

8 files changed

+271
-1
lines changed

config.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,14 @@
708708
"prerequisites": [],
709709
"difficulty": 8
710710
},
711+
{
712+
"slug": "flower-field",
713+
"name": "Flower Field",
714+
"uuid": "a75c6bf8-81be-43b2-b483-97e34d03f296",
715+
"practices": [],
716+
"prerequisites": [],
717+
"difficulty": 8
718+
},
711719
{
712720
"slug": "luhn",
713721
"name": "Luhn",
@@ -722,7 +730,8 @@
722730
"uuid": "a7bd6275-b624-4c09-9040-4b57afe1c4b6",
723731
"practices": [],
724732
"prerequisites": [],
725-
"difficulty": 8
733+
"difficulty": 8,
734+
"status": "deprecated"
726735
},
727736
{
728737
"slug": "parallel-letter-frequency",
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"authors": [
3+
"blakelewis"
4+
],
5+
"contributors": [
6+
"BNAndras"
7+
],
8+
"files": {
9+
"solution": [
10+
"flower-field.rkt"
11+
],
12+
"test": [
13+
"flower-field-test.rkt"
14+
],
15+
"example": [
16+
".meta/example.rkt"
17+
]
18+
},
19+
"blurb": "Mark all the flowers in a garden."
20+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#lang racket
2+
3+
(provide annotate)
4+
5+
(define (flower-at loc row)
6+
(cond [(null? row) 0]
7+
[(negative? loc) 0]
8+
[(>= loc (string-length row)) 0]
9+
[else (let ([c (string-ref row loc)])
10+
(if (char=? c #\*) 1 0))]))
11+
12+
13+
(define (flowers-around loc row)
14+
(+ (flower-at (sub1 loc) row) (flower-at loc row) (flower-at (add1 loc) row)))
15+
16+
(define (make-annotated-row top middle bottom)
17+
(list->string
18+
(for/list ([c (in-string middle)]
19+
[i (in-range (string-length middle))])
20+
(if (char=? c #\space)
21+
(let ([b (+ (flowers-around i top)
22+
(flowers-around i middle)
23+
(flowers-around i bottom))])
24+
(if (zero? b) #\space (integer->char (+ b (char->integer #\0)))))
25+
c))))
26+
27+
(define (following-row i field)
28+
(if (>= (add1 i) (length field)) '() (list-ref field (add1 i))))
29+
30+
(define (annotate garden)
31+
(for/fold ([out '()]
32+
[top '()]
33+
[middle (following-row -1 garden)]
34+
[bottom (following-row 0 garden)]
35+
#:result (reverse out))
36+
([i (in-inclusive-range 1 (length garden))])
37+
(values (cons (make-annotated-row top middle bottom) out)
38+
middle bottom (following-row i garden))))
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: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#lang racket/base
2+
3+
(require "flower-field.rkt")
4+
5+
(module+ test
6+
(require rackunit rackunit/text-ui))
7+
8+
(module+ test
9+
(define suite
10+
(test-suite
11+
"flower field tests"
12+
(test-equal? "no rows"
13+
(annotate '())
14+
'())
15+
16+
(test-equal? "no columns"
17+
(annotate '(""))
18+
'(""))
19+
20+
(test-equal? "no flowers"
21+
(annotate
22+
'(" "
23+
" "
24+
" "))
25+
'(" "
26+
" "
27+
" "))
28+
29+
(test-equal? "garden full of flowers"
30+
(annotate
31+
'("***"
32+
"***"
33+
"***"))
34+
'("***"
35+
"***"
36+
"***"))
37+
38+
(test-equal? "flower surrounded by spaces"
39+
(annotate
40+
'(" "
41+
" * "
42+
" "))
43+
'("111"
44+
"1*1"
45+
"111"))
46+
47+
(test-equal? "space surrounded by flowers"
48+
(annotate
49+
'("***"
50+
"* *"
51+
"***"))
52+
'("***"
53+
"*8*"
54+
"***"))
55+
56+
(test-equal? "horizontal line"
57+
(annotate '(" * * "))
58+
'("1*2*1"))
59+
60+
(test-equal? "horizontal line, flowers at edges"
61+
(annotate '("* *"))
62+
'("*1 1*"))
63+
64+
(test-equal? "vertical line"
65+
(annotate
66+
'(" "
67+
"*"
68+
" "
69+
"*"
70+
" "))
71+
'("1"
72+
"*"
73+
"2"
74+
"*"
75+
"1"))
76+
77+
(test-equal? "vertical line, flowers at edges"
78+
(annotate
79+
'("*"
80+
" "
81+
" "
82+
" "
83+
"*"))
84+
'("*"
85+
"1"
86+
" "
87+
"1"
88+
"*"))
89+
90+
(test-equal? "cross"
91+
(annotate
92+
'(" * "
93+
" * "
94+
"*****"
95+
" * "
96+
" * "))
97+
'(" 2*2 "
98+
"25*52"
99+
"*****"
100+
"25*52"
101+
" 2*2 "))
102+
103+
(test-equal? "large garden"
104+
(annotate
105+
'(" * * "
106+
" * "
107+
" * "
108+
" * *"
109+
" * * "
110+
" "))
111+
'("1*22*1"
112+
"12*322"
113+
" 123*2"
114+
"112*4*"
115+
"1*22*2"
116+
"111111"))))
117+
118+
(run-tests suite))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#lang racket
2+
3+
(provide annotate)
4+
5+
(define (annotate garden)
6+
(error "Not implemented yet"))

0 commit comments

Comments
 (0)