Skip to content

I'm yet to see a solution this complex, contrived and comprehensive.

Notifications You must be signed in to change notification settings

di-void/minesweeper-annotate-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Minesweeper

Welcome to Minesweeper on Exercism's Rust Track. If you need help running the tests or submitting your code, check out HELP.md.

Introduction

Minesweeper is a popular game where the user has to find the mines using numeric hints that indicate how many mines are directly adjacent (horizontally, vertically, diagonally) to a square.

Instructions

Your task is to add the mine counts to empty squares in a completed Minesweeper board. The board itself is a rectangle composed of squares that are either empty (' ') or a mine ('*').

For each empty square, count the number of mines adjacent to it (horizontally, vertically, diagonally). If the empty square has no adjacent mines, leave it empty. Otherwise replace it with the adjacent mines count.

For example, you may receive a 5 x 4 board like this (empty spaces are represented here with the '·' character for display on screen):

·*·*·
··*··
··*··
·····

Which your code should transform into this:

1*3*1
13*31
·2*2·
·111·

Performance Hint

All the inputs and outputs are in ASCII. Rust Strings and &str are utf8, so while one might expect "Hello".chars() to be simple, it actually has to check each char to see if it's 1, 2, 3 or 4 u8s long. If we know a &str is ASCII then we can call .as_bytes() and refer to the underlying data as a &[u8] (byte slice). Iterating over a slice of ASCII bytes is much quicker as there are no codepoints involved - every ASCII byte is one u8 long.

Can you complete the challenge without cloning the input?

Source

Created by

  • @EduardoBautista

Contributed to by

  • @ashleygwilliams
  • @coriolinus
  • @cwhakes
  • @EduardoBautista
  • @efx
  • @ErikSchierboom
  • @ffflorian
  • @IanWhitney
  • @kytrinyx
  • @lutostag
  • @mkantor
  • @nfiles
  • @petertseng
  • @rofrol
  • @stringparser
  • @workingjubilee
  • @xakon
  • @ZapAnton

About

I'm yet to see a solution this complex, contrived and comprehensive.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages