Skip to content

Instantly share code, notes, and snippets.

@harukizaemon
Created December 30, 2011 01:38
Show Gist options
  • Select an option

  • Save harukizaemon/1537171 to your computer and use it in GitHub Desktop.

Select an option

Save harukizaemon/1537171 to your computer and use it in GitHub Desktop.
Parse an OCR'd bank account number
chunk _ [] = []
chunk n xs
| n < 1 = []
| otherwise = first:chunk n remainder
where (first, remainder) = splitAt n xs
parseAccountNumber line1 line2 line3 = map match (chunk 3 columns)
where columns = zip3 line1 line2 line3
match xs = case xs of [(' ', '|', '|'), ('_', ' ', '_'), (' ', '|', '|')] -> '0'
[(' ', ' ', ' '), (' ', ' ', ' '), (' ', '|', '|')] -> '1'
[(' ', ' ', '|'), ('_', '_', '_'), (' ', '|', ' ')] -> '2'
[(' ', ' ', ' '), ('_', '_', '_'), (' ', '|', '|')] -> '3'
[(' ', '|', ' '), (' ', '_', ' '), (' ', '|', '|')] -> '4'
[(' ', '|', ' '), ('_', '_', '_'), (' ', ' ', '|')] -> '5'
[(' ', '|', '|'), ('_', '_', '_'), (' ', ' ', '|')] -> '6'
[(' ', ' ', ' '), ('_', ' ', ' '), (' ', '|', '|')] -> '7'
[(' ', '|', '|'), ('_', '_', '_'), (' ', '|', '|')] -> '8'
[(' ', '|', ' '), ('_', '_', '_'), (' ', '|', '|')] -> '9'
accountNumber = parseAccountNumber " _ _ _ _ _ _ _ _ "
"| | | _| _||_||_ |_ ||_||_|"
"|_| ||_ _| | _||_| ||_| _|"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment