Created
November 18, 2016 11:13
-
-
Save ryoi432/bebc8af5e6b8b63cf4c9598d78e5f6fb to your computer and use it in GitHub Desktop.
This file contains 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 perl | |
use strict; | |
use warnings; | |
# usage: | |
# $ perl decode_nw-7.pl 12121121211112111121121112111121122111111212112 | |
# -> B5468B | |
my %characters = ( | |
'1111122' => '0', | |
'1111221' => '1', | |
'1112112' => '2', | |
'2211111' => '3', | |
'1121121' => '4', | |
'2111121' => '5', | |
'1211112' => '6', | |
'1211211' => '7', | |
'1221111' => '8', | |
'2112111' => '9', | |
'1112211' => '-', | |
'1122111' => '$', | |
'2111212' => ':', | |
'2121112' => '/', | |
'2121211' => '.', | |
'1121212' => '+', | |
'1122121' => 'A', | |
'1212112' => 'B', | |
'1112122' => 'C', | |
'1112221' => 'D', | |
); | |
my $input = $ARGV[0]; | |
my $buf = ""; | |
my $separator_flag = 0; | |
foreach (split //, $input) { | |
if ($separator_flag == 1) { | |
die "decode error: not found separator" if $_ ne "1"; | |
$separator_flag = 0; | |
next; | |
} | |
$buf .= $_; | |
if (length($buf) == 7) { | |
if (!exists($characters{$buf})) { | |
die "decode error: not exist character"; | |
} | |
print $characters{$buf}; | |
$buf = ""; | |
$separator_flag = 1; | |
} | |
} | |
if (length($buf) > 0) { | |
die "decode error: broken code"; | |
} | |
print "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment