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!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Prompt algorithm

 
petr pavlovich
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Input file:

output file:
duplicate lines, indicating the number of repetitions
what algorithm?
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12097
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
clearly you know the algorithm...you generated the output in your post.

How did you figure out that this:

bbb -3
aaa - 2

goes in your output file?
 
petr pavlovich
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

goes in your output file?

??? I have not understood You(
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How did you mentally come up with that output?
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12097
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

((((((
Console
 
Paul Clapham
Sheriff
Pie
Posts: 20945
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't need to change anyTypeArray (below) as you scan
through it (add, delete, etc.), a further improved version is:
Jim ... ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic