Skip to content

flower-field replaces minesweeper #1289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ jobs:
# most of the time caches should hit.
echo "::set-output name=week-no::$(date -u +%Y-%U)"

- uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9
- uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684
id: cache
with:
path: |
Expand Down
84 changes: 40 additions & 44 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,60 +42,60 @@
"slug": "lucians-luscious-lasagna",
"name": "Lucian's Luscious Lasagna",
"uuid": "3aa220cb-606f-45c5-9b7a-4bce0e4eb20d",
"prerequisites": [],
"status": "beta",
"concepts": [
"basics"
]
],
"prerequisites": [],
"status": "beta"
},
{
"slug": "temperature",
"name": "Temperature",
"uuid": "6ed15adb-f022-4bbd-bbb3-22845deabc91",
"concepts": [
"numbers"
],
"prerequisites": [
"basics"
],
"status": "beta",
"concepts": [
"numbers"
]
"status": "beta"
},
{
"slug": "pacman-rules",
"name": "Pac-Man Rules",
"uuid": "9050f8c3-9976-4c4d-93e7-c9c549b1c524",
"concepts": [
"booleans"
],
"prerequisites": [
"basics"
],
"status": "wip",
"concepts": [
"booleans"
]
"status": "wip"
},
{
"slug": "guessing-game",
"name": "Guessing Game",
"uuid": "fb9868eb-ce4f-4e6b-aa0d-b47d3451070f",
"concepts": [
"pattern-matching-literals"
],
"prerequisites": [
"numbers"
],
"status": "beta",
"concepts": [
"pattern-matching-literals"
]
"status": "beta"
},
{
"slug": "valentines-day",
"name": "Valentines Day",
"uuid": "537d8df3-0b12-4dbe-aa86-65ae79c4de0e",
"concepts": [
"algebraic-data-types"
],
"prerequisites": [
"pattern-matching-literals",
"numbers"
],
"status": "beta",
"concepts": [
"algebraic-data-types"
]
"status": "beta"
}
],
"practice": [
Expand Down Expand Up @@ -297,8 +297,7 @@
"uuid": "dde7cf64-7e3b-4e5c-8a65-5d639fa8a307",
"practices": [],
"prerequisites": [],
"difficulty": 5,
"topics": []
"difficulty": 5
},
{
"slug": "luhn",
Expand All @@ -325,23 +324,30 @@
"number_theory"
]
},
{
"slug": "flower-field",
"name": "Flower Field",
"uuid": "1eff202c-ef0c-43d2-9077-7837914bc8b0",
"practices": [],
"prerequisites": [],
"difficulty": 7
},
{
"slug": "minesweeper",
"name": "Minesweeper",
"uuid": "821f2081-dfc2-40c6-8e12-2907daa04416",
"practices": [],
"prerequisites": [],
"difficulty": 7,
"topics": []
"status": "deprecated"
},
{
"slug": "game-of-life",
"name": "Game of Life",
"uuid": "eb221634-15c6-463c-8268-54a3c3aa0c66",
"practices": [],
"prerequisites": [],
"difficulty": 7,
"topics": []
"difficulty": 7
},
{
"slug": "perfect-numbers",
Expand Down Expand Up @@ -496,8 +502,7 @@
"uuid": "00b6c83b-e652-4f71-a094-b3034f77fd7b",
"practices": [],
"prerequisites": [],
"difficulty": 4,
"topics": []
"difficulty": 4
},
{
"slug": "food-chain",
Expand Down Expand Up @@ -868,8 +873,7 @@
"uuid": "01401d15-6667-4f94-bcd2-ec5a70df1cc6",
"practices": [],
"prerequisites": [],
"difficulty": 4,
"topics": []
"difficulty": 4
},
{
"slug": "sieve",
Expand Down Expand Up @@ -926,8 +930,7 @@
"uuid": "78971281-153d-4bdc-8f90-4b7eded2b201",
"practices": [],
"prerequisites": [],
"difficulty": 8,
"topics": []
"difficulty": 8
},
{
"slug": "pov",
Expand Down Expand Up @@ -1042,8 +1045,7 @@
"uuid": "f49d76f7-f826-4b6a-a514-47af7e84144a",
"practices": [],
"prerequisites": [],
"difficulty": 6,
"topics": []
"difficulty": 6
},
{
"slug": "sgf-parsing",
Expand Down Expand Up @@ -1097,8 +1099,7 @@
"uuid": "7157a846-5846-47a4-97c2-daad7f763512",
"practices": [],
"prerequisites": [],
"difficulty": 3,
"topics": []
"difficulty": 3
},
{
"slug": "roman-numerals",
Expand Down Expand Up @@ -1302,7 +1303,6 @@
"practices": [],
"prerequisites": [],
"difficulty": 1,
"topics": null,
"status": "deprecated"
},
{
Expand All @@ -1312,7 +1312,6 @@
"practices": [],
"prerequisites": [],
"difficulty": 1,
"topics": null,
"status": "deprecated"
},
{
Expand All @@ -1322,7 +1321,6 @@
"practices": [],
"prerequisites": [],
"difficulty": 1,
"topics": null,
"status": "deprecated"
},
{
Expand All @@ -1332,7 +1330,6 @@
"practices": [],
"prerequisites": [],
"difficulty": 1,
"topics": null,
"status": "deprecated"
},
{
Expand All @@ -1342,7 +1339,6 @@
"practices": [],
"prerequisites": [],
"difficulty": 1,
"topics": null,
"status": "deprecated"
},
{
Expand Down Expand Up @@ -1443,15 +1439,15 @@
}
],
"tags": [
"execution_mode/compiled",
"paradigm/declarative",
"paradigm/functional",
"typing/static",
"typing/strong",
"execution_mode/compiled",
"platform/windows",
"platform/mac",
"platform/linux",
"platform/mac",
"platform/windows",
"runtime/standalone_executable",
"typing/static",
"typing/strong",
"used_for/backends",
"used_for/financial_systems"
]
Expand Down
26 changes: 26 additions & 0 deletions exercises/practice/flower-field/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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·
```
7 changes: 7 additions & 0 deletions exercises/practice/flower-field/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -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/
33 changes: 33 additions & 0 deletions exercises/practice/flower-field/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"authors": [
"etrepum"
],
"contributors": [
"ffflorian",
"iHiD",
"keiravillekode",
"kytrinyx",
"lpalma",
"petertseng",
"ppartarr",
"rbasso",
"sshine",
"tejasbubane"
],
"files": {
"solution": [
"src/FlowerField.hs",
"package.yaml"
],
"test": [
"test/Tests.hs"
],
"example": [
".meta/examples/success-standard/src/FlowerField.hs"
],
"invalidator": [
"stack.yaml"
]
},
"blurb": "Mark all the flowers in a garden."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: flower-field

dependencies:
- base

library:
exposed-modules: FlowerField
source-dirs: src

tests:
test:
main: Tests.hs
source-dirs: test
dependencies:
- flower-field
- hspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module FlowerField (annotate) where

import Data.Char (intToDigit)
import Data.Maybe (mapMaybe)

annotate :: [String] -> [String]
annotate xss = [[ fixTile x (i, j)
| (j, x ) <- zip [0..] xs ]
| (i, xs) <- zip [0..] xss ]
where

flowers = length . filter (== '*') . mapMaybe (`lookup` tiles) . neighbors

fixTile ' ' position = case flowers position of
0 -> ' '
x -> intToDigit x
fixTile x _ = x

neighbors (i, j) = [ (i - 1, j - 1), (i - 1, j), (i - 1, j + 1)
, (i , j - 1), (i , j + 1)
, (i + 1, j - 1), (i + 1, j), (i + 1, j + 1) ]

tiles = [ ((i, j), x)
| (i, xs) <- zip [0 :: Int ..] xss
, (j, x ) <- zip [0 :: Int ..] xs ]
Loading
Loading