Rep-string: Difference between revisions
Added Quackery.
(Added PL/M) |
(Added Quackery.) |
||
Line 3,290:
===Python: find===
See [https://stackoverflow.com/questions/29481088/how-can-i-tell-if-a-string-repeats-itself-in-python/29489919#29489919 David Zhang's solution] to the same question posed on Stack Overflow.
=={{header|Quackery}}==
<code>factors</code> is defined at [http://rosettacode.org/wiki/Factors_of_an_integer#Quackery Factors of an integer].
<lang Quackery> [ [] temp put
false swap
dup size 2 < iff
swap done
dup size factors
-1 split drop
witheach
[ 2dup split drop
dip [ over size swap / ]
dup temp replace
swap of over = if
[ drop not
temp share
conclude ] ]
swap temp release ] is rep$ ( $ --> $ b )
[ dup rep$ iff
[ say 'The shortest rep-string in "'
swap echo$
say '" is "' echo$
say '".' ]
else
[ say 'There is no rep-string for "'
nip echo$ say '".' ]
cr ] is task ( $ --> )
$ "1001110011 1110111011 0010010010
1010101010 1111111111 0100101101
0100100 101 11 00 1"
nest$ witheach task</lang>
{{out}}
<pre>The shortest rep-string in "1001110011" is "10011".
There is no rep-string for "1110111011".
There is no rep-string for "0010010010".
The shortest rep-string in "1010101010" is "10".
The shortest rep-string in "1111111111" is "1".
There is no rep-string for "0100101101".
There is no rep-string for "0100100".
There is no rep-string for "101".
The shortest rep-string in "11" is "1".
The shortest rep-string in "00" is "0".
There is no rep-string for "1".</pre>
=={{header|Racket}}==
|