Hi All, I am looking for a smart solution to accomplish this task (.net 1.0)
Appreciate your input
I have a group of numbers in an arrayList
2,3,5,2,1,2,2
I need to output them into groups of
2,3,5
2
1
2
2
basically whenever I encounter 1 or 2 I bundle them up..
The numbers are in an arrayList, and I output them as string []
Arraylist Bundle(Arraylist)
{
// arr1 will contain (2,3,5)
alReturn.Add(arr1);
...................
return alReturn
}
TIA 6 1123
So whenever you get a 2 or a 1 you start a new bundle?
Just if statement it then a bit like this, very rough code:
foreach(int i in arr1)
{
if ( i>0 && i <= 2)
{
//check string array if its empty make a new one
//if it isnt add it to array and start new one
//add 1 or 2 to string array
}
else
{
//concat to string array all numbers after 1 or 2
}
}
return completeStringArray;
"Vai2000" <no****@microsoft.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hi All, I am looking for a smart solution to accomplish this task (.net
1.0)
Appreciate your input
I have a group of numbers in an arrayList
2,3,5,2,1,2,2
I need to output them into groups of
2,3,5
2
1
2
2
basically whenever I encounter 1 or 2 I bundle them up..
The numbers are in an arrayList, and I output them as string []
Arraylist Bundle(Arraylist)
{
// arr1 will contain (2,3,5)
alReturn.Add(arr1);
..................
return alReturn
}
TIA
Two approaches here, the first returns an arraylist of the starting
points of each segment, and the second returns an arraylist of
arraylists containing each segment.
private void button1_Click(object sender, System.EventArgs e)
{
ArrayList a = new ArrayList();
int[] i = new int[] {2,3,5,2,1,2,2,3};
a.AddRange(i);
ArrayList b = DoIt2(a);
ArrayList c = DoIt(a);
Console.WriteLine(".");
}
private ArrayList DoIt(ArrayList pList)
{
ArrayList a = new ArrayList();
for(int c=0;c<pList.Count;c++)
{
if(1 == (int)pList[c] || 2 == (int)pList[c])
{
a.Add(c);
}
}
return a;
}
private ArrayList DoIt2(ArrayList pList)
{
ArrayList a = new ArrayList();
ArrayList b = null;
for(int c=0;c<pList.Count;c++)
{
if(1 == (int)pList[c] || 2 == (int)pList[c])
{
if(null == b)
{
b = new ArrayList();
}
else
{
b = new ArrayList();
}
a.Add(b);
}
b.Add(pList[c]);
}
return a;
}
On 29 Jan, 16:12, "Vai2000" <nos...@microsoft.comwrote:
Hi All, I am looking for a smart solution to accomplish this task (.net 1.0)
Appreciate your input
I have a group of numbers in an arrayList
2,3,5,2,1,2,2
I need to output them into groups of
2,3,5
2
1
2
2
basically whenever I encounter 1 or 2 I bundle them up..
The numbers are in an arrayList, and I output them as string []
Arraylist Bundle(Arraylist)
{
// arr1 will contain (2,3,5)
alReturn.Add(arr1);
..................
return alReturn
}TIA
And here's the version without all the spurious extra code :)
private ArrayList DoIt2(ArrayList pList)
{
ArrayList a = new ArrayList();
ArrayList b = null;
for(int c=0;c<pList.Count;c++)
{
if(1 == (int)pList[c] || 2 == (int)pList[c])
{
b = new ArrayList();
a.Add(b);
}
b.Add(pList[c]);
}
return a;
}
On 29 Jan, 16:49, "DeveloperX" <nntp...@operamail.comwrote:
Two approaches here, the first returns an arraylist of the starting
points of each segment, and the second returns an arraylist of
arraylists containing each segment.
private void button1_Click(object sender, System.EventArgs e)
{
ArrayList a = new ArrayList();
int[] i = new int[] {2,3,5,2,1,2,2,3};
a.AddRange(i);
ArrayList b = DoIt2(a);
ArrayList c = DoIt(a);
Console.WriteLine(".");}private ArrayList DoIt(ArrayList pList)
{
ArrayList a = new ArrayList();
for(int c=0;c<pList.Count;c++)
{
if(1 == (int)pList[c] || 2 == (int)pList[c])
{
a.Add(c);
}
}
return a;}private ArrayList DoIt2(ArrayList pList)
{
ArrayList a = new ArrayList();
ArrayList b = null;
for(int c=0;c<pList.Count;c++)
{
if(1 == (int)pList[c] || 2 == (int)pList[c])
{
if(null == b)
{
b = new ArrayList();
}
else
{
b = new ArrayList();
}
a.Add(b);
}
b.Add(pList[c]);
}
return a;
}On 29 Jan, 16:12, "Vai2000" <nos...@microsoft.comwrote:
Hi All, I am looking for a smart solution to accomplish this task (.net 1.0)
Appreciate your input
I have a group of numbers in an arrayList
2,3,5,2,1,2,2
I need to output them into groups of
2,3,5
2
1
2
2
basically whenever I encounter 1 or 2 I bundle them up..
The numbers are in an arrayList, and I output them as string []
Arraylist Bundle(Arraylist)
{
// arr1 will contain (2,3,5)
alReturn.Add(arr1);
..................
return alReturn
}TIA- Hide quoted text -- Show quoted text -
Anyone that names their method "DoIt" deserves respect.
"DeveloperX" <nn*****@operamail.comwrote in message
news:11**********************@a34g2000cwb.googlegr oups.com...
And here's the version without all the spurious extra code :)
private ArrayList DoIt2(ArrayList pList)
{
ArrayList a = new ArrayList();
ArrayList b = null;
for(int c=0;c<pList.Count;c++)
{
if(1 == (int)pList[c] || 2 == (int)pList[c])
{
b = new ArrayList();
a.Add(b);
}
b.Add(pList[c]);
}
return a;
}
On 29 Jan, 16:49, "DeveloperX" <nntp...@operamail.comwrote:
>Two approaches here, the first returns an arraylist of the starting points of each segment, and the second returns an arraylist of arraylists containing each segment.
private void button1_Click(object sender, System.EventArgs e) { ArrayList a = new ArrayList();
int[] i = new int[] {2,3,5,2,1,2,2,3}; a.AddRange(i); ArrayList b = DoIt2(a); ArrayList c = DoIt(a); Console.WriteLine(".");}private ArrayList DoIt(ArrayList pList) { ArrayList a = new ArrayList(); for(int c=0;c<pList.Count;c++) { if(1 == (int)pList[c] || 2 == (int)pList[c]) { a.Add(c); } } return a;}private ArrayList DoIt2(ArrayList pList) { ArrayList a = new ArrayList(); ArrayList b = null; for(int c=0;c<pList.Count;c++) { if(1 == (int)pList[c] || 2 == (int)pList[c]) { if(null == b) { b = new ArrayList(); } else { b = new ArrayList(); } a.Add(b); } b.Add(pList[c]); } return a;
}On 29 Jan, 16:12, "Vai2000" <nos...@microsoft.comwrote:
Hi All, I am looking for a smart solution to accomplish this task (.net
1.0)
Appreciate your input
I have a group of numbers in an arrayList
2,3,5,2,1,2,2
I need to output them into groups of
2,3,5
2
1
2
2
basically whenever I encounter 1 or 2 I bundle them up..
The numbers are in an arrayList, and I output them as string []
Arraylist Bundle(Arraylist)
{
// arr1 will contain (2,3,5)
alReturn.Add(arr1);
..................
return alReturn
}TIA- Hide quoted text -- Show quoted text -
Sorry to discourage....but all the answers are spurious...!
Input ArrayList:
2,3,4,20
1,2,2
2
2,2,2
1,2,3,4
1,1
null
expected oututs
Bundle Count=1 and the bundle will contain 2,3,4,20
Bundle Count=3 Bundle#1 wil contain 1 Bundle#2 will contain 2 and Bundle#3
will cotain 2
Bundle Count=1 Bundle#1 will contain 2
Bundle Count=3 Bundle#1 wil contain 2 Bundle#2 will contain 2 and Bundle#3
will cotain 2
Bundle Count=2 Bundle#1 wil contain 1 Bundle#2 will contain 2 ,3,4
{formatted with,}
Bundle Count =2 Bundle#1 wil contain 1 Bundle#2 will contain 1
Null
............
"Daniel" <no****@pokercat.co.ukwrote in message
news:OH**************@TK2MSFTNGP04.phx.gbl...
Anyone that names their method "DoIt" deserves respect.
"DeveloperX" <nn*****@operamail.comwrote in message
news:11**********************@a34g2000cwb.googlegr oups.com...
And here's the version without all the spurious extra code :)
private ArrayList DoIt2(ArrayList pList)
{
ArrayList a = new ArrayList();
ArrayList b = null;
for(int c=0;c<pList.Count;c++)
{
if(1 == (int)pList[c] || 2 == (int)pList[c])
{
b = new ArrayList();
a.Add(b);
}
b.Add(pList[c]);
}
return a;
}
On 29 Jan, 16:49, "DeveloperX" <nntp...@operamail.comwrote:
Two approaches here, the first returns an arraylist of the starting
points of each segment, and the second returns an arraylist of
arraylists containing each segment.
private void button1_Click(object sender, System.EventArgs e)
{
ArrayList a = new ArrayList();
int[] i = new int[] {2,3,5,2,1,2,2,3};
a.AddRange(i);
ArrayList b = DoIt2(a);
ArrayList c = DoIt(a);
Console.WriteLine(".");}private ArrayList DoIt(ArrayList pList)
{
ArrayList a = new ArrayList();
for(int c=0;c<pList.Count;c++)
{
if(1 == (int)pList[c] || 2 == (int)pList[c])
{
a.Add(c);
}
}
return a;}private ArrayList DoIt2(ArrayList pList)
{
ArrayList a = new ArrayList();
ArrayList b = null;
for(int c=0;c<pList.Count;c++)
{
if(1 == (int)pList[c] || 2 == (int)pList[c])
{
if(null == b)
{
b = new ArrayList();
}
else
{
b = new ArrayList();
}
a.Add(b);
}
b.Add(pList[c]);
}
return a;
}On 29 Jan, 16:12, "Vai2000" <nos...@microsoft.comwrote:
Hi All, I am looking for a smart solution to accomplish this task
(.net
1.0)
Appreciate your input
I have a group of numbers in an arrayList
2,3,5,2,1,2,2
I need to output them into groups of
2,3,5
2
1
2
2
basically whenever I encounter 1 or 2 I bundle them up..
The numbers are in an arrayList, and I output them as string []
Arraylist Bundle(Arraylist)
{
// arr1 will contain (2,3,5)
alReturn.Add(arr1);
..................
return alReturn
}TIA- Hide quoted text -- Show quoted text -
I also have JustDoIt for when it's really time critical ;)
@Vai, I tested it with your set and a couple of others and it worked
as expected. I did make a few assumptions like your string would start
with a 1 or 2. Sorry it didn't help.
On 29 Jan, 17:00, "Daniel" <nos...@pokercat.co.ukwrote:
Anyone that names their method "DoIt" deserves respect.
"DeveloperX" <nntp...@operamail.comwrote in messagenews:11**********************@a34g2000cwb.g ooglegroups.com...
And here's the version without all the spurious extra code :)
private ArrayList DoIt2(ArrayList pList)
{
ArrayList a = new ArrayList();
ArrayList b = null;
for(int c=0;c<pList.Count;c++)
{
if(1 == (int)pList[c] || 2 == (int)pList[c])
{
b = new ArrayList();
a.Add(b);
}
b.Add(pList[c]);
}
return a;
}
On 29 Jan, 16:49, "DeveloperX" <nntp...@operamail.comwrote:
Two approaches here, the first returns an arraylist of the starting
points of each segment, and the second returns an arraylist of
arraylists containing each segment.
private void button1_Click(object sender, System.EventArgs e)
{
ArrayList a = new ArrayList();
int[] i = new int[] {2,3,5,2,1,2,2,3};
a.AddRange(i);
ArrayList b = DoIt2(a);
ArrayList c = DoIt(a);
Console.WriteLine(".");}private ArrayList DoIt(ArrayList pList)
{
ArrayList a = new ArrayList();
for(int c=0;c<pList.Count;c++)
{
if(1 == (int)pList[c] || 2 == (int)pList[c])
{
a.Add(c);
}
}
return a;}private ArrayList DoIt2(ArrayList pList)
{
ArrayList a = new ArrayList();
ArrayList b = null;
for(int c=0;c<pList.Count;c++)
{
if(1 == (int)pList[c] || 2 == (int)pList[c])
{
if(null == b)
{
b = new ArrayList();
}
else
{
b = new ArrayList();
}
a.Add(b);
}
b.Add(pList[c]);
}
return a;
}On 29 Jan, 16:12, "Vai2000" <nos...@microsoft.comwrote:
Hi All, I am looking for a smart solution to accomplish this task (.net
1.0)
Appreciate your input
I have a group of numbers in an arrayList
2,3,5,2,1,2,2
I need to output them into groups of
2,3,5
2
1
2
2
basically whenever I encounter 1 or 2 I bundle them up..
The numbers are in an arrayList, and I output them as string []
Arraylist Bundle(Arraylist)
{
// arr1 will contain (2,3,5)
alReturn.Add(arr1);
..................
return alReturn
}TIA- Hide quoted text -- Show quoted text -
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dave Benjamin |
last post by:
Hey all,
I just realized you can very easily implement a sequence grouping function
using Python 2.3's fancy slicing support:
def group(values, size):
return map(None, * for i in...
|
by: Jerry Sievers |
last post by:
Fellow Pythonists;
I am totally puzzled on the use of slicing on mapping types and
especially unsure on use of the Ellipsis... and slicing syntax that
has two or more groups seperated by comma....
|
by: Bryan Olson |
last post by:
I recently wrote a module supporting value-shared slicing. I
don't know if this functionality already existed somewhere, but
I think it's useful enough that other Pythoners might want it,
so here...
|
by: jbperez808 |
last post by:
>>> rs='AUGCUAGACGUGGAGUAG'
>>> rs='GAG'
Traceback (most recent call last):
File "<pyshell#119>", line 1, in ?
rs='GAG'
TypeError: object doesn't support slice assignment
You can't assign to...
|
by: Jon Slaughter |
last post by:
I'm having a little trouble understanding what the slicing problem is.
In B.S.'s C++ PL3rdEd he says
"Becayse the Employee copy functions do not know anything about Managers,
only the Employee...
| |
by: baibaichen |
last post by:
i have written some code to verify how to disable slicing copy
according C++ Gotchas item 30
the follow is my class hierarchy, and note that B is abstract class!!
class B
{
public:
explicit...
|
by: Vai2000 |
last post by:
Hi All, I need some smart way to accomplish this task in C# (.net 1.0)
Appreciate your inputs!!
==================================
Input ArrayList:
2,3,4,20
1,2,2
2
2,2,2
1,2,3,4
|
by: Bart Simpson |
last post by:
Can anyone explain the concept of "slicing" with respect to the "virtual
constructor" idiom as explain at parashift ?
From parashift:
class Shape {
public:
virtual ~Shape() { } ...
|
by: Rahul |
last post by:
Hi Everyone,
I was working around object slicing (pass by value) and was
wondering how it is specified in the standard,
class A
{
};
class B: public A
|
by: subramanian100in |
last post by:
Consider
class Base
{
....
};
class Derived : public Base
{
...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |