Hello,
I need some help programming. what I am expected to do is as follows:
I need to write a method: "int SeqCount (int[], arr, int n)
That counts sequences of the same type of length (n) in an array of
ints that form a rising or falling sequences with difference of 1
between them. for example
if n=3 then from the array : "1 2 3 6 9 9 8 3 2 1" the result will be 2
(1,2,3 and 3 2 1)
Lasse Reichstein Nielsen - 08 Apr 2006 13:52 GMT
> I need some help programming. what I am expected to do is as follows:
> I need to write a method: "int SeqCount (int[], arr, int n)
[quoted text clipped - 4 lines]
> if n=3 then from the array : "1 2 3 6 9 9 8 3 2 1" the result will be 2
> (1,2,3 and 3 2 1)
Is this homework? What have you done so far?
Should overlapping sequences count, or only distinct? (i.e., if n=2
is [1,2,3] one or two sequences?)
I believe you can do this with one sweep of the array, remembering the
length of the sequence up to the current position, the direction and
the previous number.
Good luck
/L

Signature
Lasse Reichstein Nielsen - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Rhino - 08 Apr 2006 14:02 GMT
> Hello,
>
[quoted text clipped - 6 lines]
> if n=3 then from the array : "1 2 3 6 9 9 8 3 2 1" the result will be 2
> (1,2,3 and 3 2 1)
This sounds like a homework question to me. We usually handle those at
comp.lang.java.help. However, we don't normally give people complete
solutions to homework questions there either: _if_ we see the student's own
code and it shows a genuine effort to solve the problem, we will give
_hints_ to help them get past whatever difficulties they are having. The
comp.lang.java.help newsgroup is _not_ a homework completion service where
you drop off your questions and then come back to collect complete programs
a few hours later.
--
Rhino
Monique Y. Mudama - 08 Apr 2006 16:30 GMT
> Hello,
>
[quoted text clipped - 6 lines]
> if n=3 then from the array : "1 2 3 6 9 9 8 3 2 1" the result will
> be 2 (1,2,3 and 3 2 1)
Post whatever code you've come up with and ask a specific question
about it.

Signature
monique
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html
Alex Hunsley - 08 Apr 2006 17:09 GMT
> Hello,
>
> I need some help programming. what I am expected to do is as follows:
Yes, exactly: what _you_ are expected to do. We are not you.
We can help with specifiec problems, but at least look like you've made
an attempt to start the thing.
This ain't a homework delegation service.
Roedy Green - 08 Apr 2006 19:19 GMT
>I need some help programming. what I am expected to do is as follows:
>I need to write a method: "int SeqCount (int[], arr, int n)
[quoted text clipped - 4 lines]
>if n=3 then from the array : "1 2 3 6 9 9 8 3 2 1" the result will be 2
>(1,2,3 and 3 2 1)
try giving yourself a graded series of problems to solve. After you
have solved each one , the next will be easier.
e.g.
0. compare to umbers and decide is we are going up or down or flat.
1. find the length of the first sequence, even if it is just 1.
2. find the length of the first sequence longer than 3.
3. find the length of all the sequences and print them out.
4. count how many sequences there were altogether.
5. count how many sequences there were of each possible length.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.