aboutsummaryrefslogtreecommitdiff
path: root/challenge-157/kueppo-wesley/perl/ch-2.pl
blob: f64f449431d911e4adcc04b0bbec53f705963788 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env perl

use strict;
use warnings;

use Math::BigInt;

print "Input: ";
my $n = <STDIN>;

if ($n > 2) {
    my($x, $count, $did) = (Math::BigInt->new($n), 0, 0);
    foreach (2..$n - 2) {
    	my $n_in_base__ = $x->to_base($_);
    	if ($n_in_base__ =~ /^(.)\g1{1, }$/) {
    		print "Output: 0\nSince $n" if (! $did);
    		print "\tin base $_ is $n_in_base__\n";
    		$did++;
    	}
    }
    print "Output : 1\n" if ($did == 0);
}