Jump to content

Could we use code to solve this..


ItHadToComeToThis
 Share

You are about to reply to a thread that has been inactive for 1708 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

list answers = [25.0, 50.0, 60.0, 25.0];

integer n = llGetListLength(answers);
float m = 100.0 / (float)n;

integer c;
integer i;
for (i = 0; i < n; i++)
{
   c += (llList2Float(answers, i) == m);
} 

float result = 0.0;
if (c) result = 100.0 / (float)c;

 

  • Like 2
Link to comment
Share on other sites

I have tonight looked a bit more at the OP and the answer from Mollymews. It's fascinating as both pretend to give a defined question and a defined answer but the question is not sufficiently defined. As I couldn't say it better with my own words, I am posting an answer from puzzling:

Quote

 

When limited to the 4 provided answers, there is no correct answer, because this question is a paradox.

When there is one correct answer, the chance to pick that answer would be 25%. However, the answer 25% exists twice, so there is a 50% chance of picking it. But there is only one answer which says 50% and the chance to pick that answer is 25%

 

So if you try to solve this problem mathematically/logically, you will end up in an unsolvable circle. Therefore there is no way to solve solve this question in code, only the first half which Molly has done.

I also realise that the OP has edited his post, deleting the question if the problem could be solved with code. Probably he realised it was a non-solvable question.

 

Link to comment
Share on other sites

On 7/24/2019 at 9:28 AM, Mollymews said:

list answers = [25.0, 50.0, 60.0, 25.0];

integer n = llGetListLength(answers);
float m = 100.0 / (float)n;

integer c;
integer i;
for (i = 0; i < n; i++)
{
   c += (llList2Float(answers, i) == m);
} 

float result = 0.0;
if (c) result = 100.0 / (float)c;

 If I may, I have never come across this form of if-statement as I see it in the last row (without the "==" operator). Can anyone explain to me what happens in this row AKA the logic? Does the server ignore the part "if (c)" and just calculates a new value for result ( = 100.0/ (float)c )? I am confused.

 

Link to comment
Share on other sites

Question has 4 different single answers and is multiple choice on top we have 2 single answers being the same - we assume everyone knows the academic standard of multiple or all answers being allowed as correct and at least one has too be correct. At completly picking random we have 1(all)+4(3choices)+12(2 choices)+4(1 choice) possible answers, that is 21.... of those 21 answers only 3 are even logically correct given that only A+D; B alone and C alone make logical sense (there can not be 2 propabilities it has to be a singular one) - the chance to answer would be 1/21th with 18/21th answers being for sure contradicting and thus wrong...

This leaves us with the only correct approach being crossing the question out completly and writinging "you Sir/Lady, are a shame of for your academic institution" under it.

EDIT: I should leave integer additions to the CPUs

Edited by Fionalein
  • Haha 1
Link to comment
Share on other sites

17 hours ago, Estelle Pienaar said:

If I may, I have never come across this form of if-statement as I see it in the last row (without the "==" operator). Can anyone explain to me what happens in this row AKA the logic? Does the server ignore the part "if (c)" and just calculates a new value for result ( = 100.0/ (float)c )? I am confused.

If the variable is expected to contain a boolean (or something that can be interpreted as such), it's not uncommon to place that alone in the if-statement without the "==" operator. The if-statement will understand that an implicit comparison to the boolean TRUE value is being made.

In this specific example, the for loop is effectively performing comparison test and adding the result of the comparison to c. Recall that TRUE is equivalent to 1 and FALSE equivalent to 0. So let's substitute the values. For the first iteration, the line becomes:

c += (25.0 == 25.0);

Since 25.0 is equal to 25.0, the comparison succeeds and is evaluated as 1, which is then assigned to the c variable. This will happen once more, as only two of the possible list values are equal to 25.0. Ultimately when we get out of the loop, c=2, which since it's not 0, would be equivalent to TRUE. If I recall correctly, any positive integer value will be interpreted as TRUE in LSL.

When we get to the final line, the if-statement will evaluate and substitute any variables in the conditional with their current values. So "if(c)" is the same as "if(2)", which is the same as "if(TRUE)". And because of the implicit comparison I mentioned earlier, this is effectively the same as saying "if(TRUE==TRUE)". So this test passes and the code will execute the last command.

That last command is "result = 100.0 / (float)c;"

Which is another shorthand as well. If-statements that contain only one command afterward can be formatted to one line as shown above. It is the same as:

if (c)
{
  result = 100.0 / (float)c;
}

Edit: my original post misread the code and I thought variable m was assigned to be 100.0. If that had been the case, then c would have come out of the loop equaling 0 which would have been the same as FALSE, and the last command would have not been executed. But since that's not the case and c=2, the final command is executed and we have a result of 50.0 (percent).

Edit2: crossed out some incorrect reasoning. See Wulfie's post below.

Edited by Fenix Eldritch
more correctios
  • Thanks 1
Link to comment
Share on other sites

9 hours ago, Fenix Eldritch said:

If the variable is expected to contain a boolean (or something that can be interpreted as such), it's not uncommon to place that alone in the if-statement without the "==" operator. The if-statement will understand that an implicit comparison to the boolean TRUE value is being made.

In this specific example, the for loop is effectively performing comparison test and adding the result of the comparison to c. Recall that TRUE is equivalent to 1 and FALSE equivalent to 0. So let's substitute the values. For the first iteration, the line becomes:

Small corrections:

  • The code for an if-check will execute as long as the evaluation is true.
    • "if(true)" will execute the code after it, but there's no implicit "if(true == true)"
       
  • While the LSL constant TRUE has a value of  1, any non-zero value is not-false and would pass the if-check.
    • "if(3)" will execute the code after it.
       
  • When you are comparing things with == for example, you are actually creating a new value.
    • "integer test = (3 == 3);" is the same as "test = 1"

Edit: Ah, sorry, skipped literally the next thing you said so these aren't really corrections.

Edited by Wulfie Reanimator
  • Thanks 2
Link to comment
Share on other sites

@Estelle Pienaar

"When limited to the 4 provided answers, there is no correct answer, because this question is a paradox.

When there is one correct answer, the chance to pick that answer would be 25%. However, the answer 25% exists twice, so there is a 50% chance of picking it. But there is only one answer which says 50% and the chance to pick that answer is 25%"

 

this is a good analysis of the puzzle from a philosophical pov, that the puzzle can be a paradox

 

from a programmatic pov then the result can be a paradox only when code is programmed for there to be a paradox

as wrote 'result' returned by the code is 50%. And this code stops there

were our code to not accept this, and choose the other possible answer, then programmatically the chances of our code picking the other answer is now 100%

example:

...

i = llListFindList(answers, [result]);
string answer = "None";
if (~i) answer = llGetSubstring("ABCD", i, i);

ps add

a paradox is created by/within the rules of the language used to construct/describe the paradox

Edited by Mollymews
ps add
Link to comment
Share on other sites

41 minutes ago, Mollymews said:

@Estelle Pienaar

from a programmatic pov then the result can be a paradox only when code is programmed for there to be a paradox

I am not experienced enough a coder to argue on the programming part of your statement. But from the logic/mathematical POV (and I insist that your attribution of "philosophical" is misleading), not the result can or cannot be a paradox, it is the question that is the paradox and that cannot be solved. Not matematically and not by code. (and the name of this thread is "Could we use code to solve this...").

In other words, your code gives us a result (plus I really like it and it has taught me something), but it does not solve the puzzle in any meaningfull way.

Link to comment
Share on other sites

23 minutes ago, Estelle Pienaar said:

From the logic/mathematical POV (and I insist that your attribution of "philosophical" is misleading), not the result can or cannot be a paradox, it is the question that is the paradox and that cannot be solved. Not matematically and not by code. (and the name of this thread is "Could we use code to solve this...").

i take your point that philosophically is maybe a bit broad

Looking at this from a narrower pov, the puzzle is a linguistic construction that asks us to make a unary decision (pick one) where the answer is Linguistically Unanswerable

programmatically we could parse the question, and on parsing 'an answer" have the program say that the question is linguistically unanswerable

Link to comment
Share on other sites

6 hours ago, Wulfie Reanimator said:
  • The code for an if-check will execute as long as the evaluation is true.
    • "if(true)" will execute the code after it, but there's no implicit "if(true == true)"

Shoot, you're absolutely right. I got carried away in my extrapolations. I now recall other instances that clearly disprove my claim: a valid key by itself in a conditional will also evaluate as true so an implicit "==true"wouldn't make sense in that case. Thanks for the correction!

Edited to add: The wiki page for IF statement has a neat table that I hadn't noticed before. It shows under what conditions the different variable types will evaluate as true. (I should have checked there in the first place :) )

Type Condition
integer True if it is not zero.
float True if it is not zero.[1]
string True if its length is not zero.
key True only if it is a valid key and not NULL_KEY.
vector True if the vector is not ZERO_VECTOR.
rotation True if the rotation is not ZERO_ROTATION.
list True if the length is not zero.
Edited by Fenix Eldritch
  • Like 3
  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1708 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...