For code using intervals to measure “distance” between values, possibly as input, output, or in method calls.

learn more… | top users | synonyms (1)

4
votes
2answers
89 views

Representing and Parsing an Open or Closed Range

I would like to represent a numeric range in C#. Either open-ended, such as "up to 35" or "100 on up" or closed-ended, such as "34 to 65". I'd like to represent the open end with NULL. Further, I'd ...
2
votes
2answers
104 views

Checking overlap ranges between two prices

I have a method (C#, .NET framework 4.0) to check overlapping ranges between two prices. I have a process, which will have one or more ...
2
votes
2answers
41 views

Merging an overlapping collection of intervals

I'm getting myself acquainted with Rust and decided to implement the classical overlapping intervals problem. Here is a statement of the problem: Given a collection of intervals, write a ...
8
votes
2answers
181 views

Parsing a list of single numbers and number ranges

I have input of a string containing a single number (like: \$3\$) or a range (like: \$1-5\$). Sample input, all together, looks like: "1-5,3,15-16", and sample ...
-2
votes
2answers
63 views

Rounding and truncation in IntRange.contains(Object o)

I made a Range class (like an Interval) that takes Integers and implements ...
3
votes
1answer
34 views

Merge adjacent numeric intervals

Given a list of pairs of integers that represent closed numeric intervals, I need to output a list of intervals where the adjacent intervals are merged together. The code assumes that the intervals do ...
5
votes
1answer
97 views

Combine a set of “ranges” to find least number of ranges

Given a set of ranges with lower bound and upper bound, I need to combine these ranges to produce minimum number of ranges which will cover all the values in the original set and nothing else. ...
1
vote
1answer
49 views

Find disjoint integer intervals

Given a list of numeric intervals in the form of (a,b), where a and b are integers, it finds ...
-2
votes
1answer
47 views

Checking whether the some of two ranges falls within a lower and upper bound

Problem 4 As per the given link, this exercise is part of recursion lab. Printer A prints a random x copies 50 ≤ x ≤ 60, and Printer B prints a random y ...
5
votes
1answer
146 views

A Range object for Java that partially implements `List`

I'm writing a neural net which uses a genetic algorithm to adjust the weights. To represent the possible range of "genes" for the GA, I'm passing in a list of bases. Unfortunately, I realized after ...
3
votes
1answer
66 views

Interval scheduling problem in C++

The problem I attempted to solve is described as: What is the largest subset of mutually non-overlapping intervals which can be selected from I? Where I is a set of N intervals where each ...
3
votes
2answers
76 views

Lazily combine ranges dependent on modulo with one loop

I have a positive integer n. I want to lazily loop over a range of integers less than n consisting of a) integers divisible by 3 ...
1
vote
0answers
53 views

Array slice type in Java - follow-up

See the previous iteration. I have essentially fixed most of the issues mentioned by maaartinus. However, I left the size field as it is. Namely, if the user wants ...
3
votes
1answer
138 views

Array slice type in Java

Edit See the next iteration at Array slice type in Java - follow-up. I have this "slice" type for managing array subranges. It is kind of the same thing as Pythons slice notation, yet I did not add ...
2
votes
1answer
62 views

Sum of squares of each interval

Q. Write three similar functions, each of which takes as an argument a sequence of intervals and returns the sum of the square of each interval that does not contain 0. Using a for ...
0
votes
1answer
86 views

Interval multiplication - faster version

For the below given problem from this assignment: Q4. In passing, Ben also cryptically comments, "By testing the signs of the endpoints of the intervals, it is possible to break ...
5
votes
3answers
360 views

Model interval inclusiveness in C#

This is my first attempt to model a day's time interval and the fact that the start and end are either inclusive or not: ...
1
vote
2answers
74 views

Counting only weekend days between two timestamps

I am fairly new to the Groovy arena. I recently modified some code to add the following block. This code is added to remove dates we were supposed to remove from the total counts. This data goes on ...
7
votes
1answer
80 views

Onion Run Festival (or the unexpected anagram for Union of Intervals)

Original question: Union of intervals In the original code, the Interval model class implements Comparable so that an input of ...
4
votes
1answer
126 views

Union of intervals

I am trying to solve for the problem with a bunch of intervals: (1,2),(2,5),(4,7),(9,11) I find their union, which in the above given case would be: ...
2
votes
1answer
20 views

1-D intersection of lines given begin and end points

I have a fairly basic question here: I want to find if two lines on a 1-D plane intersect. I know of two simple ways to solve this, but I wanted to know if Python has a more elegant way to solve this. ...
8
votes
4answers
826 views

Calculating range of ArrayLists

I have written this method which calculates the range (max - min) of an ArrayList. I have two for loops each for a different ...
4
votes
4answers
643 views

Aggregate array values into ranges

In five minutes I made a pretty ugly looking function. Can you help before I have to commit the code into history? Requirements: I would like a function that takes an array of numbers, and ...
4
votes
1answer
44 views

Average interval between dates with random blanks - follow-up

Original question: Average interval between dates with random blanks I have a spreadsheet with order date data: I need to find the average interval in days between each order date. I have to ...
5
votes
2answers
176 views

VSTO Write Dictionary To Range Extension Method

I was hoping to receive some criticism on this block of code. I wrote it to write the contents of a dictionary to excel range in VSTO. It works well. I am interested to see how people could improve ...
4
votes
1answer
75 views

Average interval between dates with random blanks

I have a spreadsheet with order date data: I need to find the average interval in days between each order date. I have to both find a way to get past the blank cells in the row, and also take into ...
2
votes
1answer
154 views

Formatting a date range, with shortening if the interval falls entirely within a calendar month

The graphic guy wants to display dates like 16. February 17. - 24. February, or ...
4
votes
3answers
1k views

Vertical Histogram

I've been been working on a vertical histogram that prints an asterisk in place of a number in a certain range (say 1-10... and so on). My code is working as required. Is there a better, simpler or ...
5
votes
1answer
99 views

Store CMTimeRange into Core Data

I wanted to store CMTimeRange structures inside managed objects, so I've worked out the following: ...
2
votes
1answer
42 views

Sane ranges for DB queries

I have a function that has, as input, a ranges object which may define from, to and ...
6
votes
4answers
2k views

Finding overlapping time intervals

You have two lists with meetings scheduling (start time, end time). Meetings in single list don't intersect. Find all intersecting meetings across the two lists. Is my complexity \$O(N M)\$? If I ...
3
votes
2answers
108 views

Reservation validation

I got a Reservation model that has reservation_start and reservation_end. Then I have the ...
8
votes
1answer
146 views

consecutive_find function for returning a consecutive range of elements

consecutive_find() is a function that returns the beginning of a range that contains strictly N consecutive elements. It was part of a SO question that I answered. ...
1
vote
2answers
222 views

Double Inclusive Range step by step

I've written a method to obtain an IEnumerable from a start point, end point and step. Similar to Enumerable.Range() but for doubles and not fixed step. ...
6
votes
4answers
2k views

Merging Overlapping Intervals

A while back I was asked the following question in a phone interview, and to be honest it stumped me. After many long nights of rolling the problem around in my head I think I came up with a decent ...
11
votes
2answers
717 views

CodeEval's SkyScrapers challenge

This is a solution to CodeEval's SkyScrapers challenge. You are given a list of triples \$(l, h, r)\$. Each triple represents an axis-aligned rectangle, with top-left corner at \$(l, h)\$ and ...
0
votes
1answer
68 views

Performance issue with conditionally removing keys from a dictionary [closed]

I'm new to Python (2.7 Spyder). My code takes a long time to execute, and seems overly complicated. I'd like to use the range function but it isn't behaving as expected so, I'm using a comparison of ...
4
votes
3answers
461 views

Mapping uint to value within min/max set

I have a method that transforms any input uint into a [min,max] set. I am looking for improvements on the function, specifically ...
10
votes
1answer
248 views

Tweets per second, using linked list

This is a TalentBuddy Challenge Your task is to write a function that prints to the standard output (stdout) the highest number of tweets recorded between each second in the array and the past ...
4
votes
3answers
510 views

Tweets per second

This challenge is from Talent Buddy: Tweets per second Japan Castle in the Sky airing broke a Twitter record on August 3, 2013. At one point during the classic anime movie showing, people ...
14
votes
2answers
693 views

Calculate the intersection between two intervals on the same circle

I want to calculate the ratio of intersection between two intervals; the length of the intersection divided by the length of the shorter interval. If two intervals do not intersect, the ratio is 0. ...
5
votes
1answer
1k views

Segment tree implementation

I'm learning segment trees and their implementation. For the purpose, I tried solving the problem on CodeChef. Full code here My tree implementation is as follows: ...
4
votes
2answers
781 views

Reverse sublists of a linked list

This code reverses each consecutive n elements of a linked list, and for spare nodes, leaves them as they are. For example, the linked list 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 for an interval of 3 ...
9
votes
1answer
200 views

Date range validation

The following code is ran when the user presses a button to generate a log file based on the date selected. The DatePicker has a restrictive selected date range of ...
1
vote
3answers
68 views

Activity by length

I was having a hard time finding out how to make this any faster. I broke down the code that I am playing with into more methods than necessary to try and see where things could increase. Can anyone ...
3
votes
1answer
73 views

Generate [min, max] range from strings

I need to generate a minimum and maximum value for a range of speeds (slow, medium, fast), the user can specify any combination of the 3 values, and receive a range that encompasses all. Given any ...
12
votes
4answers
28k views

Simple Example of an Iterable and an Iterator in Java

I was a TA for a first-year Java programming course this year. As a very simple example of iterables/iterators, I wrote the following code for the students. I am curious if any styling or other ...
10
votes
4answers
2k views

Generate sequence in Linq

I want to generate a sequence using Linq that goes from 10 to 100 with a step size of 10. The sequence also must contain a custom value (in the correct order). This is what I have now, and I'm ...
8
votes
2answers
168 views

Container for list of ranges

I made a C++ container of an ordered list of integers, that, in order to save space, I save as ranges: For example, the list \$ \{1,2,3,5,6,7,8,9,20\} \$ is saved in memory as \$ \{(1,3), (5,9), ...
7
votes
4answers
349 views

Adding intervals to an interval store

Write a program to do addition of intervals to an interval store. An interval is represented by an array of two elements - the lower and the upper bound (you can assume integers). Assume ...