Permutation matrices research.

chore: Update search2.jl.

+17 -19
+17 -19
src/jupyter/search2.jl
··· 16 16 17 17 # Check if a sequence is a Costas sequence with debug information 18 18 function iscostas(lst::Vector{T}, f::Function = normal_predicate)::Union{Unit, Tuple{Tuple{Int64, Int64}, Tuple{Int64, Int64}}} where T 19 - n::Integer = length(lst) 19 + n::Int64 = length(lst) 20 20 for k in 1:n 21 21 diffs::Vector{Tuple{Bool, Tuple{Int64, Int64}}} = [(false, (-1,-1)) for _ in 1:2 * n] 22 22 for i in 1:(n - k) ··· 34 34 end 35 35 36 36 using Base.Threads 37 - function searchallt(n::Integer)::Vector{Vector{Integer}} 37 + function searchallt(n::Int64)::Vector{Vector{Int64}} 38 38 p1::Int64 = 0 39 39 p2::Int64 = 0 40 40 p3::Int64 = 0 ··· 43 43 i2::Int64 = 0 44 44 i3::Int64 = 0 45 45 i4::Int64 = 0 46 - acc::Vector{Vector{Vector{Integer}}} = [[] for _ in 1:nthreads()] 46 + acc::Vector{Vector{Vector{Int64}}} = [[] for _ in 1:nthreads()] 47 47 48 48 @threads :static for i in 1:factorial(n) 49 49 tid::Int64 = threadid() 50 50 lst::Vector{Int64} = nthperm(1:n, i) 51 51 if (i1 != 0 && p1 == lst[i1]) && (i2 != 0 && p2 == lst[i2]) && (i3 != 0 && p3 == lst[i3]) && (i4 != 0 && p4 == lst[i4]) 52 - #println("miss: ", lst) 53 52 continue 54 53 end 55 - result = iscostasdbg(lst) 54 + result = iscostas(lst) 56 55 if result isa Unit 57 56 push!(acc[tid], lst) 58 57 else 59 - #println("fail: ", lst, "; ", result) 60 58 (i1, i2), (i3, i4) = result 61 59 p1, p2, p3, p4 = lst[i1], lst[i2], lst[i3], lst[i4] 62 60 end ··· 64 62 reduce(vcat, acc) 65 63 end 66 64 67 - function searchall(n::Integer)::Vector{Vector{Integer}} 65 + function searchall(n::Int64)::Vector{Vector{Int64}} 68 66 p1::Int64 = 0 69 67 p2::Int64 = 0 70 68 p3::Int64 = 0 ··· 73 71 i2::Int64 = 0 74 72 i3::Int64 = 0 75 73 i4::Int64 = 0 76 - acc::Vector{Vector{Vector{Integer}}} = [] 74 + acc::Vector{Vector{Int64}} = [] 77 75 78 76 for i in 1:factorial(n) 79 77 lst::Vector{Int64} = nthperm(1:n, i) 80 78 if (i1 != 0 && p1 == lst[i1]) && (i2 != 0 && p2 == lst[i2]) && (i3 != 0 && p3 == lst[i3]) && (i4 != 0 && p4 == lst[i4]) 81 79 continue 82 80 end 83 - result = iscostasdbg(lst) 81 + result = iscostas(lst) 84 82 if result isa Unit 85 83 push!(acc, lst) 86 84 else ··· 143 141 return nothing 144 142 end 145 143 146 - const START = 10 147 - const LIMIT = 20 148 - 149 - for n in (START + 1):LIMIT 150 - out = searchdbg(n) 151 - file_path = "costas_$(n)x$n.dat" 152 - serialize(file_path, out) 153 - println("$file_path has $(length(out)) arrays.") 154 - end 155 - 144 + # const START = 10 145 + # const LIMIT = 20 146 + # 147 + # for n in (START + 1):LIMIT 148 + # out = searchdbg(n) 149 + # file_path = "costas_$(n)x$n.dat" 150 + # serialize(file_path, out) 151 + # println("$file_path has $(length(out)) arrays.") 152 + # end 153 + #