Re: [go-nuts] How to find repeated string?

2020-08-20 Thread 洪嘉鴻
Hello everyone,
I'll try the methods mentioned above.

Thanks for your replying.
Max

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d79952c7-57f8-4bde-9d38-474ced14d08fo%40googlegroups.com.


Re: [go-nuts] How to find repeated string?

2020-08-19 Thread Brian Candler
Here's one way to do adjacent repeats.
https://play.golang.org/p/402UEPtIkfw

But if you don't understand regular expressions, this could be done more 
simply by:

- finding the first occurrence of substr
- advancing the offset to just after the end of the match
- check if substr appears at the new position
- keep repeating until substr cannot be found any more

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/9f51a985-40be-40f1-9259-b4a53d54d6e3o%40googlegroups.com.


Re: [go-nuts] How to find repeated string?

2020-08-19 Thread Bakul Shah
On Aug 19, 2020, at 1:07 AM, 洪嘉鴻  wrote:
> 
> Hello everyone:
> I use golang with Win10. The version of golang which I'm using is go1.15.
> I want to find out the repeated string.
> For example, given a string which is "1134534534534534".
> I want the output string to be "345"
> I've tried to 
> Could anyone help me to solve this problem?

Your problem specification is ambiguous. For example, if you may be able
represent your input string as

...S^N... or 
...T^M... or 
...U...V..U..V..V.. where there are U occurs L times and V occurs K times.
Here S, T, U and V are substrings

Then any of the following possible answers may make sense:
1. S if len(S) > len(any T)
2. T if M > N (T occurs more frequently than any S)
3. U if len(U) > len(any V)
4. V if K > L (V occurs more frequently than any U)

Based on your example it appears you want 2. or 4. but can't be sure.
Specify the problem clearly & completely and the solution will usually
suggest itself!

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/62DA1B47-04CD-4B21-8F32-A0A907983757%40iitbombay.org.


Re: [go-nuts] How to find repeated string?

2020-08-19 Thread Michael Jones
Maybe this way?
https://play.golang.org/p/_OM4RvO83Cf

On Wed, Aug 19, 2020 at 4:04 AM Ian Davis  wrote:

> On Wed, 19 Aug 2020, at 12:02 PM, Ian Davis wrote:
>
>
>
> On Wed, 19 Aug 2020, at 11:54 AM, Brian Candler wrote:
>
> Or another thought - perhaps you are looking for *adjacent* repeats only?
>
> In that case strings.Count doesn't help because it counts all occurrences,
> not just adjacent ones.
>
>
> I suspect the OP is looking for the longest repeating substring.
>
>
> Hmm, that's not correct. Sorry for the noise.
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/bbc89836-e955-45ed-aaa5-f06669128281%40www.fastmail.com
> 
> .
>


-- 

*Michael T. jonesmichael.jo...@gmail.com *

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CALoEmQwHU3trJrnLUFCqo7%2Bq0q8_K1EDsqv3oJ6-nfOP151kFQ%40mail.gmail.com.


Re: [go-nuts] How to find repeated string?

2020-08-19 Thread Ian Davis
On Wed, 19 Aug 2020, at 12:02 PM, Ian Davis wrote:
> 
> 
> On Wed, 19 Aug 2020, at 11:54 AM, Brian Candler wrote:
>> Or another thought - perhaps you are looking for *adjacent* repeats only?
>> 
>> In that case strings.Count doesn't help because it counts all occurrences, 
>> not just adjacent ones.
> 
> I suspect the OP is looking for the longest repeating substring.

Hmm, that's not correct. Sorry for the noise.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/bbc89836-e955-45ed-aaa5-f06669128281%40www.fastmail.com.


Re: [go-nuts] How to find repeated string?

2020-08-19 Thread Ian Davis


On Wed, 19 Aug 2020, at 11:54 AM, Brian Candler wrote:
> Or another thought - perhaps you are looking for *adjacent* repeats only?
> 
> In that case strings.Count doesn't help because it counts all occurrences, 
> not just adjacent ones.

I suspect the OP is looking for the longest repeating substring.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/7de9-dca1-483a-86ca-7695f59dd0f2%40www.fastmail.com.


Re: [go-nuts] How to find repeated string?

2020-08-19 Thread Brian Candler
Or another thought - perhaps you are looking for *adjacent* repeats only?

In that case strings.Count doesn't help because it counts all occurrences, 
not just adjacent ones.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/466d74d0-ab8c-41bc-8622-3412a4229e6bo%40googlegroups.com.


Re: [go-nuts] How to find repeated string?

2020-08-19 Thread Brian Candler
On Wednesday, 19 August 2020 10:41:57 UTC+1, 洪嘉鴻 wrote:
>
> Hello!
> This  is the code which I'm trying.
> The generation of map is the candidates from the string s1.
> However, the answer should be "345", which the count is not the most.
>

Your program says that the string "345" occurs 4 times - which is correct.

However, it also says that there are other sequences which occur more times 
- e.g. "34" occurs 5 times.  And there are longer repeating patterns which 
occur fewer times, e.g. "3453" occurs 2 times.  These are all correct.

So you have to think: what is your reason that "345" should be selected as 
"the best" answer, given that there are other answers which are better in 
terms of number of repeats or length of sequence?

You could create a score which is the length of the string times the number 
of repeats - e.g. "345" length 3 x 4 occurrences = score 12:
https://play.golang.org/p/7npKJ5B5VZR

But then there are non-repeating sequences which score higher.  Do you want 
to exclude sequences with a repeat count of 1 ?
https://play.golang.org/p/_Dg6s4nMOgw

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5f22cd5e-d333-4232-a55b-66616b51926bo%40googlegroups.com.


Re: [go-nuts] How to find repeated string?

2020-08-19 Thread 洪嘉鴻
Hello!
This  is the code which I'm trying.
The generation of map is the candidates from the string s1.
However, the answer should be "345", which the count is not the most.

Thanks for your replying.
Max


Jan Mercl於 2020年8月19日星期三 UTC+8下午4時31分09秒寫道:
>
> On Wed, Aug 19, 2020 at 10:07 AM 洪嘉鴻 > 
> wrote: 
>
> > Hello everyone: 
> > I use golang with Win10. The version of golang which I'm using is 
> go1.15. 
> > I want to find out the repeated string. 
> > For example, given a string which is "1134534534534534". 
> > I want the output string to be "345" 
> > I've tried to 
> > Could anyone help me to solve this problem? 
>
> It would be nice if you can show the code that you wrote in an attempt 
> to solve this problem. Someone may then point out where a mistake was 
> made and/or suggest a better solution. 
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/3da3891b-9bb7-4981-9262-03708aad1d7do%40googlegroups.com.


Re: [go-nuts] How to find repeated string?

2020-08-19 Thread Jan Mercl
On Wed, Aug 19, 2020 at 10:07 AM 洪嘉鴻  wrote:

> Hello everyone:
> I use golang with Win10. The version of golang which I'm using is go1.15.
> I want to find out the repeated string.
> For example, given a string which is "1134534534534534".
> I want the output string to be "345"
> I've tried to
> Could anyone help me to solve this problem?

It would be nice if you can show the code that you wrote in an attempt
to solve this problem. Someone may then point out where a mistake was
made and/or suggest a better solution.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA40n-UrU6o8xbnZNYtTFSHG12Yg8BT68_eEU4C3JoKK4bKCSw%40mail.gmail.com.


[go-nuts] How to find repeated string?

2020-08-19 Thread 洪嘉鴻
Hello everyone:
I use golang with Win10. The version of golang which I'm using is go1.15.
I want to find out the repeated string.
For example, given a string which is "1134534534534534".
I want the output string to be "345"
I've tried to 
Could anyone help me to solve this problem?

Any help is appreciated.
Thank you very much!
Max

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/94f77c6a-10fe-42a1-8ed9-ed63706b30e3o%40googlegroups.com.