7 kyu

ISBN Corruption

Description:

ISBN

An ISBN (International Standard Book Number) is a ten digit code which uniquely identifies a book. The first nine digits represent the book and the last digit is used to make sure the ISBN is correct. To verify an ISBN you calculate 10 times the first digit, plus 9 times the second digit, plus 8 times the third... all the way until you add 1 times the last digit. If the final number leaves no remainder when divided by 11 the code is a valid ISBN.

For example 0201103311 is a valid ISBN, since 10*0 + 9*2 + 8*0 + 7*1 + 6*1 + 5*0 + 4*3 + 3*3 + 2*1 + 1*1 = 55.

Each of the first nine digits can take a value between 0 and 9. Sometimes it is necessary to make the last digit equal to ten; this is done by writing the last digit as X. For example, 156881111X.

Write a program that reads in an ISBN code (will always be valid) with a single missing digit, marked with a ?, and outputs the correct value for the missing digit.

Example:

15688?111X => "1"
020161586? => "X"

Input/Output

  • [input] string representing the 10-digit ISBN code 15688?111X
  • [output] string representing the missing digit '1'

Source: 2003 British Informatics Olympiad

Strings
Algorithms
Arrays

More By Author:

Check out these other kata created by alexlostorto

Stats:

CreatedDec 19, 2023
PublishedDec 20, 2023
Warriors Trained345
Total Skips1
Total Code Submissions769
Total Times Completed170
Python Completions170
Total Stars6
% of votes with a positive feedback rating89% of 44
Total "Very Satisfied" Votes36
Total "Somewhat Satisfied" Votes6
Total "Not Satisfied" Votes2
Total Rank Assessments12
Average Assessed Rank
7 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • alexlostorto Avatar
  • E-One Avatar
Ad