标题: [技术讨论] 做题:数字黑洞一例(523066680版主出的) [打印本页]
作者: sxw 时间: 2011-10-18 21:39 标题: 做题:数字黑洞一例(523066680版主出的)
批版的601997526 已经写出来了,俺写个Perl版的:- #!/usr/bin/perl
- use strict;
- use warnings;
-
- while (1) {
- print "Type a number between 1000-9999:";
- chomp (my $num=<STDIN>);
- redo if $num !~ /^\d\d\d\d$/;
- redo if $num =~ /^(\d)\1\1\1$/;
-
- until ($num==6174) {
- my @big_to_small=sort {$b <=> $a } split //,$num;
- my @small_to_big=reverse @big_to_small;
- my $left=join "",@big_to_small;
- my $right=join "",@small_to_big;
- $num=scalar($left-$right);
- print "$left-$right=","$num\n";
- }
- print "-" x 15,"\n";
- }
复制代码
作者: 523066680 时间: 2011-10-20 11:07
前来支持~
作者: sxw 时间: 2011-10-20 11:14
回复 2# 523066680
热烈欢迎,哈哈
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |