批版的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";
- }
复制代码
|