Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Thursday Code Puzzler: ISBN Validator

DZone's Guide to

Thursday Code Puzzler: ISBN Validator

· Java Zone ·
Free Resource

Verify, standardize, and correct the Big 4 + more– name, email, phone and global addresses – try our Data Quality APIs now at Melissa Developer Portal!

Thursday is code puzzler day here at DZone. The idea is simple: solve the coding problem as efficiently as you can, in any language or framework that you find suitable.

Note: Even though there really is nothing stopping you from finding a solution to this on the internet, try to keep honest, and come up with your own answer.  It's all about the participation!

Do you have code puzzlers that you'd like to share with the DZone community?  If so, please submit here. 

Check if a given string is an ISBN number

Write a method that will take a string parameter and check if it conforms to the ISBN-13 specification as detailed in Wikipedia. 

The calculation of an ISBN-13 check digit begins with the first 12 digits of the thirteen-digit ISBN (thus excluding the check digit itself). Each digit, from left to right, is alternately multiplied by 1 or 3, then those products are summed modulo10 to give a value ranging from 0 to 9. Subtracted from 10, that leaves a result from 1 to 10. A zero (0) replaces a ten (10), so, in all cases, a single check digit results.

Formally, the ISBN-13 check digit calculation is:
x_{13} = \big(10 - \big(x_1 + 3x_2 + x_3 + 3x_4 + \cdots + x_{11} + 3x_{12}\big) \,\bmod\, 10\big) \,\bmod\, 10.

Catch up on all our previous puzzlers here.

 

Developers! Quickly and easily gain access to the tools and information you need! Explore, test and combine our data quality APIs at Melissa Developer Portal – home to tools that save time and boost revenue. Our APIs verify, standardize, and correct the Big 4 + more – name, email, phone and global addresses – to ensure accurate delivery, prevent blacklisting and identify risks in real-time.

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}