Post Reply 
Micro-challenge: Special Event
01-03-2023, 03:24 PM (This post was last modified: 01-04-2023 02:33 PM by Albert Chan.)
Post: #23
RE: Micro-challenge: Special Event
(01-03-2023 04:26 AM)Thomas Klemm Wrote:  
(01-02-2023 09:16 PM)Albert Chan Wrote:  BTW, there was a typo, the number have no radix point.

Believe it or not, that was on purpose.

I get it now ... it is not a typo.

Test with horner's rule code that allowed variable base (in a table)
Code:
function peval(a, b, s)
    s = s or 0
    if type(b) == 'table' then
        for i=1,#a do s = s*b[i] + a[i] end
    else
        for i=1,#a do s = s*b + a[i] end
    end
    return s
end

For example, 2 weeks 3 days 4 hours 5 minutes, convert to weeks only.
We could convert it all to minutes, then divide by minutes in 1 week.

lua> peval({2,3,4,5}, {1,7,24,60}), peval({1,0,0,0}, {1,7,24,60})
24725      10080
lua> 24725 / 10080
2.452876984126984

We could also do this in 1 shot: 2 + 1/7*(3 + 1/24*(4 + 1/60*5))

lua> peval({5,4,3,2}, {1,1/60,1/24,1/7})
2.452876984126984

Note: base first element is only a placeholder, that's why it stay put.
From Lua peval(a, b) code. With default s = 0, s*b[1] + a[1] = a[1]
As long as b[1] is finite, it will not affect result.

If we set s = a[1], and skip innermost factor, we get the same reult.

lua> peval({4,3,2}, {1/60,1/24,1/7}, 5)
2.452876984126984

(12-26-2022 02:00 PM)Thomas Klemm Wrote:  \(
\begin{align}
\pi = 2 + \frac{1}{3}\left(2 + \frac{2}{5}\left(2 + \frac{3}{7}\left(2 + \cdots \right)\right)\right)
\end{align}
\)

Thus we can write in this specific basis: \(\pi = 2.2222\cdots\).

To make pi = (2.2222 ...)b, we do the same way.

(2.2222)b = (22222 / 10000)b

lua> b = {1, 3/1, 5/2, 7/3, 9/4}
lua> peval({2,2,2,2,2}, b), peval({1,0,0,0,0}, b)
122      39.375
lua> 122 / 39.375 -- = 3 + 31/315
3.0984126984126985
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Micro-challenge: Special Event - EdS2 - 12-19-2022, 04:05 PM
RE: Micro-challenge: Special Event - johnb - 12-24-2022, 05:43 PM
RE: Micro-challenge: Special Event - EdS2 - 12-23-2022, 07:08 AM
RE: Micro-challenge: Special Event - johnb - 12-24-2022, 05:50 PM
RE: Micro-challenge: Special Event - Albert Chan - 01-03-2023 03:24 PM



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