This week's book giveaway is in the Design forum.We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!

# Prompt algorithm

petr pavlovich
Greenhorn
Posts: 22
Input file:

output file:
duplicate lines, indicating the number of repetitions
what algorithm?

fred rosenberger
lowercase baba
Bartender
Posts: 12097
30
clearly you know the algorithm...you generated the output in your post.

How did you figure out that this:

bbb -3
aaa - 2

petr pavlovich
Greenhorn
Posts: 22
fred rosenberger wrote:clearly you know the algorithm...you generated the output in your post.

How did you figure out that this:

bbb -3
aaa - 2

??? I have not understood You(

Wouter Oet
Saloon Keeper
Posts: 2700
How did you mentally come up with that output?

fred rosenberger
lowercase baba
Bartender
Posts: 12097
30
In your original post, you gave us the input:

ddd
bbb
ccc
aaa
bbb
aaa
bbb

SOMEHOW, you were able to then say
"I want my program to output this:
bbb -3
aaa - 2

You used your own brain to figure out what that output should be. How did you do it in your head?

I am 100% serious in saying you should write down the steps you used in your head. make them simple and clear. When you've done that, go back and refine them to be more specific. You can't say "I counted the number of times bbb occurred", because I would come back with "How did you know to count 'bbb'? Once you knew you needed to count those, how did you count them?"

petr pavlovich
Greenhorn
Posts: 22

((((((
Console

Paul Clapham
Sheriff
Posts: 20945
31
The standard Java idiom for iterating through the elements of an array is this:

Whereas you have this:

See the difference? You are iterating one time too many.>

Jim Hoglund
Ranch Hand
Posts: 525
If you don't need to change anyTypeArray (below) as you scan
through it (add, delete, etc.), a further improved version is:
Jim ... ...