|
| 1 | +# [Recursive Digit Sum](https://www.hackerrank.com/challenges/recursive-digit-sum) |
| 2 | + |
| 3 | +- Difficulty: `#medium` |
| 4 | +- Category: `#ProblemSolvingBasic` |
| 5 | + |
| 6 | +## Language Difficulties |
| 7 | + |
| 8 | +The first attempt solved most of the cases. |
| 9 | +The failed test cases reported a "Runtime error". |
| 10 | +Initially, it seemed pointless, since there are |
| 11 | +no edge cases in the calculations that could cause |
| 12 | +typical runtime errors like division by zero or |
| 13 | +performing operations on a null value. |
| 14 | + |
| 15 | +Unlocking a failed test case, and locally replicating the given input, |
| 16 | +found the real problem: |
| 17 | + |
| 18 | +```text |
| 19 | +ValueError: Exceeds the limit (4300) for integer string conversion |
| 20 | +``` |
| 21 | + |
| 22 | +The input number is too high for some reason in Python. |
| 23 | + |
| 24 | +A [little reseach](https://stackoverflow.com/a/75162528/6366150) give some answers: |
| 25 | + |
| 26 | +### Problem fixes |
| 27 | + |
| 28 | +So, the problem arises from a limitation imposed in Python, which fixes |
| 29 | +the size of a number that will be transformed from a string to an integer. |
| 30 | + |
| 31 | +The limit can be increased via a parameter or programmatically. |
| 32 | +However, if the value is set as a hardcoded integer (in test cases), |
| 33 | +it will still fail at runtime. |
| 34 | + |
| 35 | +> [!IMPORTANT] |
| 36 | +> |
| 37 | +> The solution is then to enter the number (from the large test case) |
| 38 | +> as a string and then do the transformation at runtime, |
| 39 | +> including the parameter that arbitrarily extends the length of the number. |
| 40 | +
|
| 41 | +## Sources |
| 42 | + |
| 43 | +- [Stackoverflow: ValueError: Exceeds the limit (4300) for integer string conversion](https://stackoverflow.com/a/75162528/6366150) |
| 44 | +- [CVE: CVE-2020-10735](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-10735) |
| 45 | +- [Multiline String in Python - GeeksforGeeks](https://www.geeksforgeeks.org/multiline-string-in-python/) |
| 46 | +- [string splitterworld's simplest string tool](https://onlinestringtools.com/split-string) |
0 commit comments