Unicode Twitter文本压缩挑战 规则 您的程序必须有两种模式:编码和解码
当编码时:Unicode Twitter文本压缩挑战 规则 您的程序必须有两种模式:编码和解码,unicode,twitter,compression,code-golf,Unicode,Twitter,Compression,Code Golf,当编码时: 您的程序必须输入一些人类可读的Latin1文本,大概是英语。 忽略标点符号并不重要 你只需要担心实际的英语单词,而不是L337 任何带重音的字母都可以转换为简单的ASCII码 您可以选择如何处理数字 123 一二三 一百二十三 123 1 2 3 一百二十三 一二三 一百二十三 123 1 2 3 您的程序必须输出一条可以在中表示的消息 范围U+0000–U+10FFFF 不包括非字符: U+FFFE U+FFFF U+nFFFE,U+nFFFF,其中n是1–10十六
Latin1
文本,大概是英语。
- 忽略标点符号并不重要
- 你只需要担心实际的英语单词,而不是L337
- 任何带重音的字母都可以转换为简单的ASCII码
- 您可以选择如何处理数字
- 123
- 一二三
- 一百二十三
- 123
- 1 2 3
- 一百二十三
- 一二三
- 一百二十三
- 123
- 1 2 3
- 范围
–U+0000
不包括非字符:U+10FFFF
U+FFFE
U+FFFF
U+
n
,FFFE
U+
n
,其中FFFF
是n
–1
十六进制10
–U+FDD0
U+FDEF
–U+D800
(代理代码点)U+DFFF
- 离原文越近越好
- 不需要任何标点符号
- 可以是L337或lol
encode
或decode
作为其第一个参数来设置模式- 从标准输入获取输入,并在标准输出时生成输出。
my program encode output.utf
my program decode output.txt
- 从第二个参数中命名的文件中获取输入,并在第三个参数中命名的文件中生成输出。
my program encode input.txt output.utf
my program decode output.utf output.txt
这些规则是的规则的变体。PAQ8O10T不确定我是否有时间/精力使用实际代码来跟进这些规则,但我的想法如下:
- 任何长度低于一定长度的任意拉丁1字符串都可以简单地编码(甚至不压缩),而不会丢失为140个字符。天真的估计是280个字符,尽管有竞赛规则中的代码点限制,它可能比这个短一点
- 比上述长度稍长的字符串(让guestimate在280到500个字符之间)最有可能使用标准压缩技术压缩为足够短的字符串,以允许进行上述编码
#! perl
use strict;
use warnings;
use 5.010;
use Getopt::Long;
use Pod::Usage;
use autodie;
my %opts = (
infile => '-',
outfile => '-',
);
GetOptions (
'encode|e' => \$opts{encode},
'decode|d' => \$opts{decode},
'infile|i=s' => \$opts{infile},
'outfile|o=s' => \$opts{outfile},
'help|h' => \&help,
'man|m' => \&man,
);
unless(
# exactly one of these should be set
$opts{encode} xor $opts{decode}
){
help();
}
{
my $infile;
if( $opts{infile} ~~ ['-', '&0'] ){
$infile = *STDIN{IO};
}else{
open $infile, '<', $opts{infile};
}
my $outfile;
if( $opts{outfile} ~~ ['-', '&1'] ){
$outfile = *STDOUT{IO};
}elsif( $opts{outfile} ~~ '&2' ){
$outfile = *STDERR{IO};
}else{
open $outfile, '>', $opts{outfile};
}
if( $opts{decode} ){
while( my $line = <$infile> ){
chomp $line;
say {$outfile} $line;
}
}elsif( $opts{encode} ){
while( my $line = <$infile> ){
chomp $line;
$line =~ s/[\W_]+/ /g;
say {$outfile} $line;
}
}else{
die 'How did I get here?';
}
}
sub help{
pod2usage();
}
sub man{
pod2usage(1);
}
__END__
=head1 NAME
sample.pl - Using GetOpt::Long and Pod::Usage
=head1 SYNOPSIS
sample.pl [options] [file ...]
Options:
--help -h brief help message
--man -m full documentation
--encode -e encode text
--decode -d decode text
--infile -i input filename
--outfile -o output filename
=head1 OPTIONS
=over 8
=item B<--help>
Print a brief help message and exits.
=item B<--man>
Prints the manual page and exits.
=item B<--encode>
Removes any character other than /\w/.
=item B<--decode>
Just reads from one file, and writes to the other.
=item B<--infile>
Input filename. If this is '-' or '&0', then read from STDIN instead.
If you use '&0', you must pass it in with quotes.
=item B<--outfile>
Output filename. If this is '-' or '&1', then write to STDOUT instead.
If this is '&2', then write to STDERR instead.
If you use '&1' or '&2', you must pass it in with quotes.
=back
=head1 DESCRIPTION
B<This program> will read the given input file(s) and do something
useful with the contents thereof.
=cut
echo Hello, this is, some text | perl sample.pl -e
Hello this is some text
A white dwarf is a small star composed mostly of electron-degenerate matter. Because a
white dwarf's mass is comparable to that of the Sun and its volume is comparable to that
of the Earth, it is very dense.
A white dwarf be small star composed mostly electron degenerate matter because white
dwarf mass be comparable sun IT volume be comparable earth IT be very dense