6 people like it.

Minesweeper Tweet

Minesweeper computation Kata as a tweet (140 characters) not counting code to open namespace and to prepare field as a 2D array.

1: 
2: 
3: 
4: 
5: 
6: 
open System.Linq
let n, m= 4, 4
let field = [|"*..."; "...."; ".*.."; "...."|]
let s = Array2D.init n m (fun y x -> field.[y].[x])
// Tweet
s|>Array2D.mapi(fun x y->function '*'->'*'|_->'0'+char([for i in 0..8->x+i%3-1,y+i/3-1].Count(fun(x,y)->x>=0&&x<n&&y>=0&&y<m&&s.[x,y]='*')))
namespace System
namespace System.Linq
val n : int

Full name: Script.n
val m : int

Full name: Script.m
val field : string []

Full name: Script.field
val s : char [,]

Full name: Script.s
module Array2D

from Microsoft.FSharp.Collections
val init : length1:int -> length2:int -> initializer:(int -> int -> 'T) -> 'T [,]

Full name: Microsoft.FSharp.Collections.Array2D.init
val y : int
val x : int
val mapi : mapping:(int -> int -> 'T -> 'U) -> array:'T [,] -> 'U [,]

Full name: Microsoft.FSharp.Collections.Array2D.mapi
Multiple items
val char : value:'T -> char (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.char

--------------------
type char = System.Char

Full name: Microsoft.FSharp.Core.char
val i : int

More information

Link:http://fssnip.net/ce
Posted:7 years ago
Author:Phillip Trelford
Tags: kata , game