// SPDX-License-Identifier: MIT
// Copyright (c) 2026 Incoprea
// Measure balance across a weighted collection
// Not compiled or tested in-world
// Setup: Place in a spare owned prim. Set WEIGHTS with at least two positive entries. Touch to run; output is private to the owner.
// Stop / restore: Disable/remove. No scene changes or external calls.
// Notes: Returns zero for highly concentrated weights in the limit and one for equal weights. Uses natural logarithms; it is a balance descriptor, not a quality score.
// License: see LICENSE in this distribution.
// Original Incoprea. MIT.
list WEIGHTS=[6.0,3.0,1.0];
default
{
    touch_start(integer detectedCount)
    {
        if(llDetectedKey(0)!=llGetOwner())return;
        integer n=llGetListLength(WEIGHTS);
        if(n<2)
        {
            llOwnerSay("Need at least two weights.");
            return;
        }
        float total;
        integer i;
        for(i=0;i<n;++i)
        {
            float w=llList2Float(WEIGHTS,i);
            if(w<=0.0)
            {
                llOwnerSay("Weights must be positive.");
                return;
            }
            total+=w;
        }
        float entropy;
        for(i=0;i<n;++i)
        {
            float p=llList2Float(WEIGHTS,i)/total;
            entropy-=p*llLog(p);
        }
        llOwnerSay("Normalized entropy="+(string)(entropy/llLog((float)n)));
    }
}
