exercism/julia/minesweeper/minesweeper.ipynb
2022-08-24 14:28:45 +02:00

69 lines
6.4 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": ["# Minesweeper\n", "\n", "Add the mine counts to a completed Minesweeper board.\n", "\n", "Minesweeper is a popular game where the user has to find the mines using\n", "numeric hints that indicate how many mines are directly adjacent\n", "(horizontally, vertically, diagonally) to a square.\n", "\n", "In this exercise you have to create some code that counts the number of\n", "mines adjacent to a given empty square and replaces that square with the\n", "count.\n", "\n", "The board is a rectangle composed of blank space (' ') characters. A mine\n", "is represented by an asterisk ('\\*') character.\n", "\n", "If a given space has no adjacent mines at all, leave that square blank.\n", "\n", "## Examples\n", "\n", "For example you may receive a 5 x 4 board like this (empty spaces are\n", "represented here with the '·' character for display on screen):\n", "\n", "```\n", "·*·*·\n", "··*··\n", "··*··\n", "·····\n", "```\n", "\n", "And your code will transform it into this:\n", "\n", "```\n", "1*3*1\n", "13*31\n", "·2*2·\n", "·111·\n", "```\n", "\n", "## Version compatibility\n", "This exercise has been tested on Julia versions >=1.0.\n", "\n", "## Submitting Incomplete Solutions\n", "It's possible to submit an incomplete solution so you can see how others have completed the exercise."]
},
{
"cell_type": "markdown",
"metadata": {},
"source": ["## Your solution"]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": ["# submit"]
},
{
"cell_type": "markdown",
"metadata": {},
"source": ["## Test suite"]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": ["using Test\n", "\n", "# include(\"minesweeper.jl\")\n", "\n", "@testset \"no rows\" begin\n", " @test annotate([]) == []\n", "end\n", "\n", "@testset \"no columns\" begin\n", " @test annotate([\"\"]) == [\"\"]\n", "end\n", "\n", "@testset \"no mines\" begin\n", " minefield = [\" \",\n", " \" \",\n", " \" \"]\n", " out = [\" \",\n", " \" \",\n", " \" \"]\n", " @test annotate(minefield) == out\n", "end\n", "\n", "@testset \"minefield only mines\" begin\n", " minefield = [\"***\",\n", " \"***\",\n", " \"***\"]\n", " out = [\"***\",\n", " \"***\",\n", " \"***\"]\n", " @test annotate(minefield) == out\n", "end\n", "\n", "@testset \"mine surrounded by spaces\" begin\n", " minefield = [\" \",\n", " \" * \",\n", " \" \"]\n", " out = [\"111\",\n", " \"1*1\",\n", " \"111\"]\n", " @test annotate(minefield) == out\n", "end\n", "\n", "@testset \"space surrounded by mines\" begin\n", " minefield = [\"***\",\n", " \"* *\",\n", " \"***\"]\n", " out = [\"***\",\n", " \"*8*\",\n", " \"***\"]\n", " @test annotate(minefield) == out\n", "end\n", "\n", "@testset \"horizontal line\" begin\n", " minefield = [\" * * \"]\n", " out = [\"1*2*1\"]\n", " @test annotate(minefield) == out\n", "end\n", "\n", "@testset \"horizontal line mines at edges\" begin\n", " minefield = [\"* *\"]\n", " out = [\"*1 1*\"]\n", " @test annotate(minefield) == out\n", "end\n", "\n", "@testset \"vertical line\" begin\n", " minefield = [\" \",\n", " \"*\",\n", " \" \",\n", " \"*\",\n", " \" \"]\n", " out = [\"1\",\n", " \"*\",\n", " \"2\",\n", " \"*\",\n", " \"1\"]\n", " @test annotate(minefield) == out\n", "end\n", "\n", "@testset \"vertical line mines at edges\" begin\n", " minefield = [\"*\",\n", " \" \",\n", " \" \",\n", " \" \",\n", " \"*\"]\n", " out = [\"*\",\n", " \"1\",\n", " \" \",\n", " \"1\",\n", " \"*\"]\n", " @test annotate(minefield) == out\n", "end\n", "\n", "@testset \"cross\" begin\n", " minefield = [\" * \",\n", " \" * \",\n", " \"*****\",\n", " \" * \",\n", " \" * \"]\n", " out = [\" 2*2 \",\n", " \"25*52\",\n", " \"*****\",\n", " \"25*52\",\n", " \" 2*2 \"]\n", " @test annotate(minefield) == out\n", "end\n", "\n", "@testset \"large minefield\" begin\n", " minefield = [\" * * \",\n", " \" * \",\n", " \" * \",\n", " \" * *\",\n", " \" * * \",\n", " \" \"]\n", " out = [\"1*22*1\",\n", " \"12*322\",\n", " \" 123*2\",\n", " \"112*4*\",\n", " \"1*22*2\",\n", " \"111111\"]\n", " @test annotate(minefield) == out\n", "end"]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Prepare submission\n",
"To submit your exercise, you need to save your solution in a file called `minesweeper.jl` before using the CLI.\n",
"You can either create it manually or use the following functions, which will automatically write every notebook cell that starts with `# submit` to the file `minesweeper.jl`.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# using Pkg; Pkg.add(\"Exercism\")\n",
"# using Exercism\n",
"# Exercism.create_submission(\"minesweeper\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.3.0",
"language": "julia",
"name": "julia-1.3"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.3.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}