Problem Description: In the Whimsical Library, each book is enchanted with a magical code to ensure the protection of knowledge. The validation process for these magical codes involves a combination of mathematical spells. The validation process is described as follows: Take the sum of the digits at odd positions from left to right. Take the sum of the squared digits at even positions from left to right. If the absolute difference between the results from step 1 and step 2 is a prime number, the book code is considered valid; otherwise, it is invalid. Example 1: Consider the magical book code 86420137. Step 1. Take the sum of the digits at odd positions from left to right. 8+4+0+3=15 Step 2. Take the sum of the squared digits at even positions from left to right. 6^2+2^2+1^2+7^2=36+4+1+49 = 90 Step 3. If the absolute difference between the results from step 1 and step 2 is a prime number. 115-901 = 75 (not a prime number) Book code 86420137 is invalid. Example 2: Now, let's examine the magical book code 13579246. Step 1. Take the sum of the digits at odd positions from left to right. 1+5+9+2=17 Step 2. Take the sum of the squared digits at even positions from left to right. 3^2+7^2+4^2+6^2=9+49 +16+36 = 110 Step 3. If the absolute difference between the results from step 1 and step 2 is a prime number. 17-1101 = 93 (not a prime number) Book code 13579246 is invalid. Example 3: Finally, let's check the magical book code 24681357. Step 1. Take the sum of the digits at odd positions from left to right. 2+6+1+5=14

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Problem Description:
In the Whimsical Library, each book is enchanted with a magical code to ensure the
protection of knowledge. The validation process for these magical codes involves a
combination of mathematical spells.
The validation process is described as follows:
Take the sum of the digits at odd positions from left to right.
Take the sum of the squared digits at even positions from left to right.
If the absolute difference between the results from step 1 and step 2 is a prime
number, the book code is considered valid; otherwise, it is invalid.
Example 1:
Consider the magical book code 86420137.
Step 1. Take the sum of the digits at odd positions from left to right.
8+4+0+3=15
Step 2. Take the sum of the squared digits at even positions from left to right.
6^2+2^2+1^2+7^2=36+4+1+49 = 90
Step 3. If the absolute difference between the results from step 1 and step 2 is a prime
number.
115-901 75 (not a prime number)
Book code 86420137 is invalid.
Example 2:
Now, let's examine the magical book code 13579246.
Step 1. Take the sum of the digits at odd positions from left to right.
1+5+9+2=17
Step 2. Take the sum of the squared digits at even positions from left to right.
3^2+7^2+4^2 +6^2=9+49 +16+36 110
Step 3. If the absolute difference between the results from step 1 and step 2 is a prime
number.
|17-110| = 93 (not a prime number)
Book code 13579246 is invalid.
Example 3:
Finally, let's check the magical book code 24681357.
Step 1. Take the sum of the digits at odd positions from left to right.
2+6+1+5=14
Step 2. Take the sum of the squared digits at even positions from left to right.
4^2 +8^2+3^2+7^2=16 +64 +9+49 = 138
Step 3. If the absolute difference between the results from step 1 and step 2 is a prime
number.
114-138) 124 (not a prime number)
Book code 24681357 is invalid.
Your task is to write a program that reads magical book codes from user input and
classifies them as "valid" or "invalid." The program should have two arrays for valid
and invalid book codes, initially empty. The array sizes should be set to 20, assuming
the user will enter at most 20 book codes. The program should start asking for an
integer from the user, representing the magical book code. If the book code is valid
according to the validation steps, it should be added to the "valid book codes" array. If
the code is invalid, it should be added to the "invalid book codes" array. If the user
enters the code O, the program should display the valid and invalid book codes arrays
and stop. Error handling for non-integer inputs is not required.
Transcribed Image Text:Problem Description: In the Whimsical Library, each book is enchanted with a magical code to ensure the protection of knowledge. The validation process for these magical codes involves a combination of mathematical spells. The validation process is described as follows: Take the sum of the digits at odd positions from left to right. Take the sum of the squared digits at even positions from left to right. If the absolute difference between the results from step 1 and step 2 is a prime number, the book code is considered valid; otherwise, it is invalid. Example 1: Consider the magical book code 86420137. Step 1. Take the sum of the digits at odd positions from left to right. 8+4+0+3=15 Step 2. Take the sum of the squared digits at even positions from left to right. 6^2+2^2+1^2+7^2=36+4+1+49 = 90 Step 3. If the absolute difference between the results from step 1 and step 2 is a prime number. 115-901 75 (not a prime number) Book code 86420137 is invalid. Example 2: Now, let's examine the magical book code 13579246. Step 1. Take the sum of the digits at odd positions from left to right. 1+5+9+2=17 Step 2. Take the sum of the squared digits at even positions from left to right. 3^2+7^2+4^2 +6^2=9+49 +16+36 110 Step 3. If the absolute difference between the results from step 1 and step 2 is a prime number. |17-110| = 93 (not a prime number) Book code 13579246 is invalid. Example 3: Finally, let's check the magical book code 24681357. Step 1. Take the sum of the digits at odd positions from left to right. 2+6+1+5=14 Step 2. Take the sum of the squared digits at even positions from left to right. 4^2 +8^2+3^2+7^2=16 +64 +9+49 = 138 Step 3. If the absolute difference between the results from step 1 and step 2 is a prime number. 114-138) 124 (not a prime number) Book code 24681357 is invalid. Your task is to write a program that reads magical book codes from user input and classifies them as "valid" or "invalid." The program should have two arrays for valid and invalid book codes, initially empty. The array sizes should be set to 20, assuming the user will enter at most 20 book codes. The program should start asking for an integer from the user, representing the magical book code. If the book code is valid according to the validation steps, it should be added to the "valid book codes" array. If the code is invalid, it should be added to the "invalid book codes" array. If the user enters the code O, the program should display the valid and invalid book codes arrays and stop. Error handling for non-integer inputs is not required.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY