+ 3

Why does this program not print all the numbers?

https://code.sololearn.com/ci9Ds6ofWXDz/?ref=app

26th Feb 2023, 12:32 AM
Maryam Prhn🇮🇷
Maryam Prhn🇮🇷 - avatar
18 ответов
+ 10
Maryam Prhn🇮🇷 assuming your code works fine (I can't verify that now), it takes more than 0.5 seconds to finish execution which is a time limit on SL. so either: try to see if it really does what it's intended to do by running on your own PC, and/or Try to implement it with a faster algorithm. PS: Upon more investigation, your code will hit the time limit and it also hits the max output file size limit, which is 100KB. I was able to run your code from 10000000 to ~10649200 in which case file size is ~99430B (close to 100k limit). In this range your code outputs 11048 lines, which confirms: 8chars+1 newline, total of 9 chars per line: 11048*9= 99432 Bytes *if your code outputs more than 100KB, it will truncate to 2KB and an exec timeout error displays (although it might be wrong and the actual problem is large output).
26th Feb 2023, 1:18 AM
Tina
Tina - avatar
+ 3
nope, int is 4 bytes (on the machine that code runs) so the range is about +/-2 billions. check exact value via INT_MAX and INT_MIN, include climits.
26th Feb 2023, 8:19 AM
Tina
Tina - avatar
+ 3
I was able to get your code to run on Sololearn by making two minor changes: 1. starting the loop with the first valid number, which is m=123456789. 2. combining the not0 and notRepeat functions into one. I did this by removing not0 and editing notRepeat's line 7: From if(arr[r]==1) To this, so that it includes the check for 0 if(r==0 || arr[r]==1) Though it produced output, it still gets cut off due to Sololearn's arbitrary limitations. If I understand correctly, this task could be stated another way: Find all permutations of 9 distinct digits, 1 through 9. The output should produce 9! (factorial) = 362,880 answers. I found this C code that most elegantly generates permutations. It is a much more efficient technique. https://code.sololearn.com/cXwnK6Z7IEEM/?ref=app Don't copy it. Use it for understanding and inspiration.
27th Feb 2023, 10:10 AM
Brian
Brian - avatar
+ 2
Maryam Prhn🇮🇷 P.S. If you or anyone else reading this uses an Android device, the Cxxdroid app will compile offline on your device: https://play.google.com/store/apps/details?id=ru.iiec.cxxdroid It will correctly compile your code on even my old Samsung S6 phone although it takes a short while to complete. It also allows adding external libraries like Boost, OpenSSL & GMP etc.
27th Feb 2023, 7:33 AM
Scott D
Scott D - avatar
+ 1
Thank you very much for your guidance🤩🤩
26th Feb 2023, 8:51 AM
Maryam Prhn🇮🇷
Maryam Prhn🇮🇷 - avatar
+ 1
Maryam Prhn🇮🇷 Assuming 9 digits, no digit can repeat and no 0: the smallest possible number would be: m = 123456789 the largest: n = 987654321 So change the values of those and it will run in Sololearn but will time out. With your current values it times out before any printing is executed so message is "No output". Change the values and you will print some output & then get the console message "Execution Timed Out!". Run the code using an online compiler such as: https://www.onlinegdb.com/online_c++_compiler and it will work.
27th Feb 2023, 2:54 AM
Scott D
Scott D - avatar
+ 1
Scott D That's right, thank you🌸
27th Feb 2023, 10:16 AM
Maryam Prhn🇮🇷
Maryam Prhn🇮🇷 - avatar
+ 1
Brian Thank you for your help, it was useful🌸
27th Feb 2023, 10:18 AM
Maryam Prhn🇮🇷
Maryam Prhn🇮🇷 - avatar
+ 1
Just change for(i=m; i<=n; i++){ to for(i=m; i<=n; i--){
27th Feb 2023, 7:37 PM
Kisomba John Bosco
Kisomba John Bosco - avatar
+ 1
Let me first check again
27th Feb 2023, 7:51 PM
Kisomba John Bosco
Kisomba John Bosco - avatar
+ 1
JOHN BOSCO Using i-- it prints only 8 digits, in reverse order, and as explained due to the limitations using Sololearn the execution times out. When the starting value is changed to 123456789 (which is the lowest starting value where no digits repeat) then it will work with 9 digits, forward, but again due to limitations will time out. It appears the only way to get the code to work properly is with a different compiler. https://code.sololearn.com/cv79GPBNjBtT/?ref=app
27th Feb 2023, 7:59 PM
Scott D
Scott D - avatar
+ 1
"the smallest possible number would be: m = 123456789 the largest: n = 987654321 " ...this made me think. Can't you split the range up by using %1000 and /10000 send then to the function separately, if both are "true", then return "true" . There will be less function calls and less iterations in the function.
27th Feb 2023, 9:12 PM
rodwynnejones
rodwynnejones - avatar
+ 1
rodwynnejones It is a good solution, but my problem is solved. Thank you anyway🙏🌸
27th Feb 2023, 9:26 PM
Maryam Prhn🇮🇷
Maryam Prhn🇮🇷 - avatar
+ 1
On second thoughts......It won't work, Good to know you've solved it though.
27th Feb 2023, 10:19 PM
rodwynnejones
rodwynnejones - avatar
0
Ahh thanks🤩🙏. I have to use long ina for these numbers because it's too big?
26th Feb 2023, 6:08 AM
Maryam Prhn🇮🇷
Maryam Prhn🇮🇷 - avatar
0
ali star hi😁
27th Feb 2023, 10:19 AM
Maryam Prhn🇮🇷
Maryam Prhn🇮🇷 - avatar
0
JOHN BOSCO thanks 🌸
27th Feb 2023, 7:41 PM
Maryam Prhn🇮🇷
Maryam Prhn🇮🇷 - avatar
0
JOHN BOSCO But then it prints eight-digit numbers
27th Feb 2023, 7:43 PM
Maryam Prhn🇮🇷
Maryam Prhn🇮🇷 - avatar