#!/usr/bin/perl

# 978067172014 (as printed, ends in 8...)
# (+ 9 8 6 1 2 1 )27  (* 27 3)81 (+ 81 25)106 ->4
#  (+ 7 0 7 7 0 4)25
sub upcverf {			# 1 arg, return it
    my ($upc) = @_;
    print "handling <$_>\n";
    my @upc, $ck, $mul;
    @upc = split(//,$upc);
    $ck = 0; $mul = 3;
    for (@upc) {
	$ck += $mul * $_;
	print "$_/$ck/$mul ";
	$mul = 4-$mul;
    }
    print "\n";
    $ck = 10 - ($ck % 10);
    0 if ($ck == 10);
    $ck;
}

sub isbnverf {
    my ($isbn) = @_;
    # (sum(k=1:9) digit(k) * k) mod 11 == digit(10)
    # where X as a digit has value 10, and hyphens are ignored, and
    my @isbn, $ck, $cnt;
    @isbn = split(//,$isbn);
    $cnt = 1;
    for (@isbn) {
	$ck += $cnt * $_;
	$cnt ++;
	# print "$_/$ck/$cnt ";
    }
    $ck = $ck % 11;
    "X" if $ck == 10;
    $ck;
}


while(<>) {
    chomp;
    print &isbnverf($_)."\n";
    print &upcverf($_)."\n";
}
