Post Reply 
Maths/Stats challenge - 1 of 2 - polls
05-26-2022, 12:01 PM
Post: #19
RE: Maths/Stats challenge - 1 of 2 - polls
Perhaps it is safer to avoid solutions that depends on how half-way cases is handled.

Starting from roundtrip condition:

round(round(P[i]*n/100)*100/n) == P[i]                  // assumed integer P[i], unit = %

→ abs(round(P[i]*n/100)*100/n - P[i]) < 0.5           // half-way solutions removed
→ abs(round(P[i]*n/100)*100 - P[i]*n)*2 < n          // multiply by 2n
→ abs(smod(P[i]*n, 100))*2 < n                             // smod = Euclidean symmetric remainder

If n=100, LHS=0 → always roundtrip.
If n>100, max(LHS)=100 < n → always roundtrip.

We flip roundtrip condition for badn:
Code:
function badn(n,P)  -- removed half-way solutions
    for i=1,#P do
        if abs((P[i]*n+50)%100-50)*2 >= n then return true end
    end
end

function firstn(P)  -- assume P table of integers, unit=%
    for n=1,99 do   -- search non-trivial solution only
        if not badn(n,P) then return n end
    end
end

(05-25-2022 10:39 AM)Joe Horn Wrote:  My 50g program finds these smaller denominator solutions:

[5. 9. 8.] / 22 ~ [0.23 0.41 0.36]
[6. 9. 23. 13.] / 51 ~ [0.12 0.18 0.45 0.25]
[7. 1. 23. 14.] / 45 ~ [0.16 0.02 0.51 0.31]
[24. 9. 13. 7. 0.] / 53 ~ [0.45 0.17 0.25 0.13 0. ]

lua> firstn {23, 41, 36}
22
lua> firstn {12, 18, 45, 25}
51
lua> firstn {16, 2, 51, 31}
45
lua> firstn {45, 17, 25, 13, 0}
53

This matched Joe Horns answer, implied solutions does not have any half-way cases.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Maths/Stats challenge - 1 of 2 - polls - Albert Chan - 05-26-2022 12:01 PM



User(s) browsing this thread: 1 Guest(s)