-
Notifications
You must be signed in to change notification settings - Fork 0
/
033.pl
executable file
·43 lines (38 loc) · 955 Bytes
/
033.pl
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
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use List::MoreUtils qw(any);
sub gcd {
my ( $a, $b ) = @_;
( $a, $b ) = ( $b, $a ) if $a > $b;
while ($a) {
( $a, $b ) = ( $b % $a, $a );
}
return $b;
}
my ( $numerator, $denominator ) = ( 1, 1 );
foreach my $n ( 10 .. 99 ) {
my @n = split( //, $n );
foreach my $d ( $n + 1 .. 99 ) {
my @d = split( //, $d );
foreach my $z (
grep {
my $x = $_;
any { $_ == $x } @d
} @n
)
{
next if $z == 0;
my ($x) = grep { $_ != $z } @n;
my ($y) = grep { $_ != $z } @d;
next unless defined $x && defined $y;
next if $y == 0;
if ( $n / $d == $x / $y ) {
$numerator *= $n;
$denominator *= $d;
}
}
}
}
say $denominator / gcd( $numerator, $denominator );