标题: [原创代码] 平分时钟推广到12的倍数 [打印本页]
作者: sxw 时间: 2011-10-9 15:32 标题: 平分时钟推广到12的倍数
可以处理12的倍数,写的很乱,到了720就变得很慢了:- #!/usr/bin/perl
- use strict;
- use warnings;
- print "请输入12的倍数:";
- chomp (my $digit=<STDIN>);
-
-
- use List::Util qw(sum);
- my $i=1;
- my $half_digit=$digit/2;
- my $half_sum=sum(1..$digit)/2;
- my $half_1=$half_sum+1;
- while ($i <= $half_1) {
- my $result=sum($i++..$half_digit++);
- print join " ",$i-1..$half_digit-1 if $half_sum==$result;
-
- }
- print "\n\n\n";
-
- $i=$digit/2+2;
- $half_digit=$digit/2;
- while ($i<=$digit) {
- my $result=sum(1..$digit)-sum($i-$half_digit..$i-1);
- my @num=($i..$digit);
- print join " ",@num,1..$half_digit-@num if $half_sum==$result;
- $i++;
-
- }
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |