Created
December 30, 2011 01:38
-
-
Save harukizaemon/1537171 to your computer and use it in GitHub Desktop.
Parse an OCR'd bank account number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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