| Index | Recent Threads | Unanswered Threads | Who's Active | Guidelines | Search |
| World Community Grid Forums
|
| No member browsing this thread |
|
Thread Status: Active Total posts in this thread: 11
|
|
| Author |
|
|
Former Member
Cruncher Joined: May 22, 2018 Post Count: 0 Status: Offline |
These are brought to you by the fun-loving people over at Tribalwar.com
----------------------------------------![]() Phyzx ![]() Click Here to Join >> Tribalwar ![]() [Edit 2 times, last edit by Former Member at Apr 13, 2005 11:59:35 AM] |
||
|
|
Former Member
Cruncher Joined: May 22, 2018 Post Count: 0 Status: Offline |
|
||
|
|
Former Member
Cruncher Joined: May 22, 2018 Post Count: 0 Status: Offline |
Phyzx --
These signs are funny, but don't really belong in the Teams forum. I quote from the Forum Index, "Teams - This forum is for teams to communicate among members and recruit new members." Postings like this would properly belong in the Chat Room forum. Thanks, |
||
|
|
Former Member
Cruncher Joined: May 22, 2018 Post Count: 0 Status: Offline |
it is code
|
||
|
|
Former Member
Cruncher Joined: May 22, 2018 Post Count: 0 Status: Offline |
it is code And here I was under the impression that this was code: for (j=0; j<=3; j++) { |
||
|
|
Former Member
Cruncher Joined: May 22, 2018 Post Count: 0 Status: Offline |
it is code And here I was under the impression that this was code: for (j=0; j<=3; j++) {And I thought code was -.-. --- -.. . |
||
|
|
Former Member
Cruncher Joined: May 22, 2018 Post Count: 0 Status: Offline |
it is code And here I was under the impression that this was code: for (j=0; j<=3; j++) {What in the world does that loop accomplish? ;) Heh, obviously you just made a valid snippet of code that would compile but not necessarily do anything, but I am going to deconstruct it in Common Lisp to warm up my brain, in line with Tribalwar's "do nothing, well" policy. Generally when I see an or check for a value of zero I assume there isn't a good reason; however in the interests of recreating it I left it in. I'm also using the loop macro since it's fairly intuitive to the procedural eye.
Now, for the critical analysis: Basically, there's no point in assigning rand more than once (and to exaggerate that, I am setting it at every iteration), because the values assigned to it are not accumulating in any way. Thus, assuming that the random number function is random enough for our purposes, there is no logical difference between assigning it once and assigning it every time. Instead, we just want a true/false check -- do any of the first 4 elements in the array have the same value as rand, or is rand's initial value zero? If so, set it to a random * 22. This can be done by evaluating sequence functions like find-if. (Alternatively, I don't know if CL has a function that lets you specify a list/range of indices and get back a list of values . . . but if it doesn't have one we could write one, and then use a contains check. pseudocode: (or ((contains (our-containment-function used-numbers range) rand) (= rand 0)) (setf rand (random 22))) Which is a single if'd assignment, but slightly more readable. But there's more optimization -- because I would assume that the zero check is just to see if it has been assigned a random value yet or not. If so, then it will ALWAYS assign a value to rand (ie it will never let rand through unassigned). In most programs this would indicate a logical error, but there is really no context here, so we can assume that it's desired behavior. This means that the entire loop evaluates to a really obfuscated way of accomplishing a simple assignment of rand to a random value in the range of 22. (setf rand (random 22)) Add to that the fact that the majority of variable assignment is totally unnecessary (and is usually used in less capable languages to help simulate lexical closures) and leads to side effects, it's not terribly unlikely that the whole assignment was a bad idea in the first place, and we can probably strike the whole thing, leaving us with nothing. Which would be a pretty good optimization! [Edit 2 times, last edit by Former Member at Apr 12, 2005 6:00:19 PM] |
||
|
|
Former Member
Cruncher Joined: May 22, 2018 Post Count: 0 Status: Offline |
Some things are a bit more obvious than others.
|
||
|
|
Former Member
Cruncher Joined: May 22, 2018 Post Count: 0 Status: Offline |
---------------------------------------- [Edit 2 times, last edit by Former Member at Apr 13, 2005 12:06:13 PM] |
||
|
|
Former Member
Cruncher Joined: May 22, 2018 Post Count: 0 Status: Offline |
---------------------------------------- [Edit 1 times, last edit by Former Member at Apr 13, 2005 12:06:34 PM] |
||
|
|
|