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
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
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
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
Similar Kata:
Stats:
Created | Jun 9, 2023 |
Warriors Trained | 5 |
Total Skips | 0 |
Total Code Submissions | 13 |
Total Times Completed | 5 |
Rust Completions | 3 |
JavaScript Completions | 2 |
Total Stars | 1 |
% of votes with a positive feedback rating | 17% of 3 |
Total "Very Satisfied" Votes | 0 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 3 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |