0 people like it.

KataBankOCR User Story 1

User Story 1 at http://codingdojo.org/cgi-bin/wiki.pl?KataBankOCR 1. Define a function which retrieves text of a single digit with specified index in text of a number. 2. Make a sequence of texts of each digit of account number. 3. Find indices of text of 0 to 9 digit which satisfies structural equality to them.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
let zeroToNineText = """
 _     _  _     _  _  _  _  _ 
| |  | _| _||_||_ |_   ||_||_|
|_|  ||_  _|  | _||_|  ||_| _|                          
"""

let getDigit (text:string) digit = 
  [| for line in text.Split('\n').[1..3] -> line.Substring (3*digit, 3) |]

let zeroToNine = List.map (getDigit zeroToNineText) [0..9]

let toNumber number =
  Seq.init 9 (fun i -> Seq.findIndex ((=) (getDigit number i)) zeroToNine)
  |> Seq.fold(fun state x -> x + 10 * state) 0
        
let accountNo = """
    _  _  _  _  _  _     _ 
|_||_|| || ||_   |  |  ||_ 
  | _||_||_||_|  |  |  | _| 
"""

let n = toNumber accountNo 
val zeroToNineText : string

Full name: Script.zeroToNineText
val getDigit : text:string -> digit:int -> string []

Full name: Script.getDigit
val text : 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 digit : int
val line : 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 []
System.String.Substring(startIndex: int) : string
System.String.Substring(startIndex: int, length: int) : string
val zeroToNine : string [] list

Full name: Script.zeroToNine
Multiple items
module List

from Microsoft.FSharp.Collections

--------------------
type List<'T> =
  | ( [] )
  | ( :: ) of Head: 'T * Tail: 'T list
  interface IEnumerable
  interface IEnumerable<'T>
  member Head : 'T
  member IsEmpty : bool
  member Item : index:int -> 'T with get
  member Length : int
  member Tail : 'T list
  static member Cons : head:'T * tail:'T list -> 'T list
  static member Empty : 'T list

Full name: Microsoft.FSharp.Collections.List<_>
val map : mapping:('T -> 'U) -> list:'T list -> 'U list

Full name: Microsoft.FSharp.Collections.List.map
val toNumber : number:string -> int

Full name: Script.toNumber
val number : string
module Seq

from Microsoft.FSharp.Collections
val init : count:int -> initializer:(int -> 'T) -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.init
val i : int
val findIndex : predicate:('T -> bool) -> source:seq<'T> -> int

Full name: Microsoft.FSharp.Collections.Seq.findIndex
val fold : folder:('State -> 'T -> 'State) -> state:'State -> source:seq<'T> -> 'State

Full name: Microsoft.FSharp.Collections.Seq.fold
val state : int
val x : int
val accountNo : string

Full name: Script.accountNo
val n : int

Full name: Script.n
Raw view New version

More information

Link:http://fssnip.net/kF
Posted:4 years ago
Author:nagat01
Tags: kata , structural equality