We're a place where coders share, stay up-to-date and grow their careers.

F# solution. The problem was badly specified, so here some assumptions:

?

module DailyChallenge [<Literal>] let DigitRows = 3 [<Literal>] let DigitCols = 3 let private isValidInput (input : string list) = input.Length % DigitRows = 0 && List.forall (fun (row : string) -> row.Length % DigitCols = 0) input let private range current max = let rStart = current * max (rStart, rStart + max - 1) let private parseChar = function | [ " _ "; "| |"; "|_|" ] -> "0" | [ " "; " |"; " |" ] -> "1" | [ " _ "; " _|"; "|_ " ] -> "2" | [ " _ "; " _|"; " _|" ] -> "3" | [ " "; "|_|"; " |" ] -> "4" | [ " _ "; "|_ "; " _|" ] -> "5" | [ " _ "; "|_ "; "|_|" ] -> "6" | [ " _ "; " |"; " |" ] -> "7" | [ " _ "; "|_|"; "|_|" ] -> "8" | [ " _ "; "|_|"; " _|" ] -> "9" | _ -> "?" let private parseInput (input : string list) = seq { for row in 0 .. input.Length / DigitRows - 1 do let rStart, rEnd = range row DigitRows for col in 0 .. input.[0].Length / DigitCols - 1 do let cStart, cEnd = range col DigitCols yield input.[rStart..rEnd] |> List.map (fun (row : string) -> row.[cStart..cEnd]) |> parseChar } |> System.String.Concat let convert input = if isValidInput input then Some(parseInput input) else None

Tests:

module DailyChallengeTests open FsUnit.Xunit open Xunit open DailyChallenge [<Fact>] let ``023056789``() = let rows = [ " _ _ _ _ _ _ _ _ _ " "| | _| _|| ||_ |_ ||_||_|" "|_||_ _||_| _||_| ||_| _|" ] convert rows |> should equal (Some "023056789") [<Fact>] let ``823856989``() = let rows = [ " _ _ _ _ _ _ _ _ _ " "|_| _| _||_||_ |_ |_||_||_|" "|_||_ _||_| _||_| _||_| _|" ] convert rows |> should equal (Some "823856989") [<Fact>] let ``123456789``() = let rows = [ " _ _ _ _ _ _ _ " " | _| _||_||_ |_ ||_||_|" " ||_ _| | _||_| ||_| _|" ] convert rows |> should equal (Some "123456789") [<Fact>] let ``invalid``() = let rows = [ " _ _ _ _ _ _ _ " ] convert rows |> should equal None [<Fact>] let ``uncrecognized character``() = let rows = [ " _ _ _ _ _ _ _ " "| _| _||_||_ |_ ||_||_|" "| |_ _| | _||_| ||_| _|" ] convert rows |> should equal (Some "?23456789")

## re: Daily Challenge #222 - Parse Bank Account Numbers VIEW POST

FULL DISCUSSIONF# solution. The problem was badly specified, so here some assumptions:

`?`

in the output.Tests: