Created
July 1, 2015 11:40
-
-
Save hnq90/dcac861e89232555e8eb to your computer and use it in GitHub Desktop.
Techlooper Contest - Decode Braille
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
| #!/usr/bin/env ruby | |
| # Reference: http://www.loc.gov/nls/reference/braille/card.html | |
| # Contest: http://techlooper.com/#/contest | |
| # HuyNQ | |
| braille_alphabet= [ | |
| '0.....', | |
| '0.0...', | |
| '00....', | |
| '00.0..', | |
| '0..0..', | |
| '000...', | |
| '0000..', | |
| '0.00..', | |
| '.00...', | |
| '.000..', | |
| '0...0.', | |
| '0.0.0.', | |
| '00..0.', | |
| '00.00.', | |
| '0..00.', | |
| '000.0.', | |
| '00000.', | |
| '0.000.', | |
| '.00.0.', | |
| '.0000.', | |
| '0...00', | |
| '0.0.00', | |
| '.000.0', | |
| '00..00', | |
| '00.000', | |
| '0..000', | |
| '......', | |
| '..00.0' | |
| ] | |
| CAP = '.....0' | |
| ASTERISK = '.0.000' | |
| alphabet = 'abcdefghijklmnopqrstuvwxyz .'.split('') | |
| encoded = %(0...00 | |
| ...... | |
| 0.000. | |
| ...... | |
| .00.0. | |
| 00..0. | |
| 0..... | |
| 0.000. | |
| .0000. | |
| ..00.0 | |
| ...... | |
| .....0 | |
| .00.0. | |
| 0..0.. | |
| 00.00. | |
| 00.0.. | |
| ...... | |
| 0..0.. | |
| 00..0. | |
| 0..... | |
| .00... | |
| 0.0.0. | |
| ...... | |
| .0.000 | |
| 0.0... | |
| ...... | |
| 00.... | |
| 0..00. | |
| 00.0.. | |
| 0..0.. | |
| ...... | |
| 0..... | |
| .0000. | |
| ...... | |
| 0.0.00 | |
| .00... | |
| 0..0.. | |
| .0000. | |
| 00.00. | |
| 0..... | |
| 00..0. | |
| .000.0 | |
| 0..00. | |
| 0.000. | |
| 0...0. | |
| .00.0. | |
| ..00.0 | |
| 00.... | |
| 0..00. | |
| 00..0. | |
| ...... | |
| .0.000 | |
| 00.0.. | |
| ...... | |
| .00... | |
| 00.00. | |
| .00.0. | |
| .0000. | |
| 0.000. | |
| 0...00 | |
| 00.... | |
| .0000. | |
| .00... | |
| 0..00. | |
| 00.00. | |
| .00.0.).split("\n") | |
| braille_dict = Hash[braille_alphabet.zip(alphabet)] | |
| decoded = [] | |
| encoded.each_with_index do |e, i| | |
| decoded << | |
| if (encoded[i - 1] == ASTERISK) | |
| braille_alphabet.index(e) + 1 | |
| elsif encoded[i - 1] == CAP | |
| braille_dict[e].capitalize | |
| else | |
| braille_dict[e] | |
| end | |
| end | |
| p decoded.join | |
| # >> "u r smart. Send email 2 code at vietnamworks.com 4 instructions" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment