Math challenge, round to nearest 5 minute interval

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Math challenge, round to nearest 5 minute interval

Jolle Carlestam-3
Lack a bit of math and lasso knowledge in regards to rounding.

I want to round to the nearest 5 minute interval. Or alternatively find the nearest lower value in a five minute interval.

Say that I have values

2, 8, 11 and 13

after rounding I would like to have
0, 10, 10 and 15
or possibly
0, 5, 10, 10

What's the math to accomplish that?

HDB
Jolle
#############################################################
This message is sent to you because you are subscribed to
  the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
To switch to the DIGEST mode, E-mail to <[hidden email]>
To switch to the INDEX mode, E-mail to <[hidden email]>
Send administrative queries to  <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: Math challenge, round to nearest 5 minute interval

Brad Lindsay-2
I think something like this should work:
Round(# mins / 5) * 5

Brad


On Jul 18, 2011, at 8:43 AM, Jolle Carlestam wrote:

> Lack a bit of math and lasso knowledge in regards to rounding.
>
> I want to round to the nearest 5 minute interval. Or alternatively find the nearest lower value in a five minute interval.
>
> Say that I have values
>
> 2, 8, 11 and 13
>
> after rounding I would like to have
> 0, 10, 10 and 15
> or possibly
> 0, 5, 10, 10
>
> What's the math to accomplish that?
>
> HDB
> Jolle
> #############################################################
> This message is sent to you because you are subscribed to
>  the mailing list <[hidden email]>.
> To unsubscribe, E-mail to: <[hidden email]>
> To switch to the DIGEST mode, E-mail to <[hidden email]>
> To switch to the INDEX mode, E-mail to <[hidden email]>
> Send administrative queries to  <[hidden email]>
>


#############################################################
This message is sent to you because you are subscribed to
  the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
To switch to the DIGEST mode, E-mail to <[hidden email]>
To switch to the INDEX mode, E-mail to <[hidden email]>
Send administrative queries to  <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: Math challenge, round to nearest 5 minute interval

Jolle Carlestam-3
Thanks Brad!

Not that you provided actual working Lasso code. :-)
That was easy to fix.

Pending yours and others responses I found this on my own
math_round((#mins * 2), 10.0)/2)

Comparing the two methods like this:
iterate(array(2,5,8,10,11,13,15,19,21,))
        loop_value
        ' --- '
        integer(math_round((loop_value * 2), 10.0)/2) // my fiddling
        ' --- '
        integer(math_round(loop_value / 5, 1.0) * 5) // Brads suggestion
        '<br>'
/iterate
->
2 --- 0 --- 0
5 --- 5 --- 5
8 --- 10 --- 5
10 --- 10 --- 10
11 --- 10 --- 10
13 --- 15 --- 10
15 --- 15 --- 15
19 --- 20 --- 15
21 --- 20 --- 20

Looks to work equally well. I still prefer yours to mine.

Thanks!

HDB
Jolle

18 jul 2011 kl. 14.48 skrev Brad Lindsay:

> I think something like this should work:
> Round(# mins / 5) * 5
>
> Brad
>
>
> On Jul 18, 2011, at 8:43 AM, Jolle Carlestam wrote:
>
>> Lack a bit of math and lasso knowledge in regards to rounding.
>>
>> I want to round to the nearest 5 minute interval. Or alternatively find the nearest lower value in a five minute interval.
>>
>> Say that I have values
>>
>> 2, 8, 11 and 13
>>
>> after rounding I would like to have
>> 0, 10, 10 and 15
>> or possibly
>> 0, 5, 10, 10
>>
>> What's the math to accomplish that?
>>
>> HDB
>> Jolle


#############################################################
This message is sent to you because you are subscribed to
  the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
To switch to the DIGEST mode, E-mail to <[hidden email]>
To switch to the INDEX mode, E-mail to <[hidden email]>
Send administrative queries to  <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: Math challenge, round to nearest 5 minute interval

Richard Taubo
Just for the record you could also use the following (where %=modulo):
        integer(loop_value - (loop_value%5))

That should give the same result as in Brad´s case.

Richard Taubo

On 18. juli 2011, at 15.00, Jolle Carlestam wrote:

> Thanks Brad!
>
> Not that you provided actual working Lasso code. :-)
> That was easy to fix.
>
> Pending yours and others responses I found this on my own
> math_round((#mins * 2), 10.0)/2)
>
> Comparing the two methods like this:
> iterate(array(2,5,8,10,11,13,15,19,21,))
> loop_value
> ' --- '
> integer(math_round((loop_value * 2), 10.0)/2) // my fiddling
> ' --- '
> integer(math_round(loop_value / 5, 1.0) * 5) // Brads suggestion
> '<br>'
> /iterate
> ->
> 2 --- 0 --- 0
> 5 --- 5 --- 5
> 8 --- 10 --- 5
> 10 --- 10 --- 10
> 11 --- 10 --- 10
> 13 --- 15 --- 10
> 15 --- 15 --- 15
> 19 --- 20 --- 15
> 21 --- 20 --- 20
>
> Looks to work equally well. I still prefer yours to mine.
>
> Thanks!
>
> HDB
> Jolle
>
> 18 jul 2011 kl. 14.48 skrev Brad Lindsay:
>
>> I think something like this should work:
>> Round(# mins / 5) * 5
>>
>> Brad
>>
>>
>> On Jul 18, 2011, at 8:43 AM, Jolle Carlestam wrote:
>>
>>> Lack a bit of math and lasso knowledge in regards to rounding.
>>>
>>> I want to round to the nearest 5 minute interval. Or alternatively find the nearest lower value in a five minute interval.
>>>
>>> Say that I have values
>>>
>>> 2, 8, 11 and 13
>>>
>>> after rounding I would like to have
>>> 0, 10, 10 and 15
>>> or possibly
>>> 0, 5, 10, 10
>>>
>>> What's the math to accomplish that?
>>>
>>> HDB
>>> Jolle
>
>
> #############################################################
> This message is sent to you because you are subscribed to
>  the mailing list <[hidden email]>.
> To unsubscribe, E-mail to: <[hidden email]>
> To switch to the DIGEST mode, E-mail to <[hidden email]>
> To switch to the INDEX mode, E-mail to <[hidden email]>
> Send administrative queries to  <[hidden email]>
>


#############################################################
This message is sent to you because you are subscribed to
  the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
To switch to the DIGEST mode, E-mail to <[hidden email]>
To switch to the INDEX mode, E-mail to <[hidden email]>
Send administrative queries to  <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: Math challenge, round to nearest 5 minute interval

Jolle Carlestam-3
Indeed it did.
Ah, there's so many lovely ways to skin a cat one should have become a sadistic butcher.

Thanks!

HDB
Jolle

18 jul 2011 kl. 16.45 skrev Richard Taubo:

> Just for the record you could also use the following (where %=modulo):
> integer(loop_value - (loop_value%5))
>
> That should give the same result as in Brad´s case.
>
> Richard Taubo
>
> On 18. juli 2011, at 15.00, Jolle Carlestam wrote:
>
>> Thanks Brad!
>>
>> Not that you provided actual working Lasso code. :-)
>> That was easy to fix.
>>
>> Pending yours and others responses I found this on my own
>> math_round((#mins * 2), 10.0)/2)
>>
>> Comparing the two methods like this:
>> iterate(array(2,5,8,10,11,13,15,19,21,))
>> loop_value
>> ' --- '
>> integer(math_round((loop_value * 2), 10.0)/2) // my fiddling
>> ' --- '
>> integer(math_round(loop_value / 5, 1.0) * 5) // Brads suggestion
>> '<br>'
>> /iterate
>> ->
>> 2 --- 0 --- 0
>> 5 --- 5 --- 5
>> 8 --- 10 --- 5
>> 10 --- 10 --- 10
>> 11 --- 10 --- 10
>> 13 --- 15 --- 10
>> 15 --- 15 --- 15
>> 19 --- 20 --- 15
>> 21 --- 20 --- 20
>>
>> Looks to work equally well. I still prefer yours to mine.
>>
>> Thanks!
>>
>> HDB
>> Jolle
>>
>> 18 jul 2011 kl. 14.48 skrev Brad Lindsay:
>>
>>> I think something like this should work:
>>> Round(# mins / 5) * 5
>>>
>>> Brad
>>>
>>>
>>> On Jul 18, 2011, at 8:43 AM, Jolle Carlestam wrote:
>>>
>>>> Lack a bit of math and lasso knowledge in regards to rounding.
>>>>
>>>> I want to round to the nearest 5 minute interval. Or alternatively find the nearest lower value in a five minute interval.
>>>>
>>>> Say that I have values
>>>>
>>>> 2, 8, 11 and 13
>>>>
>>>> after rounding I would like to have
>>>> 0, 10, 10 and 15
>>>> or possibly
>>>> 0, 5, 10, 10
>>>>
>>>> What's the math to accomplish that?
>>>>
>>>> HDB
>>>> Jolle
>>
>>
>> #############################################################
>> This message is sent to you because you are subscribed to
>> the mailing list <[hidden email]>.
>> To unsubscribe, E-mail to: <[hidden email]>
>> To switch to the DIGEST mode, E-mail to <[hidden email]>
>> To switch to the INDEX mode, E-mail to <[hidden email]>
>> Send administrative queries to  <[hidden email]>
>>
>
>
> #############################################################
> This message is sent to you because you are subscribed to
>  the mailing list <[hidden email]>.
> To unsubscribe, E-mail to: <[hidden email]>
> To switch to the DIGEST mode, E-mail to <[hidden email]>
> To switch to the INDEX mode, E-mail to <[hidden email]>
> Send administrative queries to  <[hidden email]>
>
>
>


#############################################################
This message is sent to you because you are subscribed to
  the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
To switch to the DIGEST mode, E-mail to <[hidden email]>
To switch to the INDEX mode, E-mail to <[hidden email]>
Send administrative queries to  <[hidden email]>

Reply | Threaded
Open this post in threaded view
|

Re: Math challenge, round to nearest 5 minute interval

Jolle Carlestam-3
In reply to this post by Richard Taubo
I could not have been fully awoke when I looked at the results before. There is a difference between my approach and Brad/Richard.

Looks like my attempt really does correct rounding whereas Brad/Richard code does the alternative solution in rounding down to closest 5 interval.
In my case that's the preferred solution. But I honestly didn't spot the different results until now.

Well, as they say, the last thing you go blind on is your eyes.

HDB
Jolle

18 jul 2011 kl. 16.45 skrev Richard Taubo:

> Just for the record you could also use the following (where %=modulo):
> integer(loop_value - (loop_value%5))
>
> That should give the same result as in Brad´s case.
>
> Richard Taubo
>
> On 18. juli 2011, at 15.00, Jolle Carlestam wrote:
>
>> Thanks Brad!
>>
>> Not that you provided actual working Lasso code. :-)
>> That was easy to fix.
>>
>> Pending yours and others responses I found this on my own
>> math_round((#mins * 2), 10.0)/2)
>>
>> Comparing the two methods like this:
>> iterate(array(2,5,8,10,11,13,15,19,21,))
>> loop_value
>> ' --- '
>> integer(math_round((loop_value * 2), 10.0)/2) // my fiddling
>> ' --- '
>> integer(math_round(loop_value / 5, 1.0) * 5) // Brads suggestion
>> '<br>'
>> /iterate
>> ->
>> 2 --- 0 --- 0
>> 5 --- 5 --- 5
>> 8 --- 10 --- 5
>> 10 --- 10 --- 10
>> 11 --- 10 --- 10
>> 13 --- 15 --- 10
>> 15 --- 15 --- 15
>> 19 --- 20 --- 15
>> 21 --- 20 --- 20
>>
>> Looks to work equally well. I still prefer yours to mine.
>>
>> Thanks!
>>
>> HDB
>> Jolle
>>
>> 18 jul 2011 kl. 14.48 skrev Brad Lindsay:
>>
>>> I think something like this should work:
>>> Round(# mins / 5) * 5
>>>
>>> Brad
>>>
>>>
>>> On Jul 18, 2011, at 8:43 AM, Jolle Carlestam wrote:
>>>
>>>> Lack a bit of math and lasso knowledge in regards to rounding.
>>>>
>>>> I want to round to the nearest 5 minute interval. Or alternatively find the nearest lower value in a five minute interval.
>>>>
>>>> Say that I have values
>>>>
>>>> 2, 8, 11 and 13
>>>>
>>>> after rounding I would like to have
>>>> 0, 10, 10 and 15
>>>> or possibly
>>>> 0, 5, 10, 10
>>>>
>>>> What's the math to accomplish that?
>>>>
>>>> HDB
>>>> Jolle
>>
>>
>> #############################################################
>> This message is sent to you because you are subscribed to
>> the mailing list <[hidden email]>.
>> To unsubscribe, E-mail to: <[hidden email]>
>> To switch to the DIGEST mode, E-mail to <[hidden email]>
>> To switch to the INDEX mode, E-mail to <[hidden email]>
>> Send administrative queries to  <[hidden email]>
>>
>
>
> #############################################################
> This message is sent to you because you are subscribed to
>  the mailing list <[hidden email]>.
> To unsubscribe, E-mail to: <[hidden email]>
> To switch to the DIGEST mode, E-mail to <[hidden email]>
> To switch to the INDEX mode, E-mail to <[hidden email]>
> Send administrative queries to  <[hidden email]>
>
>
>


#############################################################
This message is sent to you because you are subscribed to
  the mailing list <[hidden email]>.
To unsubscribe, E-mail to: <[hidden email]>
To switch to the DIGEST mode, E-mail to <[hidden email]>
To switch to the INDEX mode, E-mail to <[hidden email]>
Send administrative queries to  <[hidden email]>