#! /usr/bin/perl
#
# $Id: num-knobeln.pl $
#
# description to follow
#
# Copyright (C) 2010 Andreas Ferber <af@chaos-agency.de>
# This code is distributed under the GNU General Public License version 2
#
# TODO:
#
# {{{ ChangeLog:
# }}}

use strict;
no warnings;

use Math::BigInt lib => 'GMP';
use IO::Handle;

my $n_max = 11;

my $n = 0;
my $k = 1;
my $mod = Math::BigInt->new('1E20');

K: while (1) {
    my $a = Math::BigInt->new(2);
    $a->bmodpow($k, $mod);

    my $str = reverse($a->bstr());
    DIGIT: for (my $n_try = 1; $n_try <= 20; $n_try++) {
        my $digit = substr($str, $n_try-1, 1);
        last DIGIT unless $digit eq '1' || $digit eq '2';

        if ($n_try > $n) {
            $n = $n_try;
            print "n = ${n} -> k = $k\n";
            STDOUT->flush();
            last K if $n == $n_max;
        }
    }

    $k += 4;

    #if (($k % 10000) == 1) {
    #    print STDERR "k = $k\n";
    #}
}
