using Plots # Parameters n = 40 # must be even t = 1/n a = [sqrt(1 - t^2), -t] b = [-sqrt(1 - t^2), -t] c = [0.0, 1.0] # Construct the multiset vectors = vcat(fill(a, n÷2), fill(b, n÷2), [c]) # ------------------------------------------------------------------ # Choose an ordering by specifying the indices. # # Example 1: all a's, then c, then all b's # perm = vcat(1:n÷2, n+1, n÷2+1:n) # Example 2: alternate a,b, then c perm = vcat(Iterators.flatten([(i, n÷2+i) for i in 1:n÷2])..., n+1) # Example 3: random # perm = randperm(length(vectors)) # ------------------------------------------------------------------ S = zeros(2) pts = [copy(S)] for i in perm S += vectors[i] push!(pts, copy(S)) end x = first.(pts) y = last.(pts) θ = range(0, 2π, length=400) plot(cos.(θ), sin.(θ), aspect_ratio=1, lw=2, color=:black, label="unit circle") plot!(x, y, marker=:circle, ms=3, lw=2, label="walk") scatter!([0],[0], color=:red, label="origin") println("Maximum norm = ", maximum(norm.(pts)))