i'm looking for a way to extend a list of 2 elements that represent boundaries, to the entire range.
for example: input list = [1 ,5,10,15]
output list would be = [1, 2, 3, 4 ,5 , 10 , 11 , 12 ,13 ,14 ,15]
i can make it using the following semi-pseudo code, but perhaps there is an easier way, more elegant... - $i = 0;
-
while $i != length(list)
-
for ($j = list($i); j++; j<list($i+1)) {
-
push(@out_list,$j);
-
};
-
$i += 2;
-
};
1 1081
i'm looking for a way to extend a list of 2 elements that represent boundaries, to the entire range.
for example: input list = [1 ,5,10,15]
output list would be = [1, 2, 3, 4 ,5 , 10 , 11 , 12 ,13 ,14 ,15]
i can make it using the following semi-pseudo code, but perhaps there is an easier way, more elegant...
$i = 0;
while $i != length(list)
for ($j = list($i); j++; j<list($i+1)) {
push(@out_list,$j);
};
$i += 2;
};
Though logic remains the same, you may reduce the number of lines of code by using this: -
for($i=0;$i<@list;$i+=2) {
-
push @out_list,($list[$i]..$list[$i+1]);
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Matthew Wilson |
last post by:
I have a list of very simple circle objects:
class Circle:
def __init__(self, x,y,r):
self.center =(x,y)
self.r = r
I want to write a function that accepts a list of circle objects and
then...
|
by: Jim Cobban |
last post by:
I cannot get Netscape 4.79 to properly display the ordered list in the
following fragment.
<P>Get a specific portion of the date.
Depending upon the value of index:
<ol start=0>
<li>complete...
|
by: Jeff |
last post by:
Hello,
I'm finishing a speech recognition jukebox
(http://intelligentjukebox.com/) I have a very basic template
question. I can't find any good examples of what I want to do. I
could write...
|
by: Arne Claus |
last post by:
Hi
If've just read, that remove() on a list does not actually remove the
elements, but places them at the end of the list (according to TC++STL
by Josuttis). It also says, that remove returns a...
|
by: greenflame |
last post by:
I am trying to reorder elements of a list and I am stuck as to what
might be the best way to approach this. I have a (main) list of
elements and another (ordering) list (which is may shorter, but...
|
by: Amit Bhatia |
last post by:
Hi,
I am not sure if this belongs to this group. Anyway, my question is as
follows: I have a list (STL list) whose elements are pairs of integers (STL
pairs, say objects of class T). When I create...
|
by: Amar |
last post by:
Hi,
I have a generic list with a some objects of a particular class in it.
I have implemented a IComparer for the the class and pass it to the
List.
The list.sort method works fine when the value...
|
by: Tony Johansson |
last post by:
Hello!
Sorry for opening up this task again.
I want to fully understand this List that is return from CollectionBase.
According to you is List in CollectionBase implemented something like...
|
by: Juha Nieminen |
last post by:
Assume we have this:
std::list<Typelist1(10, 1), list2(20, 2);
std::list<Type>::iterator iter = list1.end();
list1.swap(list2);
What happens here, according to the standard?
1) 'iter'...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |