-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathsum_factorial.pl
More file actions
executable file
·47 lines (34 loc) · 883 Bytes
/
sum_factorial.pl
File metadata and controls
executable file
·47 lines (34 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl
# Author: Daniel "Trizen" Șuteu
# License: GPLv3
# Date: 13th October 2013
# https://trizenx.blogspot.com
# This script generates sums of consecutive numbers for factorial numbers.
use 5.010;
use strict;
use warnings;
sub sum_x {
my ($x, $y, $z) = @_;
($x + $y) * (($y - $x) / $z + 1) / 2;
}
sub factorial {
my ($n) = @_;
my $fact = 1;
$fact *= $_ for 2 .. $n;
$fact;
}
foreach my $i (1 .. 9) {
my $fact = factorial($i);
O: for (my $o = 1 ; $o <= int sqrt($fact) ; $o++) {
N: for (my $n = 1 ; $n <= $fact ; $n++) {
M: for (my $m = $n ; $m <= $fact ; $m++) {
my $sum = sum_x($n, $m, $o);
if ($sum == $fact) {
printf "%2d. %10d:%5d %10d .. %d\n", $i, $fact, $o, $n, $m;
}
}
}
last if $o >= 1;
}
say '';
}