|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Setup: I have a big tree of "if" statements (imagine the PHP code
version of a choose-your-own-adventure story) and I want to be able to tell which end-branch I've reached. Right now, l have all the end- branches numbered with integers, and the integer of the end branch is returned. Problem: If I insert a new end-branch, I have to laboriously re-number all the end branches that come after it. As the tree gets larger and larger, this becomes more and more of a hassle. This has me wondering if PHP has any functionality that would allow me to have the engine auto-insert the numbering for me on a pass of the script that would occur prior to execution. That way I could make the script just have some sort of ++ deal at each end branch, rather than assigning the numbers in the script by hard-coding them in. Alternatively, is there some other way to accomplish the same thing? Thanks! Robert K S |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
..oO(Robert K S)
>Setup: I have a big tree of "if" statements (imagine the PHP code >version of a choose-your-own-adventure story) and I want to be able to >tell which end-branch I've reached. Right now, l have all the end- >branches numbered with integers, and the integer of the end branch is >returned. > >Problem: If I insert a new end-branch, I have to laboriously re-number >all the end branches that come after it. As the tree gets larger and >larger, this becomes more and more of a hassle. > >This has me wondering if PHP has any functionality that would allow me >to have the engine auto-insert the numbering for me on a pass of the >script that would occur prior to execution. That way I could make the >script just have some sort of ++ deal at each end branch, rather than >assigning the numbers in the script by hard-coding them in. > >Alternatively, is there some other way to accomplish the same thing? It would to post some more details about what you're trying to achieve. Micha |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
In article <5d2b0983-ec15-4724-8624-3cc2c1bc0d92@i7g2000prf.googlegroups.com>,
Robert K S <robertks@gmail.com> wrote: >Problem: If I insert a new end-branch, I have to laboriously re-number >all the end branches that come after it. Why? If all you need is a unique ID for each branch, what does it matter what order they're in? -A |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Thanks for the replies, Michael and axlq--
Michael: If you want to see the end result, check out http://www.j-archive.com/wageringcalculator.php Type three numbers in the fields and hit submit. The number in parentheses at returned with each result is the branch end ID. axlq: Fair point, it doesn't matter what order they're in. What's the best way to generate a unique ID for each end of the branch, such that no ID can be repeated and the IDs are always consistent from execution to execution? All the best, Robert K S |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Feb 14, 4:33am, Robert K S <rober...@gmail.com> wrote:
> Thanks for the replies, Michael and axlq-- > > Michael: If you want to see the end result, check outhttp://www.j-archive.com/wageringcalculator.php > > Type three numbers in the fields and hit submit. > > The number in parentheses at returned with each result is the branch > end ID. > > axlq: Fair point, it doesn't matter what order they're in. What's the > best way to generate a unique ID for each end of the branch, such that > no ID can be repeated and the IDs are always consistent from execution > to execution? > > All the best, > Robert K S Not sure if this really what you want, but what about using array_unshift() to add an entry to the start of an array. That would push all of the other entries down by one? Rob. |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On 13 Feb, 22:58, Robert K S <rober...@gmail.com> wrote:
> Setup: I have a big tree of "if" statements (imagine the PHP code > version of a choose-your-own-adventure story) and I want to be able to > tell which end-branch I've reached. Right now, l have all the end- > branches numbered with integers, and the integer of the end branch is > returned. > > Problem: If I insert a new end-branch, I have to laboriously re-number > all the end branches that come after it. As the tree gets larger and > larger, this becomes more and more of a hassle. > > This has me wondering if PHP has any functionality that would allow me > to have the engine auto-insert the numbering for me on a pass of the > script that would occur prior to execution. That way I could make the > script just have some sort of ++ deal at each end branch, rather than > assigning the numbers in the script by hard-coding them in. > > Alternatively, is there some other way to accomplish the same thing? > > Thanks! > > Robert K S You're trying to polish a turd here. If you really have so many 'if' conditions that you need to keep track of them with arbitary data structures then you've gone the wrong way about solving the problem. The right way to solve the problem would be to push the branching logic into a data structure. Go read up on expert systems and heuristics. C. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On Feb 14, 7:40am, "C. (http://symcbean.blogspot.com/)"
<colin.mckin...@gmail.com> wrote: > On 13 Feb, 22:58, Robert K S <rober...@gmail.com> wrote: > > Setup: I have a big tree of "if" statements (imagine the PHP code > > version of a choose-your-own-adventure story) and I want to be able to > > tell which end-branch I've reached. Right now, l have all the end- > > branches numbered with integers, and the integer of the end branch is > > returned. > > > Problem: If I insert a new end-branch, I have to laboriously re-number > > all the end branches that come after it. As the tree gets larger and > > larger, this becomes more and more of a hassle. > > > This has me wondering if PHP has any functionality that would allow me > > to have the engine auto-insert the numbering for me on a pass of the > > script that would occur prior to execution. That way I could make the > > script just have some sort of ++ deal at each end branch, rather than > > assigning the numbers in the script by hard-coding them in. > > > Alternatively, is there some other way to accomplish the same thing? > > > Thanks! > > > Robert K S Thanks for the advice, Colin. Have you checked out the application? Writing an inference engine in PHP would be overkill. If there was an open source solution that I could tinker with, I might look into it. In the meantime, it's much more cost-effective on my part to keep polishing the turd. (I'm also not convinced the collection of questions in the knowledgebase would be any less ungainly than the if- tree of value comparison conditionals that I already have in place.) Rob, thanks also for your reply. I hope I'm understanding you're suggestion correctly, but if I'm not, please set me straight. array_unshift is a runtime function and so it would only operate on branches of the if-tree that are reached during execution. I was hoping that there was some capability in PHP that worked the script over before runtime. Robert |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
Robert K S wrote:
> On Feb 14, 7:40 am, "C. (http://symcbean.blogspot.com/)" > <colin.mckin...@gmail.com> wrote: >> On 13 Feb, 22:58, Robert K S <rober...@gmail.com> wrote: >>> Setup: I have a big tree of "if" statements (imagine the PHP code >>> version of a choose-your-own-adventure story) and I want to be able to >>> tell which end-branch I've reached. Right now, l have all the end- >>> branches numbered with integers, and the integer of the end branch is >>> returned. >>> Problem: If I insert a new end-branch, I have to laboriously re-number >>> all the end branches that come after it. As the tree gets larger and >>> larger, this becomes more and more of a hassle. >>> This has me wondering if PHP has any functionality that would allow me >>> to have the engine auto-insert the numbering for me on a pass of the >>> script that would occur prior to execution. That way I could make the >>> script just have some sort of ++ deal at each end branch, rather than >>> assigning the numbers in the script by hard-coding them in. >>> Alternatively, is there some other way to accomplish the same thing? >>> Thanks! >>> Robert K S > > Thanks for the advice, Colin. Have you checked out the application? > Writing an inference engine in PHP would be overkill. If there was an > open source solution that I could tinker with, I might look into it. > In the meantime, it's much more cost-effective on my part to keep > polishing the turd. (I'm also not convinced the collection of > questions in the knowledgebase would be any less ungainly than the if- > tree of value comparison conditionals that I already have in place.) > > Rob, thanks also for your reply. I hope I'm understanding you're > suggestion correctly, but if I'm not, please set me straight. > array_unshift is a runtime function and so it would only operate on > branches of the if-tree that are reached during execution. I was > hoping that there was some capability in PHP that worked the script > over before runtime. > > Robert > Robert, No, PHP Has no preprocessor. Of course, you could always use the __LINE__ directive to give the current line number, if all you need to do is relate it back to a specific statement. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
![]() |
| Outils de la discussion | |
|
|