Home > Mathematica, Mathematics > On the Clock

On the Clock

I have continued to learn a lot from Mathematica Stackexchange, Some of this has occurred with embarrassment (as I miss some obvious point). These small humiliations are, however, opportunities to learn and for improvement.

This post arises from my failure to account for the obvious challenges of modular arithmetic in relation to handling date and time data.  User Mr. Wizard is an unending source of education (done in clear, polite and with integrity).

Here (for my own educational purposes  and archive) is a way to partition a list based on elements within d of starting element:

 

 

sp[u_, d_] := Module[
{s, off},
s = Sort@u;
off = Mod[First@s, d];
GatherBy[list, Floor[# - off, d] &]
]

Using a test case

list = RandomInteger[10, 1000];

and visualizing:
ListPlot[sp[list, 5], PlotStyle -> {Red, Green, Blue}, Frame -> True]

yields:

wordpressmodular

Advertisements
Categories: Mathematica, Mathematics
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s