+ 10

# [ASSIGNMENT] Shortable Prime Numbers

PART 1: Prime number is called Shortable if it can be consiquently reduced by 1 digit (until sigle digit Prime rests) from any chosen in advance side and resulting number is also Prime. Shortable Prime can be called Left/Right/Full Shortable Prime if it can be reduced from left/right/both sides. For example: 13 -> 3 => 13 is Left Shortable Prime 31 -> 3 => 31 is Right Shortable Prime 3797 -> 797 -> 97 -> 7 and 3797 -> 379 -> 37 -> 3 => 3797 is Full Shortable Prime See PART 2 in comments below...

47 Answers

+ 4

More than one week past from the assignment publication and it seems that everyone who wanted to participate have already done it. So, as usual, I sum it up with the list of all accepted solutions:
TASK 1 + EXTRA TASK:
@Ali Zhussupov (C++): https://code.sololearn.com/cPjJNsAw55ya/#cpp
@Kinshuk Vasisht (C++): https://code.sololearn.com/cL4laCc1KfY8/?ref=app
@Swapnil More (C): https://code.sololearn.com/c47p3p5fdZe3/?ref=app
@~ swim ~ (C++): https://code.sololearn.com/c6HIr5oxSdXQ/?ref=app
@LukArToDo (kt): https://code.sololearn.com/cQIEeDa7o68C/?ref=app
@Nevfy (Python): https://code.sololearn.com/cTKjAquzJU3u/?ref=app
TASK 1:
@cyk (Python): https://code.sololearn.com/cq6vN3AvSCEX/?ref=app
TASK 2 + EXTRA TASK:
@Kinshuk Vasisht (C++): https://code.sololearn.com/cL4laCc1KfY8/?ref=app
@LukArToDo (kt): https://code.sololearn.com/cuKuQ24413Ll/?ref=app
@Nevfy (Python): https://code.sololearn.com/cTKjAquzJU3u/?ref=app
TASK 2:
@Ali Zhussupov (C++): https://code.sololearn.com/cURh4PHQyES9/#cpp
@Louis (Python): https://code.sololearn.com/cdus3iaZZxfl/?ref=app
@Swapnil More (C): https://code.sololearn.com/cSQykzdhGG3j/?ref=app
@~ swim (C++): https://code.sololearn.com/cuRy692IgY3m/?ref=app
@LukArToDo (kt): https://code.sololearn.com/cZ5wvA18SEFG/?ref=app
BY THE WAY, interesting fact, there are only ten Full Shortable Primes!

+ 15

Nevfy
Ok. Thanks.

+ 14

Nevfy
Please clarify whether numbers 5003, 5023 or 5107 are Left Shortable Primes. Thanks.

+ 8

Nevfy
Thanks. It's fixed 😉

+ 4

+ 4

@cyk Ok, I see what you mean. I will try to explain more which numbers are considered to be Shortable Primes. Let's look on sequence of operations to proof thar 3797 is Full Shortable Prime:
1. Is 3797 Prime? Yes - go to step 2.
2. Cut one digit from right -> 379.
3. Is 379 Prime? Yes - go to next step.
4. Cut one digit from right -> 37.
5. Is 37 Prime? Yes - go to next step.
6. Cut one digit from right -> 3.
7. Is 3 Prime? Yes - go to next step.
8. Resulting number is single digit Prime, so initial number is Right Shortable Prime.
Analogously you can check that 3797 is Left Shortable Prime, so it is Full Shortable Prime in the end.
Now let's have a look for 12345:
1. 1. Is 12345 Prime? No. Stop check.
Return 12345 is not Shortable Prime.
Is it more clear now?

+ 4

My Try, with different tasks in the same program : https://code.sololearn.com/cL4laCc1KfY8/?ref=app

+ 3

PART 2:
TASK 1:
Write a code which checks if input number is Shortable Prime. Print out not only True or False but specify what kind of Shortable Prime it is: Left, Right or Full.
Input: 3797
Output: Full Shortable Prime
Input: 13
Output: Left Shortable Prime
Input: 19
Output: Not a Shortable Prime
TASK 2:
Write a code which finds all Shortable Prime in a given range [A,B] and print them out grouped by Left, Right and Full Shortable Primes.
Input: 1 10000
Output:
Left Shortable Prime: ...find it... :-)
Right Shortable Prime: ...find it...
Full Shortable Prime: ...find it...
EXTRA TASK:
For tasks 1 and 2 print out not only numbers itself, but also its reducing process like it is shown in the example or any other way you like. :-)
CLARIFICATION NOTES:
- Single digit Primes are not Shortable Primes.
- If number is Full Shortable Prime there is no need to print it also in lists of Left and Right Shortable Primes.
- Numbers that contain '0' as a digit can be Left Shortable Primes according to a general rule. Example: 5003. It is Prime and 3 is Prime as well. However, it is not Right Shortable Prime, because 500 and 50 are not Prime numbers.

+ 3

TASK 1 + EXTRA TASK: https://code.sololearn.com/cPjJNsAw55ya/#cpp
TASK 2: https://code.sololearn.com/cURh4PHQyES9/#cpp
Nevfy, thanks for the challenge!

+ 3

Nevfy Fixed!

+ 3

@~ swim ~ I'm happy to hear that you are fine now! There are plenty of new challenges that are waiting for you. :-)
I've spent last 3 days in mountains and I was surprised how many new challenges have appeared for such short time while I was away.

+ 2

Quoi de neuf Nevfy? All right, let me see if I got this right. It is shortable if when we remove a digit what is left is a prime as well?

+ 2

It runs fine now. And sure, what should it return for 12345? I would guess it is right shortable because if you you divide 1234 and 5, 5 is on the right and is prime...

+ 2

Yep! Thanks. Will let you know when the code is fixed. ☺

+ 2

Nevfy, It is fixed now but way too long so I will probably be working on optimizing it. Check it out and let me know if there is any bug.

+ 2

Nevfy The error has been removed. Sorry for the inconvenience caused.