[Pascal] Counting letters in a row without arrays

Click For Summary

Discussion Overview

The discussion revolves around a programming exercise that requires counting consecutive letters in a word and identifying the most repeated letter in a row without using arrays, strings, or subfunctions. Participants explore various approaches to solve this problem while adhering to the constraints set by the exercise.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant suggests defining an unknown number of char variables and using a while loop to enter characters until a return is pressed, but struggles with how to manage the input without arrays.
  • Another participant points out that processing the input incrementally could allow for immediate output after certain conditions are met, rather than waiting for all input to be entered.
  • A participant emphasizes the requirement to enter the entire sequence before receiving any output, questioning the feasibility of processing input in real-time.
  • One participant hints at the potential use of recursion as a solution, although it is unclear if others are familiar with this concept.

Areas of Agreement / Disagreement

Participants express differing views on whether the program should process input incrementally or wait until all input is received before providing output. There is no consensus on the best approach to take given the constraints of the exercise.

Contextual Notes

Participants are working under specific constraints that prohibit the use of arrays and strings, which complicates their ability to manage input effectively. The discussion reflects various interpretations of how to adhere to these limitations while still achieving the desired outcome.

trash
Messages
13
Reaction score
0
I'm working with this exercise: make a program that gives the number of consecutive letters of a word and the most repeated letter in a row -example: if i enter aaafdseergftth and i press return the program should return a = 3, e=2, t=2 and a=3-.

I've come up with a couple of "solutions", like define a string and then use an array to get the characters and compare then with a while loop, but here's the issue: i can't use arrays, string, sunbfunctions to solve this excersise, and explicitely says i have to look for another solution.

Now here is my second idea without using strings or arrays: Define an unknown amounts of char variables and enter each one until Intro is entered with a while loop like While not (Eoln) do (...). And that's the only thing i can come up right now to solve it, but when i was looking for a way to define an unknown amount of variables i found nothing but a solution with an array that i should resize to enter new variables.

The next attempt: i defined tree variables char and one int. Then i defined a While Not (Eoln) that checks every letter entered and compare it with the one before, that would almost solve the exercise. The issue is that every time i enter a letter the while loop will be triggered, then after the loop -after i enter return- i could only print the character of the last of consecutive row of letters -the while is needed because i want the result after i entered all the letters-. If i try with the example above i get: t = 2.

Any ideas?
 
Technology news on Phys.org
trash said:
The next attempt: i defined tree variables char and one int. Then i defined a While Not (Eoln) that checks every letter entered and compare it with the one before, that would almost solve the exercise.

That's a good idea.

The issue is that every time i enter a letter the while loop will be triggered, then after the loop -after i enter return- i could only print the character of the last of consecutive row of letters

When you have processed the first 4 characters "aaaf", you know enough to print out "a = 3". You don't have to process the whole string before you print out something.
 
AlephZero said:
When you have processed the first 4 characters "aaaf", you know enough to print out "a = 3". You don't have to process the whole string before you print out something.
Thanks for answring AlephZero.
I have to enter the whole thing before i get the answer, that's what the exercise ask for.

If i don't process the whole thing wouldn't it go like this?
[Enter a]
Nothing happens
[Enter a]
Nothing happens
[Enter a]
Nothing happens
[Enter f]
prints a=3

I would like something like:
[Enter a]
[Enter a]
[Enter a]
[Enter b]
[Enter b]
[Enter f]
[Enter Return]
prints a=3, b=2
 
trash said:
I have to enter the whole thing before i get the answer, that's what the exercise ask for.

Hint: Can you use or have you been introduced to "recursion" yet?

If not then ignore this.
 

Similar threads

Replies
5
Views
2K
  • · Replies 66 ·
3
Replies
66
Views
6K
  • · Replies 23 ·
Replies
23
Views
2K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 36 ·
2
Replies
36
Views
5K
Replies
1
Views
8K