# 程序员的算法趣题Perl版

2017-09-30 21:50:37来源:CSDN作者:tyn243222791人点击

``#! perl#20170925use strict;my \$num = 11;my \$num2;my \$num8;my \$count = 1000000;while(\$count) {    \$count--;    \$num2 = sprintf "%b", \$num;    \$num8 = sprintf "%o", \$num;    my \$res = &isHuiWen(\$num, \$num2, \$num8);    if(\$res) {        last;    }    \$num += 2;}sub isHuiWen {    my \$sign = 1;    foreach (@_) {        \$sign *= &isRight(\$_);    }    if(\$sign) {        print "@_/n";        return 1;    }    0;}# use reverse function to find the huiwen numbersub isRight {    my \$arg = @_[0];    if(\$arg eq reverse \$arg) {        return 1;    }    0;}``

``#! perl#20170930use strict;my \$card_total = 100;my @num = (0) x  \$card_total;my \$n = 2;while(\$n <= \$card_total) {    my \$nn = \$n - 1;     for(my \$i = \$nn; \$i < \$card_total; \$i += \$n) {        @num[\$i] = !@num[\$i];    }    \$n++;}for(my \$i = 0; \$i < \$card_total; \$i++) {    if(!@num[\$i]) {        my \$j = \$i + 1;        print \$j, "/n";    }}``

1
4
9
16
25
36
49
64
81
100