Golang Problems

161 views
Skip to first unread message

Vignesh Kumar

unread,
Feb 27, 2021, 10:02:37 PM2/27/21
to golang-nuts
Hello all, 

Thanks in advance. Please help me to finish this assignments. 

Write a program which will accept a string. This program should output all the characters and number of their occurrences, in order of their occurrences. So that, character appearing most number of times should be printed first and characters appearing least number of times (i.e. 1 time) should appear at the last. Capital and small characters should be considered as same. Only spaces in the input string should not be counted.

Example: Input string is "Hello there", it should output: e: 3, h: 2, l: 2, o:1, i: 1, t : 1, r: 1 *



Kurtis Rader

unread,
Feb 27, 2021, 10:07:50 PM2/27/21
to Vignesh Kumar, golang-nuts
This mailing list is not your free resource for doing homework on your behalf. For $10_000 USD I will provide a solution. Otherwise, please go away and ponder if employment as a ditch digger isn't better suited to your skills.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b608f1a5-d833-4bf1-b954-61598e30f808n%40googlegroups.com.


--
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

peterGo

unread,
Feb 27, 2021, 10:20:19 PM2/27/21
to golang-nuts
On Saturday, February 27, 2021 at 10:07:50 PM UTC-5 Kurtis Rader wrote:
This mailing list is not your free resource for doing homework on your behalf. For $10_000 USD I will provide a solution. Otherwise, please go away and ponder if employment as a ditch digger isn't better suited to your skills.


Kurtis,

There is no need to be nasty about it. This forum has a code of conduct.

Please follow the Go Community Code of Conduct while posting here. In short:
  • Treat everyone with respect and kindness.
  • Be thoughtful in how you communicate.
  • Don’t be destructive or inflammatory.
 
Peter

Marcin Romaszewicz

unread,
Feb 28, 2021, 12:32:36 AM2/28/21
to Vignesh Kumar, golang-nuts
We're not going to do your homework for you, but some things to consider:

- maps are good at associating values with names
- there's a strings.ToLower() function you will find useful
- sort.Ints sorts ints in ascending order
- if s is a string, s[0] is a rune
- if r is a rune, string(r) is a 1 character string

These are bits of Go that you will find helpful in solving your assignment.

On Sat, Feb 27, 2021 at 7:02 PM Vignesh Kumar <vines...@gmail.com> wrote:

Jan Mercl

unread,
Feb 28, 2021, 2:29:20 AM2/28/21
to Marcin Romaszewicz, Vignesh Kumar, golang-nuts
On Sun, Feb 28, 2021 at 6:32 AM Marcin Romaszewicz <mar...@gmail.com> wrote:

> - if s is a string, s[0] is a rune

If s is a non-empty string, s[0] is a byte.

> - if r is a rune, string(r) is a 1 character string

If r is a rune, string(r) is a string of 1 or more bytes.

Jesper Louis Andersen

unread,
Feb 28, 2021, 9:12:29 AM2/28/21
to Vignesh Kumar, golang-nuts
You've stated the assignment.

What have you tried in order to solve it?

The best way to get at this is to just jump out in it and start trying stuff and see when it fails. Don't be afraid of stuff falling apart in the beginning. That's not what you are going to hand in, anyway. In addition, we don't know if you are expected to use all of the language, or only parts of the language to solve it. If you haven't gotten to, say, maps yet, and we suggest solutions using maps, that isn't going to help you a lot. Another thing is if you are allowed to use library functions, and which you are allowed to use, because some of them trivializes parts of the assignment.

We can give far better support to your problem if you try doing part of it yourself, because you will have some concrete questions about the whole thing then.

There's some simpler variants of the full assignment you can also try first:

1. Build a system which accepts a string and returns the length of the string. This will set up the necessary scaffold for the later versions of the program.
2. Build a function which traverses through the string, one rune[0] at a time, and then counts every non-space character in the string.
3. Build a function which counts occurrences of  characters, but doesn't care about the order in which they are reported.
3.5. Handle capitalization.
4. Build a function which can sort an unordered set of occurrences, or use a library function.

This will successively get you closer and closer to the target, by introducing small parts of the whole one thing at a time.

[0] One important thing is what the possible input for the strings are. Or said more formally: what's the alphabet looking like? If you only ever expect ASCII characters, the problem is far simpler to solve than if you want to handle full unicode. Especially because you want to care about capitalization---there are languages out there where capitalization isn't as clear cut as one might think. The same goes for "what is a space?". Unicode contains several code points that could be considered spaces.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b608f1a5-d833-4bf1-b954-61598e30f808n%40googlegroups.com.


--
J.
Reply all
Reply to author
Forward
0 new messages