Draft

ISBN-10 & ISBN-13 Validator

Description:

You are a new engineer for a bookshop that is owned by a rather odd person. They like to write down the ISBNs for their new orders down on paper, but sometimes they dont write valid ISBNs and sometimes they insert nonesense in the middle of the ISBN.

Your validator should check for both ISBN-10 and ISBN-13 numbers after it removes all the extra junk characters. The checksum equations for both ISBN-10 and ISBN-13 are provided. As an extra challenge try to create your solution based on the notation equations instead of the simplified.


Constraints

You will be provided one of the shop keepers notes as a string. The string will hold anything from a properly formatted ISBN all the way to a grocery list! It is also possible for a ISBN to get mixed into their notes, they get distracted easily when writing.


ISBN-10

To validate an ISBN-10 number we need to calculate the value and then compare it to the checksum. The checksum is stored in the last number of the ISBN-10. The check value is calculated using the below summation formula.


Nerd Equation

Given an ISBN-10 of 0541530011

x=[0,5,4,1,5,3,0,0,1,1]x9=i=08(ixi)+xi11x = [0,5,4,1,5,3,0,0,1,1]\\\\ x_{9} = \displaystyle\sum_{i=0}^8 (i * x_i) + x_i \bmod {11}

Simplified Equation

The checksum is equal to the sum of numbers 1 to 9 multiplied by their relative position(index + 1) modulus 10.

Given an ISBN-10 of 0541530011

check=((01)+(52)+(43)+...+(08)+(19))11check==1check = ((0 * 1) + (5*2) + (4*3) + ... + (0*8) + (1 * 9)) \bmod 11\\ check == 1

ISBN-13

To validate an ISBN-13 number, similar to ISBN-10, we must first find out checksum and then compare it to our calculated check value. The checksum is stored in the last character of the ISBN-13 number and the check value is calculated using the first 12 numbers. Use the below equation to calculate the check value.

Nerd Equation

Given an ISBN-13 of 9781234567897

x=[9,7,8,1,2,3,4,5,6,7,8,9,7]x12=10((i=011{xiif i2=03xiotherwise)10)x = [9,7,8,1,2,3,4,5,6,7,8,9,7]\\\\ x_{12} = 10 - (\left(\displaystyle\sum_{i=0}^{11} \begin{cases} x_i &\text{if } i \bmod 2 = 0 \\ 3x_i &\text otherwise \end{cases}\right) \bmod {10})

Simplified Equation

The checksum is equal to 10 minus the sum of numbers 1 to 12 multiplied by either 1 or 3 (alternating) modulus 10.

Given an ISBN-13 of 9781234567897

check=10((9)+(37)+(8)+(31)+...+(8)+(39)10)check==7check = 10 - ((9) + (3*7) + (8) + (3*1) + ... + (8) + (3*9) \bmod 10)\\ check == 7
Strings
Arrays

Stats:

CreatedJun 9, 2023
Warriors Trained5
Total Skips0
Total Code Submissions13
Total Times Completed5
Rust Completions3
JavaScript Completions2
Total Stars1
% of votes with a positive feedback rating17% of 3
Total "Very Satisfied" Votes0
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes2
Total Rank Assessments3
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • 0x4445565A Avatar
Ad