Skip to content
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
17 changes: 13 additions & 4 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
"representer": false,
"analyzer": false
},
"test_runner": {
"average_run_time": 1
},
"blurb": "YAMLScript is a dynamic, general purpose programming language. It has a clean YAML syntax and embeds nicely into existing YAML files, making the desired parts of them dynamic. When a YAMLScript program is run, the source code transpiles to Clojure code, and is evaluted by a native binary runtime interpreter called `ys` (not by the JVM).",
"version": 3,
"online_editor": {
"indent_style": "space",
"indent_size": 2
},
"test_runner": {
"average_run_time": 1
},
"files": {
"solution": [
"%{kebab_slug}.ys"
Expand Down Expand Up @@ -508,13 +508,22 @@
"prerequisites": [],
"difficulty": 8
},
{
"slug": "flower-field",
"name": "Flower Field",
"uuid": "911b5139-299b-4c92-8dea-cf1bfa75ba2f",
"practices": [],
"prerequisites": [],
"difficulty": 8
},
{
"slug": "minesweeper",
"name": "Minesweeper",
"uuid": "4e7dd5dd-a6b6-4d8c-be9c-7a5995a86de9",
"practices": [],
"prerequisites": [],
"difficulty": 8
"difficulty": 8,
"status": "deprecated"
}
]
},
Expand Down
14 changes: 11 additions & 3 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ status:
representer: false
analyzer: false

test_runner:
average_run_time: 1

blurb:
YAMLScript is a dynamic, general purpose programming language.
It has a clean YAML syntax and embeds nicely into existing YAML files, making
Expand All @@ -29,6 +26,9 @@ online_editor:
indent_style: space
indent_size: 2

test_runner:
average_run_time: 1

files:
solution:
- '%{kebab_slug}.ys'
Expand Down Expand Up @@ -456,12 +456,20 @@ exercises:
prerequisites: []
difficulty: 8

- slug: flower-field
name: Flower Field
uuid: 911b5139-299b-4c92-8dea-cf1bfa75ba2f
practices: []
prerequisites: []
difficulty: 8

- slug: minesweeper
name: Minesweeper
uuid: 4e7dd5dd-a6b6-4d8c-be9c-7a5995a86de9
practices: []
prerequisites: []
difficulty: 8
status: deprecated

tags:
- execution_mode/compiled
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/
28 changes: 28 additions & 0 deletions exercises/practice/flower-field/.meta/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
SHELL := bash

BASE := $(shell pwd)

export YS_VERSION := 0.1.96

YS_LOCAL_PREFIX := ../../../../.local/v$(YS_VERSION)

YS_LOCAL_BIN := $(YS_LOCAL_PREFIX)/bin

YS_BIN := $(YS_LOCAL_BIN)/ys-$(YS_VERSION)

TEST_FILE ?= $(wildcard *-test.ys)


export PATH := $(YS_LOCAL_BIN):$(PATH)

export YSPATH := $(BASE)


default:

test: $(YS_BIN)
prove -v $(TEST_FILE)

$(YS_BIN):
curl -s https://yamlscript.org/install | \
BIN=1 VERSION=$(YS_VERSION) PREFIX=$(YS_LOCAL_PREFIX) bash >/dev/null
23 changes: 23 additions & 0 deletions exercises/practice/flower-field/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"authors": [
"ingydotnet"
],
"contributors": [
"BNAndras"
],
"files": {
"solution": [
"flower-field.ys"
],
"test": [
"flower-field-test.ys",
"GNUmakefile",
"Makefile",
".yamlscript/exercism-ys-installer"
],
"example": [
".meta/flower-field.ys"
]
},
"blurb": "Mark all the flowers in a garden."
}
91 changes: 91 additions & 0 deletions exercises/practice/flower-field/.meta/flower-field-test.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env ys-0

use ys::taptest: :all
load: 'flower-field.ys'

test::
- name: No rows
code: annotate([])
want: []

- name: No columns
code: annotate([""])
want:
- ''

- name: No flowers
code: annotate([" " " " " "])
want:
- ' '
- ' '
- ' '

- name: garden full of flowers
code: annotate(["***" "***" "***"])
want:
- '***'
- '***'
- '***'

- name: flower surrounded by spaces
code: annotate([" " " * " " "])
want:
- '111'
- 1*1
- '111'

- name: Space surrounded by flowers
code: annotate(["***" "* *" "***"])
want:
- '***'
- '*8*'
- '***'

- name: Horizontal line
code: annotate([" * * "])
want:
- 1*2*1

- name: Horizontal line, flowers at edges
code: annotate(["* *"])
want:
- '*1 1*'

- name: Vertical line
code: annotate([" " "*" " " "*" " "])
want:
- '1'
- '*'
- '2'
- '*'
- '1'

- name: Vertical line, flowers at edges
code: annotate(["*" " " " " " " "*"])
want:
- '*'
- '1'
- ' '
- '1'
- '*'

- name: Cross
code: annotate([" * " " * " "*****" " * " " * "])
want:
- ' 2*2 '
- 25*52
- '*****'
- 25*52
- ' 2*2 '

- name: Large garden
code: annotate([" * * " " * " " * " " * *" " * * " " "])
want:
- 1*22*1
- 12*322
- ' 123*2'
- 112*4*
- 1*22*2
- '111111'

done: 12
19 changes: 19 additions & 0 deletions exercises/practice/flower-field/.meta/flower-field.ys
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
!YS-v0

defn annotate(garden):
map-indexed _ garden:
fn(r row): !:join
map-indexed _ row:
fn(c col):
list =:
? for x [-1 0 1],
y [-1 0 1]
:when garden
.get(r + x)
.get(c + y)
.eq(\\*)
: 1
cond:
list.#.!: \\space
col == \\*: col
else: \\0 + list.#
46 changes: 46 additions & 0 deletions exercises/practice/flower-field/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[237ff487-467a-47e1-9b01-8a891844f86c]
description = "no rows"

[4b4134ec-e20f-439c-a295-664c38950ba1]
description = "no columns"

[d774d054-bbad-4867-88ae-069cbd1c4f92]
description = "no flowers"

[225176a0-725e-43cd-aa13-9dced501f16e]
description = "garden full of flowers"

[3f345495-f1a5-4132-8411-74bd7ca08c49]
description = "flower surrounded by spaces"

[6cb04070-4199-4ef7-a6fa-92f68c660fca]
description = "space surrounded by flowers"

[272d2306-9f62-44fe-8ab5-6b0f43a26338]
description = "horizontal line"

[c6f0a4b2-58d0-4bf6-ad8d-ccf4144f1f8e]
description = "horizontal line, flowers at edges"

[a54e84b7-3b25-44a8-b8cf-1753c8bb4cf5]
description = "vertical line"

[b40f42f5-dec5-4abc-b167-3f08195189c1]
description = "vertical line, flowers at edges"

[58674965-7b42-4818-b930-0215062d543c]
description = "cross"

[dd9d4ca8-9e68-4f78-a677-a2a70fd7a7b8]
description = "large garden"
Loading