Re: Math problem

2012-02-19 Thread Kay C Lan
Once I put 17 into tRepeats so I do 102 cycles, I get very similar: For 102 cycles K's solution = 1657ms Paul's solution = 1453ms Geoff's solution = 1536ms For 102 cycles K's solution = 1638ms Paul's solution = 1455ms Geoff's solution = 1533ms For 102 cycles K's solution =

Re: Math problem

2012-02-19 Thread Kay C Lan
On Sun, Feb 19, 2012 at 5:32 PM, Kay C Lan wrote: > >put "For " & tRepeats & " cycles" & cr into R > > Oopps. That should read "For " & (6 * tRepeats) & " cycles" & cr into R Because of the nested repeat it's really doing 600 cycles. ___ use-li

Re: Math problem

2012-02-19 Thread Kay C Lan
On Sun, Feb 19, 2012 at 4:48 PM, Geoff Canyon Rev wrote: > "repeat for each line" is incredibly fast, so I'm not surprised that it > beats an array. Interestingly, I was able to speed up all three solutions > by doing this: > > get aTime[i]["Increment"] > > and then using "it" in the math mak

Re: Math problem

2012-02-19 Thread Geoff Canyon Rev
On Sun, Feb 19, 2012 at 12:58 AM, Kay C Lan wrote: > I've tweaked your solution only slightly as you solution only worked for > quarter hour increment, whilst both mine and Paul's would work for any > required increment . I simply replace your fixed 4 with the 3600/increment > that both Paul and I

Re: Math problem

2012-02-18 Thread Kay C Lan
On Sun, Feb 19, 2012 at 12:22 PM, Geoff Canyon Rev wrote: > (and to return hours, so it matches the output of the other > two). > OK, now I see where I was getting confused. I was focused on decimal hours as per the OP, but you were outputting seconds. I've tweaked your solution only slightly a

Re: Math problem

2012-02-18 Thread J. Landman Gay
On 2/18/12 10:32 PM, Geoff Canyon Rev wrote: On Sat, Feb 18, 2012 at 9:57 PM, J. Landman Gay wrote: function whichOne var,fld1,fld2 -- from a handler by Tony Root -- Handles a case where you need to return one value if your key is empty, another if not. return (item offset(char 1 of (var =

Re: Math problem

2012-02-18 Thread Geoff Canyon Rev
On Sat, Feb 18, 2012 at 9:57 PM, J. Landman Gay wrote: > function whichOne var,fld1,fld2 > -- from a handler by Tony Root > -- Handles a case where you need to return one value if your key is empty, > another if not. > > return (item offset(char 1 of (var = empty),"tf") of quote & fld1 &","& >

Re: Math problem

2012-02-18 Thread Geoff Canyon Rev
On Fri, Feb 17, 2012 at 7:55 PM, Kay C Lan wrote: > Guys I thought I'd speed test these. Given that we're dealing in seconds (and therefore integers), the very clever itemoffset idea Peter came up with is unnecessary. Here's a comparison of the three options, with mine tweaked to be similar to

Re: Math problem

2012-02-18 Thread J. Landman Gay
On 2/18/12 7:41 PM, Peter M. Brigham, MD wrote: I picked this trick up from someone along the way, on this list I believe, I've lost track of where it came from, so credit goes to someone else. It may be from something I posted to the HyperCard list eons ago. I got it from Paul Foraker, who wo

Re: Math problem

2012-02-18 Thread Joe Lewis Wilkins
That's great. I understand. Sometimes we get a bit too cryptic for our own good. (smile) Joe Wilkins Architect On Feb 18, 2012, at 7:45 PM, Geoff Canyon Rev wrote: > This is the entire function definition, with the comment in place: > > function roundUp x,i -- rounds x up to the next i > retu

Re: Math problem

2012-02-18 Thread Geoff Canyon Rev
This is the entire function definition, with the comment in place: function roundUp x,i -- rounds x up to the next i return x div i * i + item itemoffset((x mod i > 0),"true,false") of (i,0) end roundUp I only included the first line in my original question because it's the only line with a com

Re: Math problem

2012-02-18 Thread Joe Lewis Wilkins
Kind of true Geoff, but the call would have arguments in place of parameters, whereas function roundUp x,i isn't the function's definition either. Not intending to nit-pick. Joe Wilkins Architect On Feb 18, 2012, at 7:01 PM, Geoff Canyon Rev wrote: > ? That is the definition (and not a call

Re: Math problem

2012-02-18 Thread Joe Lewis Wilkins
No Al, In the early days, even with HC, when most of us were using Assembler, Pascal and Basic, it was not in the lease uncommon to comment every line of code so we knew what we were doing; particularly with Assembly language. Of course using C it was an absolute must; and, if I were working wi

Re: Math problem

2012-02-18 Thread Alejandro Tejada
by step... Is this science fiction or does actually exists something alike in some development platform? Al -- View this message in context: http://runtime-revolution.278305.n4.nabble.com/Math-problem-tp4385121p4401011.html Sent from the Revolution - User mailing list archive at Nabble.com. ___

Re: Math problem

2012-02-18 Thread Geoff Canyon Rev
? That is the definition (and not a call). On Sat, Feb 18, 2012 at 2:24 PM, Joe Lewis Wilkins wrote: > Certainly better than nothing; but, if you put it in the function > definition instead of the calls, you only have to do it one time. > > Joe Wilkins > > On Feb 18, 2012, at 12:04 PM, gcanyon+r

Re: Math problem

2012-02-18 Thread Joe Lewis Wilkins
You're forgiven, Peter. Joe Wilkins Architect On Feb 18, 2012, at 5:41 PM, Peter M. Brigham, MD wrote: > I picked this trick up from someone along the way, on this list I believe, > I've lost track of where it came from, so credit goes to someone else. You're > right, Joe, commenting something

Re: Math problem

2012-02-18 Thread Peter M. Brigham, MD
I picked this trick up from someone along the way, on this list I believe, I've lost track of where it came from, so credit goes to someone else. You're right, Joe, commenting something as opaque as this (at least at first glance) is advisable, especially when you're sharing code. I can only ple

Re: Math problem

2012-02-18 Thread Joe Lewis Wilkins
Alex, I'm sure that one of the problems that faces most new LC coders is that they do too much before they try it out. By the time I have something "done" I've already debugged it dozens of times. It just works. Of course I don't stretch LC to its limits very often. When I do something, I've do

Re: Math problem

2012-02-18 Thread Alejandro Tejada
ience fiction or does actually exists something like that in some development platform? Does exist Linting software for this language? (Besides the Livecode own compiler) http://en.wikipedia.org/wiki/Lint_(software) Al -- View this message in context: http://runtime-revolution.278305.n4.nabble.co

Re: Math problem

2012-02-18 Thread Joe Lewis Wilkins
Certainly better than nothing; but, if you put it in the function definition instead of the calls, you only have to do it one time. Joe Wilkins On Feb 18, 2012, at 12:04 PM, gcanyon+rev wrote: > I'm curious what you think of this, which is what I try to do regularly when > I create one-liners

Re: Math problem

2012-02-18 Thread gcanyon+rev
I'm curious what you think of this, which is what I try to do regularly when I create one-liners (which I favor). function roundUp x,i -- rounds x up to the next i On Feb 18, 2012, at 11:23 AM, Joe Lewis Wilkins wrote: > If you're going to use one liners like this, you'd better add some comme

Re: Math problem

2012-02-18 Thread Joe Lewis Wilkins
True Ken, but w/o comment it is much more difficult to know what is going on. If you're going to use one liners like this, you'd better add some commentary. One of the weaknesses I see in LC coding is the shortage of comments. I realize that is a strong-point of LC; it is "almost" self-commentin

Re: Math problem

2012-02-18 Thread Ken Ray
> function roundUp x > return trunc(x) + char itemoffset((x mod 1 > 0),"true,false") of "10" > end roundUp VERY clever, Peter! That's a great one-line variant to: function roundUp x put trunc(x) into tRetVal if x mod 1 > 0 then add 1 to tRetVal return tRetVal end roundUp :D Ken Ray Son

Re: Math problem

2012-02-17 Thread Peter M. Brigham, MD
Well, there's something wrong with the K solution and the Paul solution. Stepping through the script with the debugger, for the first line of tStore, the difference between tEndTime and tStartTime = 7974 (I inserted a temp variable tTemp = tEndTime - tStartTime so I could see what was going on).

Re: Math problem

2012-02-17 Thread Bob Sneidar
This is beginning to look Disturbingly like regex! Sent from my iPad On Feb 17, 2012, at 7:13 PM, "Peter M. Brigham, MD" wrote: > On Feb 17, 2012, at 6:39 PM, Geoff Canyon Rev wrote: > >> My original function took the number to be rounded and the increment to >> round up to, so I think your v

Re: Math problem

2012-02-17 Thread Peter M. Brigham, MD
On Feb 17, 2012, at 6:39 PM, Geoff Canyon Rev wrote: > My original function took the number to be rounded and the increment to > round up to, so I think your version would become: > > function roundUp x,i -- rounds x up to the next i > return x div i * i + item itemoffset((x mod i > 0),"true,fal

Re: Math problem

2012-02-17 Thread Kay C Lan
Guys I thought I'd speed test these. Unfortunately I don't have the time to figure out exactly how Geoff's amended version of Peter's solution actually works in this case; rounding 1.1 to 1.25, 3.3 to 3.5. I can get it to work with whole numbers, but not 0.25 increments as per the OP. The current

Re: Math problem

2012-02-17 Thread Bob Sneidar
OK now you are just showing off! :-) Bob On Feb 17, 2012, at 3:39 PM, Geoff Canyon Rev wrote: > My original function took the number to be rounded and the increment to > round up to, so I think your version would become: > > function roundUp x,i -- rounds x up to the next i > return x div i *

Re: Math problem

2012-02-17 Thread Geoff Canyon Rev
My original function took the number to be rounded and the increment to round up to, so I think your version would become: function roundUp x,i -- rounds x up to the next i return x div i * i + item itemoffset((x mod i > 0),"true,false") of (i,0) end roundUp On Fri, Feb 17, 2012 at 1:49 PM, Pet

Re: Math problem

2012-02-17 Thread Bob Sneidar
Thanks for that Paul! Bob On Feb 17, 2012, at 2:03 PM, Paul Dupuis wrote: > Well Bob, here is one more: > > -- countTheHour with NO IF statements, proper rounding, and a single > calculation line > -- pIncrement is in seconds, so 900 equals 15 minutes increments. The > default (by the max func

Re: Math problem

2012-02-17 Thread Paul Dupuis
Well Bob, here is one more: -- countTheHour with NO IF statements, proper rounding, and a single calculation line -- pIncrement is in seconds, so 900 equals 15 minutes increments. The default (by the max function) is 1 minute (60 seconds) -- 1 second in 1 hour is 1/3600 or 0.000278, so the roundUp

Re: Math problem

2012-02-17 Thread Bob Sneidar
Thanks all. Some ingenious ways of going about it. Never ceases to amaze me when I see all the ways of doing something when I thought there was only 1. :-) Bob On Feb 17, 2012, at 11:49 AM, Peter M. Brigham, MD wrote: > On Feb 17, 2012, at 12:20 PM, Geoff Canyon Rev wrote: > >> function round

Re: Math problem

2012-02-17 Thread Peter M. Brigham, MD
On Feb 17, 2012, at 12:20 PM, Geoff Canyon Rev wrote: > function roundUp x,i -- rounds x up to the next i > return ((x - .1) div i + 1) * i > end roundUp Works except for values like 4.1. Try this instead. It's a sort of a trick to avoid using a conditional construction, though th

Re: Math problem

2012-02-17 Thread Geoff Canyon Rev
Obviously you could do this inline, but then it wouldn't be reusable. I'd go with a function: function roundUp x,i -- rounds x up to the next i return ((x - .1) div i + 1) * i end roundUp function test T1,T2 -- returns the difference between two times in seconds -- rounded up to the

Re: Math problem

2012-02-17 Thread Kay C Lan
On Tue, Feb 14, 2012 at 6:09 AM, Bob Sneidar wrote: > Hey there it is! I was looking for a strictly mathematical method but that > will do nicely. > > Not sure how Paul's response could be the answer as it seems to miss an important step. "--take the difference in pIncrement units, rounded up…"

Re: Math problem

2012-02-13 Thread Bob Sneidar
Hey there it is! I was looking for a strictly mathematical method but that will do nicely. Bob On Feb 13, 2012, at 12:48 PM, Paul Dupuis wrote: > FUNCTION countTheHours2 pStartTime, pEndTime, pIncrement >IF pIncrement is empty THEN put 900 into pIncrement -- pIncrement is > in seconds. So

Re: Math problem

2012-02-13 Thread Paul Dupuis
FUNCTION countTheHours2 pStartTime, pEndTime, pIncrement IF pIncrement is empty THEN put 900 into pIncrement -- pIncrement is in seconds. So 900 is 15 minutes. Do not use zero. 1 is minimum. TRY convert pStartTime to seconds convert pEndTime to seconds put (round

Math problem

2012-02-13 Thread Bob Sneidar
For anyone who is good at math, here is (for me) a sticky problem. I can of course solve this with a conditional statement, and have done, but I want to see if there is a way by formula alone to solve it. This is not essential, just an exercise in math. I have 2 times, a start time and an end