Rep-string: Difference between revisions
Content added Content deleted
(→{{header|Vlang}}: Rename "Vlang" in "V (Vlang)") |
Not a robot (talk | contribs) (Add Miranda) |
||
Line 2,490: | Line 2,490: | ||
It outputs all the possibilities for a rep-string, |
It outputs all the possibilities for a rep-string, |
||
if there is no rep-string it will show an empty list {}. |
if there is no rep-string it will show an empty list {}. |
||
=={{header|Miranda}}== |
|||
<syntaxhighlight lang="miranda">main :: [sys_message] |
|||
main = [Stdout (lay (map test tests))] |
|||
test :: [char]->[char] |
|||
test s = s ++ ": " ++ show (repstrings s) |
|||
tests :: [[char]] |
|||
tests = ["1001110011", "1110111011", "0010010010", "1010101010", |
|||
"1111111111", "0100101101", "0100100", "101", "11", "00", |
|||
"1"] |
|||
repstrings :: [*]->[[*]] |
|||
repstrings s = filter matching bases |
|||
where bases = [take n s | n<-[1..#s div 2]] |
|||
matching r = s = take (#s) (concat (repeat r))</syntaxhighlight> |
|||
{{out}} |
|||
<pre>1001110011: ["10011"] |
|||
1110111011: ["1110"] |
|||
0010010010: ["001"] |
|||
1010101010: ["10","1010"] |
|||
1111111111: ["1","11","111","1111","11111"] |
|||
0100101101: [] |
|||
0100100: ["010"] |
|||
101: [] |
|||
11: ["1"] |
|||
00: ["0"] |
|||
1: []</pre> |
|||
=={{header|Modula-2}}== |
=={{header|Modula-2}}== |