Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Perfect Shuffle
- function ps(x::Array{<:Any, 1}) # perform a single perfect Shuffle
- n = length(x) # this should be even
- n2 = div(n, 2)
- z = Array{eltype(x)}(undef, n)
- for i = 1:n2
- j = 2*i
- z[j-1] = x[i]
- z[j] = x[n2+i]
- end
- return z
- end
- function main(x::Array{<:Any, 1}) # perform a series of ps until the original order reappears
- n = 1
- z = ps(x)
- while z != x
- z = ps(z)
- n += 1
- end
- return n
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement