1 people like it.
Like the snippet!
Bank OCR
User Story 1 from the Bank OCR Kata: http://codingdojo.org/cgi-bin/wiki.pl?KataBankOCR
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
|
let zeroToNineText = """
_ _ _ _ _ _ _ _
| | | _| _||_||_ |_ ||_||_|
|_| ||_ _| | _||_| ||_| _|
"""
let getDigits (source:string) len =
let lines = source.Split([|'\n'|]).[1..3]
[|for digit in 0..len-1 ->
let index = digit*3
[|for line in lines ->
line.[index..index+2]
|]
|> String.concat "\n"
|]
let zeroToNine = getDigits zeroToNineText 10
let toNumber text =
getDigits text 9
|> Array.rev
|> Array.fold (fun (result,tens) digit ->
let n = zeroToNine |> Array.findIndex ((=) digit)
result + n * tens, tens * 10
) (0,1)
|> fst
let accountNo = """
_ _ _ _ _ _ _
|_||_|| || ||_ | | ||_
| _||_||_||_| | | | _|
"""
let n = toNumber accountNo
|
val zeroToNineText : string
Full name: Script.zeroToNineText
val getDigits : source:string -> len:int -> string []
Full name: Script.getDigits
val source : string
Multiple items
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = System.String
Full name: Microsoft.FSharp.Core.string
val len : int
val lines : string []
System.String.Split([<System.ParamArray>] separator: char []) : string []
System.String.Split(separator: string [], options: System.StringSplitOptions) : string []
System.String.Split(separator: char [], options: System.StringSplitOptions) : string []
System.String.Split(separator: char [], count: int) : string []
System.String.Split(separator: string [], count: int, options: System.StringSplitOptions) : string []
System.String.Split(separator: char [], count: int, options: System.StringSplitOptions) : string []
val digit : int
val index : int
val line : string
module String
from Microsoft.FSharp.Core
val concat : sep:string -> strings:seq<string> -> string
Full name: Microsoft.FSharp.Core.String.concat
val zeroToNine : string []
Full name: Script.zeroToNine
val toNumber : text:string -> int
Full name: Script.toNumber
val text : string
module Array
from Microsoft.FSharp.Collections
val rev : array:'T [] -> 'T []
Full name: Microsoft.FSharp.Collections.Array.rev
val fold : folder:('State -> 'T -> 'State) -> state:'State -> array:'T [] -> 'State
Full name: Microsoft.FSharp.Collections.Array.fold
val result : int
val tens : int
val digit : string
val n : int
val findIndex : predicate:('T -> bool) -> array:'T [] -> int
Full name: Microsoft.FSharp.Collections.Array.findIndex
val fst : tuple:('T1 * 'T2) -> 'T1
Full name: Microsoft.FSharp.Core.Operators.fst
val accountNo : string
Full name: Script.accountNo
val n : int
Full name: Script.n
More information