Talk:Rep-string: Difference between revisions

→‎c program: task does mention it.
m (→‎Clarification: amended an earlier statement to say what I meant to say. -- ~~~~)
(→‎c program: task does mention it.)
 
(9 intermediate revisions by 4 users not shown)
Line 30:
 
:::: A task requirement is that the repeat occur two or more times.   One repeat doesn't meet that requirement. -- [[User:Gerard Schildberger|Gerard Schildberger]] ([[User talk:Gerard Schildberger|talk]]) 19:10, 13 May 2013 (UTC)
 
Should this sentence of the task description be changed?
<br>Use the function to indicate the repeating substring if any, in the following:
<br>Use the function to indicate the repeating substrings if any, in the following:
<br>Does '1111' have 1 solution ('11') or 3 ('1', '11', '111')
 
Maybe the expected results could/should be stated.--[[User:Walterpachl|Walterpachl]] ([[User talk:Walterpachl|talk]]) 21:25, 13 May 2013 (UTC)
::I have modified the task to require selection of the longest substring, if more than one is possible, since that's what most of the solutions seem to be assuming. --[[User:TimToady|TimToady]] ([[User talk:TimToady|talk]]) 23:24, 13 May 2013 (UTC)
 
::: Hi TimToady, I widened the requirement to report longest or shortest or all reps as there could be equal argument for those cases but I can't envisage an algorithm returning naturally some arbitrary other set of rep solutions unless that arbitrariness is 'self-injected'. --[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 04:17, 14 May 2013 (UTC)
 
::: '''Substring types''':
:::* longest/shortest/all ( length)
:::* ovelapping/non-overlapping
::: are any others ? --[[User:Adam majewski|Adam majewski]] ([[User talk:Adam majewski|talk]]) 06:53, 28 April 2019 (UTC)
 
==Reason for update request==
Line 46 ⟶ 61:
==Curiouser and curiouser!==
Ledrugs' Python <tt>text.startswith(shifted_text)</tt> is equivalent to TimToadys' Perl 6 boolean shift and XOR. I'll remember that! --[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 19:41, 13 May 2013 (UTC)
 
== c program ==
 
Hi,
C program works great. I have add new example and it failed ( or I'm wrong). The result IMHO should be rep-string "001"
<lang c>
/*
 
https://rosettacode.org/wiki/Rep-string#C
 
*/
#include <stdio.h>
#include <string.h>
int repstr(char *str)
{
if (!str) return 0;
size_t sl = strlen(str) / 2;
while (sl > 0) {
if (strstr(str, str + sl) == str)
return sl;
--sl;
}
return 0;
}
int main(void)
{
// input strings = tests
char *strs[] = {
"1001110011",
"1110111011",
"0010010010",
"1111111111",
"0100101101",
"0100100",
"101",
"11",
"00",
"00100100100100100100100100100100100100100100100100100100100100100100100100100" }; // not works
size_t strslen = sizeof(strs) / sizeof(strs[0]); // number of test values
size_t i;
for (i = 0; i < strslen; ++i) { // check all test values
int n = repstr(strs[i]);
// print result
if (n)
printf("\"%s\" = rep-string \"%.*s\"\n", strs[i], n, strs[i]);
else printf("\"%s\" = not a rep-string\n", strs[i]);
} //
return 0;
}
</lang>
 
{{out}}
<pre>
"1001110011" = rep-string "10011"
"1110111011" = rep-string "1110"
"0010010010" = rep-string "001"
"1111111111" = rep-string "11111"
"0100101101" = not a rep-string
"0100100" = rep-string "010"
"101" = not a rep-string
"11" = rep-string "1"
"00" = rep-string "0"
"00100100100100100100100100100100100100100100100100100100100100100100100100100" = rep-string "001001001001001001001001001001001001"
 
</pre>
 
:When given ten 1's it returns five 1's as the rep-string. Maybe The C function returns the longest rep-string and you expected the shortest? --[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 15:50, 28 April 2019 (UTC)
:: You are right, it gives the longest. I think that it should be explicitly stated. What about splitting C section into the 2 subsections : longest and shortest ? Also example strings IMHO should have strings which give differrent results for longest and shortest test. Does it sounds good ? --[[User:Adam majewski|Adam majewski]] ([[User talk:Adam majewski|talk]]) 16:13, 28 April 2019 (UTC)
 
:::There is already a section in the description on this. --[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 20:26, 29 April 2019 (UTC)
 
== new test values, ==
 
<pre>
{
"1001110011",
"1110111011",
"0010010010", /* 4 x 001 and truncated, lat char can be from 001*/
"00100100101", /* 4 x 001 but last 2 chars are NOT from 001 */
"1111111111",
"0100101101",
"0100100",
"101",
"11",
"00",
"00100100100100100100100100100100100100100100100100100100100100100100100100100"
};
</pre>
Anonymous user