Jump to content

Factorize string into Lyndon words: Difference between revisions

julia example
imported>CosmiaNebula
mNo edit summary
(julia example)
Line 141:
001
</pre>
 
=={{header|Julia}}==
{{trans|Phix}}{{trans|Python}}
<syntaxhighlight lang="Julia">function chenfoxlyndonfactorization(s)
n = length(s)
i = 1
factorization = String[]
while i <= n
j = i + 1
k = i
while j <= n && s[k] <= s[j]
if s[k] < s[j]
k = i
else
k += 1
end
j += 1
end
while i <= k
push!(factorization, s[i:i+j-k-1])
i += j - k
end
end
@assert s == prod(factorization)
return factorization
end
 
let m = "0"
for i in 1:7
m0 = m
m = replace(m, '0' => 'a')
m = replace(m, '1' => '0')
m = replace(m, 'a' => '1')
m = m0 * m
end
println(chenfoxlyndonfactorization(m))
end
</syntaxhighlight>{{out}}
<pre>
["011", "01", "0011", "00101101", "0010110011010011", "00101100110100101101001100101101", "001011001101001011010011001011001101001100101101", "001011001101", "001"]
</pre>
 
 
=={{header|MATLAB}}==
4,111

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.