File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

narrow down a range algorithm

 
Joe Robles
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a range of two date values. I need to write logic that keeps breaking the range further into lesser ranges till no more ranges are avaiable.

Is there any algorithm that I can use to do this in java.

Any help is highly appreciated.

Thanks in advance for your valuable time and interest.

Example:

start date - 01-01-1981
end date - 01-01-1988

The program must add the above and divide by 2 repeatedly so I get the following ranges.

1981-1988
1988-1994
1994-2000
2000-2006


 
Henry Wong
author
Marshal
Pie
Posts: 20835
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The program must add the above and divide by 2 repeatedly so I get the following ranges.

1981-1988
1988-1994
1994-2000
2000-2006



Can you elaborate your example a bit? I don't see any adding and divide by 2 going on.

Henry
 
Joe Robles
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

My bad.

New example:

Date range that needs to be broken: 1960 - 2000

I chose to add the above values and divide by two; and need to repeat the same for each of the resultant ranges; then the resultant ranges need to end up like this:

1960 - 1965
1965 - 1970
1970 - 1975
1975 - 1980
1980 - 1985
1985 - 1990
1990 - 1995
1995 - 2000


Hope this helps...

Thanks.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those aren't divided ranges. They have an overlap. What you actually want is
1961 to 2000

1961 to 1980, 1981 to 2000

1961 to 1970, 1971 to 1980, 1981 to 1990, 1991 to 2000, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic