- #!/usr/bin/perl
-
- use strict;
- use warnings;
-
-
-
- sub gcd {
- my ($down, $up) = sort { $a <=> $b } (shift, shift);
- my $r;
- do {
- return $up if not $down;
- $r = $up % $down;
- $up = $down;
- $down = $r;
- } while ($r);
- return $up;
- }
-
-
-
- sub reduce {
- my ($n, $d) = (shift, shift);
- my $gcd = gcd($n, $d);
- return ($n, $d) if not $gcd;
- return ($n/$gcd, $d/$gcd);
- }
-
-
-
- sub remove_common_digit {
- my ($down, $up) = sort { $a <=> $b } (shift, shift);
- my @down = split //, $down;
- my @up = split //, $up;
-
- for (0..int @down -1) {
- my $n = index $up, $down[$_];
- return ($down[($_+1)%2], $up[($n+1)%int @up]) if $n != -1;
- }
-
- return (0,0);
- }
-
-
-
- my ($big_n, $big_d) = (1, 1);
-
-
-
- for my $n (10..99) {
- for my $d ($n+1..99) {
- next if $n%10 == 0 && $d % 10 == 0;
- next if gcd($n, $d) == 1;
-
- my $left = join '/', reduce $n, $d;
- my $right = join '/', reduce remove_common_digit($n, $d);
-
- print "$n/$d -> $left -> $right\n" if $left eq $right;
- ($big_n, $big_d) = ($big_n*$n, $big_d*$d) if $left eq $right;
- }
- }
-
-
-
- print join(' ', reduce ($big_n, $big_d));