[ create a new paste ] login | about

Link: http://codepad.org/9431NzDq    [ raw code | output | fork ]

Perl, pasted on Sep 26:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#################################
# 任意位數(可超過 32bits or 64bits)

$num = '123456789123456789123456789';

print &Cal(length($num) - 1);

sub Cal{

   my $pos = shift;

   return 0 if($pos < 0);

   return substr($num,$pos,1) + &Cal($pos - 1);

}


Output:
1
135


Create a new paste based on this one


Comments: