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. 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) 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: \( 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 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)