|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Question might be wrong: what about cases in which input is like ...
Suppose we call our code by using discs.php?input=somefile.txt
Considering the requirement "There may be duplicate diameters in the file", let the contents of somefile.txt be: (Note I am showing a space ' ' between two numbers instead of new line 'n' for easier view in forums) 5 6 7 8 9 5 4 5 4 3 2 1 10 When the algo. as described is applied to this: 1) 9 8 7 6 5 5 4 5 4 3 2 1 10 2) 4 5 5 6 7 8 9 5 4 3 2 1 10 3) 9 8 7 6 5 5 4 5 4 3 2 1 10 4) 4 5 5 6 7 8 9 5 4 3 2 1 10 5) 9 8 7 6 5 5 4 5 4 3 2 1 10 6) 4 5 5 6 7 8 9 5 4 3 2 1 10 this runs into an infinite loop. You may argue that this input I gave is wrong, but, for your information I arrived at this input from reversing the algorithm for following 13 number set: 1 2 3 4 4 5 5 5 6 7 8 9 10 I first reversed the first 12 numbers: 9 8 7 6 5 5 5 4 4 3 2 1 10 now first 6: 5 5 6 7 8 9 5 4 4 3 2 1 10 now first 8: 4 5 9 8 7 6 5 5 4 3 2 1 10 now the first 7: 5 6 7 8 9 5 4 5 4 3 2 1 10 This input doesn't get reversed the way it should if we use the algorithm described. So what should be done for inputs like this: 1) ignore. 2) just make it possible... Best Regards, Jayant Kumar Gandhi Co-Founder, iDYA Research Founder, NibbleGuru Moderator: PHP-Builder.com,.... |
|
#2
|
|||
|
|||
|
RE: Question might be wrong: what about cases in which input is like ...
any one?
|
|
#3
|
|||
|
|||
|
RE: Question might be wrong: what about cases in which input is like ...
What algo as described?
Using the worst possible algorithm (flip largest out of place to top then in to place) you don't hit an infinite loop |
|
#4
|
|||
|
|||
|
RE: Question might be wrong: what about cases in which input is like ...
The point of the contest is to develop an algorithm to solve the problem. There is not a standard algorithm that you must use...
|
![]() |
| Viewing: Codewalkers Forums > PHP Contests > Older Contests > Question might be wrong: what about cases in which input is like ... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|