Permutation matrices research.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ci: Ignore correct files in jupyter notebooks.

The .gitignore had `src/jupyter/.ipynb_checkpoints/` instead of `__pycache__`.

+4660 -1
+1 -1
.gitignore
··· 3 3 results/* 4 4 venv/* 5 5 __pycache__/* 6 - src/jupyter/.ipynb_checkpoints/* 6 + src/jupyter/__pycache__/*
src/jupyter/.ipynb_checkpoints/costas_13x13-checkpoint.gif

This is a binary file and will not be displayed.

+60
src/jupyter/.ipynb_checkpoints/gif-checkpoint.jl
··· 1 + import Pkg 2 + import Serialization 3 + Pkg.add("Combinatorics") 4 + Pkg.add("Primes") 5 + Pkg.add("BenchmarkTools") 6 + Pkg.add("Transducers") 7 + Pkg.add("Plots") 8 + using Combinatorics 9 + using Primes 10 + using BenchmarkTools 11 + using Transducers 12 + using Plots 13 + 14 + include("header.jl") 15 + 16 + import Base.Iterators 17 + 18 + savevar(file_path::String, a) = Serialization.serialize(file_path, a) 19 + loadvar(file_path::String) = Serialization.deserialize(file_path) 20 + 21 + for n in 1:10 22 + # out = 1:n |> permutations |> Filter(iscostas) |> tcollect 23 + file_path = "costas_$(n)x$(n).dat" 24 + out = loadvar(file_path) 25 + #savevar(file_path, out) 26 + println("$(file_path) has $(length(out)) arrays.") 27 + end 28 + 29 + costas_1x1 = loadvar("costas_1x1.dat") 30 + costas_2x2 = loadvar("costas_2x2.dat") 31 + costas_3x3 = loadvar("costas_3x3.dat") 32 + costas_4x4 = loadvar("costas_4x4.dat") 33 + costas_5x5 = loadvar("costas_5x5.dat") 34 + costas_6x6 = loadvar("costas_6x6.dat") 35 + costas_7x7 = loadvar("costas_7x7.dat") 36 + costas_8x8 = loadvar("costas_8x8.dat") 37 + costas_9x9 = loadvar("costas_9x9.dat") 38 + costas_10x10 = loadvar("costas_10x10.dat") 39 + costas_11x11 = loadvar("costas_11x11.dat") 40 + println("costas_11x11 has $(length(costas_11x11)) arrays.") 41 + costas_12x12 = loadvar("costas_12x12.dat") 42 + println("costas_12x12 has $(length(costas_12x12)) arrays.") 43 + costas_13x13 = loadvar("costas_13x13.dat") 44 + println("costas_13x13 has $(length(costas_13x13)) arrays.") 45 + 46 + ize = 10 47 + last = costas_10x10[1][1:size - 3] 48 + inputs = [] 49 + arr = [] 50 + for l in costas_13x13 51 + if last != l[1:size - 3] 52 + push!(inputs, arr) 53 + last = l[1:size - 3] 54 + arr = [] 55 + end 56 + push!(arr, (l[size - 2], l[size - 1], l[size])) 57 + end 58 + println(length(inputs)) 59 + inputs 60 +
+4152
src/jupyter/.ipynb_checkpoints/julia-checkpoint.ipynb
··· 1 + { 2 + "cells": [ 3 + { 4 + "cell_type": "code", 5 + "execution_count": 8, 6 + "id": "eb80a7fb-7fb8-4117-898e-967f179749f5", 7 + "metadata": {}, 8 + "outputs": [ 9 + { 10 + "name": "stderr", 11 + "output_type": "stream", 12 + "text": [ 13 + "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", 14 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Project.toml`\n", 15 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Manifest.toml`\n", 16 + "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", 17 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Project.toml`\n", 18 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Manifest.toml`\n", 19 + "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", 20 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Project.toml`\n", 21 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Manifest.toml`\n", 22 + "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", 23 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Project.toml`\n", 24 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Manifest.toml`\n", 25 + "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", 26 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Project.toml`\n", 27 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Manifest.toml`\n" 28 + ] 29 + }, 30 + { 31 + "data": { 32 + "text/plain": [ 33 + "loadvar (generic function with 1 method)" 34 + ] 35 + }, 36 + "execution_count": 8, 37 + "metadata": {}, 38 + "output_type": "execute_result" 39 + } 40 + ], 41 + "source": [ 42 + "import Pkg\n", 43 + "import Serialization\n", 44 + "Pkg.add(\"Combinatorics\")\n", 45 + "Pkg.add(\"Primes\")\n", 46 + "Pkg.add(\"BenchmarkTools\")\n", 47 + "Pkg.add(\"Transducers\")\n", 48 + "Pkg.add(\"Plots\")\n", 49 + "using Combinatorics\n", 50 + "using Primes\n", 51 + "using BenchmarkTools\n", 52 + "using Transducers\n", 53 + "using Plots\n", 54 + "\n", 55 + "include(\"header.jl\")\n", 56 + "\n", 57 + "import Base.Iterators\n", 58 + "\n", 59 + "savevar(file_path::String, a) = Serialization.serialize(file_path, a)\n", 60 + "loadvar(file_path::String) = Serialization.deserialize(file_path)" 61 + ] 62 + }, 63 + { 64 + "cell_type": "code", 65 + "execution_count": 9, 66 + "id": "a9926a33-dc1c-4bd0-a26e-50e96184c3a0", 67 + "metadata": {}, 68 + "outputs": [ 69 + { 70 + "name": "stdout", 71 + "output_type": "stream", 72 + "text": [ 73 + "false\n", 74 + "true\n", 75 + "true\n", 76 + "false\n" 77 + ] 78 + } 79 + ], 80 + "source": [ 81 + "println(iscostas([1,2,3]))\n", 82 + "println(iscostas([1,2]))\n", 83 + "println(iscostas([1,2,4,3]))\n", 84 + "println(iscostas([4,2,3,1]))" 85 + ] 86 + }, 87 + { 88 + "cell_type": "code", 89 + "execution_count": 10, 90 + "id": "903347cf-2f5f-4c3d-87cd-832347941bcc", 91 + "metadata": {}, 92 + "outputs": [ 93 + { 94 + "data": { 95 + "text/plain": [ 96 + "4-element Vector{Vector{Integer}}:\n", 97 + " [2, 4, 8, 5, 10, 9, 7, 3, 6, 1]\n", 98 + " [6, 3, 7, 9, 10, 5, 8, 4, 2, 1]\n", 99 + " [7, 5, 2, 3, 10, 4, 6, 9, 8, 1]\n", 100 + " [8, 9, 6, 4, 10, 3, 2, 5, 7, 1]" 101 + ] 102 + }, 103 + "execution_count": 10, 104 + "metadata": {}, 105 + "output_type": "execute_result" 106 + } 107 + ], 108 + "source": [ 109 + "welch(11)" 110 + ] 111 + }, 112 + { 113 + "cell_type": "code", 114 + "execution_count": 11, 115 + "id": "2bd42ccd-f652-4887-babc-ac2a1de2a0e0", 116 + "metadata": {}, 117 + "outputs": [ 118 + { 119 + "data": { 120 + "text/plain": [ 121 + "4-element Vector{Vector{Integer}}:\n", 122 + " [5, 3, 2, 7, 1, 8, 4, 6, 9]\n", 123 + " [1, 4, 6, 2, 9, 3, 8, 7, 5]\n", 124 + " [2, 1, 5, 8, 3, 9, 7, 4, 6]\n", 125 + " [4, 6, 3, 1, 7, 2, 5, 9, 8]" 126 + ] 127 + }, 128 + "execution_count": 11, 129 + "metadata": {}, 130 + "output_type": "execute_result" 131 + } 132 + ], 133 + "source": [ 134 + "lempel(11)" 135 + ] 136 + }, 137 + { 138 + "cell_type": "code", 139 + "execution_count": 12, 140 + "id": "fd67b6f4-2954-4521-a993-68a839c158ab", 141 + "metadata": {}, 142 + "outputs": [ 143 + { 144 + "data": { 145 + "text/plain": [ 146 + "4-element Vector{Vector{Integer}}:\n", 147 + " [5, 3, 2, 7, 1, 8, 4, 6, 9]\n", 148 + " [1, 4, 6, 2, 9, 3, 8, 7, 5]\n", 149 + " [2, 1, 5, 8, 3, 9, 7, 4, 6]\n", 150 + " [4, 6, 3, 1, 7, 2, 5, 9, 8]" 151 + ] 152 + }, 153 + "execution_count": 12, 154 + "metadata": {}, 155 + "output_type": "execute_result" 156 + } 157 + ], 158 + "source": [ 159 + "lempel(11) |> Filter(iscostas) |> collect" 160 + ] 161 + }, 162 + { 163 + "cell_type": "code", 164 + "execution_count": 13, 165 + "id": "f9f95fc7-0f77-49c8-855c-061f4c971022", 166 + "metadata": {}, 167 + "outputs": [ 168 + { 169 + "name": "stdout", 170 + "output_type": "stream", 171 + "text": [ 172 + "costas_1x1.dat has 1 arrays.\n", 173 + "costas_2x2.dat has 2 arrays.\n", 174 + "costas_3x3.dat has 4 arrays.\n", 175 + "costas_4x4.dat has 12 arrays.\n", 176 + "costas_5x5.dat has 40 arrays.\n", 177 + "costas_6x6.dat has 116 arrays.\n", 178 + "costas_7x7.dat has 200 arrays.\n", 179 + "costas_8x8.dat has 444 arrays.\n", 180 + "costas_9x9.dat has 760 arrays.\n", 181 + "costas_10x10.dat has 2160 arrays.\n", 182 + "costas_11x11 has 4367 arrays.\n", 183 + "costas_12x12 has 7852 arrays.\n", 184 + "costas_13x13 has 12828 arrays.\n" 185 + ] 186 + } 187 + ], 188 + "source": [ 189 + "for n in 1:10\n", 190 + " # out = 1:n |> permutations |> Filter(iscostas) |> tcollect\n", 191 + " file_path = \"costas_$(n)x$(n).dat\"\n", 192 + " out = loadvar(file_path)\n", 193 + " #savevar(file_path, out)\n", 194 + " println(\"$(file_path) has $(length(out)) arrays.\")\n", 195 + "end\n", 196 + "\n", 197 + "costas_1x1 = loadvar(\"costas_1x1.dat\")\n", 198 + "costas_2x2 = loadvar(\"costas_2x2.dat\")\n", 199 + "costas_3x3 = loadvar(\"costas_3x3.dat\")\n", 200 + "costas_4x4 = loadvar(\"costas_4x4.dat\")\n", 201 + "costas_5x5 = loadvar(\"costas_5x5.dat\")\n", 202 + "costas_6x6 = loadvar(\"costas_6x6.dat\")\n", 203 + "costas_7x7 = loadvar(\"costas_7x7.dat\")\n", 204 + "costas_8x8 = loadvar(\"costas_8x8.dat\")\n", 205 + "costas_9x9 = loadvar(\"costas_9x9.dat\")\n", 206 + "costas_10x10 = loadvar(\"costas_10x10.dat\")\n", 207 + "costas_11x11 = loadvar(\"costas_11x11.dat\")\n", 208 + "println(\"costas_11x11 has $(length(costas_11x11)) arrays.\")\n", 209 + "costas_12x12 = loadvar(\"costas_12x12.dat\")\n", 210 + "println(\"costas_12x12 has $(length(costas_12x12)) arrays.\")\n", 211 + "costas_13x13 = loadvar(\"costas_13x13.dat\")\n", 212 + "println(\"costas_13x13 has $(length(costas_13x13)) arrays.\")" 213 + ] 214 + }, 215 + { 216 + "cell_type": "code", 217 + "execution_count": 7, 218 + "id": "239e70bf-e41a-4d74-9935-ad5343195031", 219 + "metadata": {}, 220 + "outputs": [ 221 + { 222 + "name": "stdout", 223 + "output_type": "stream", 224 + "text": [ 225 + "costas_1x2.dat has 1 arrays.\n", 226 + "costas_2x3.dat has 1 arrays.\n", 227 + "costas_3x4.dat has 2 arrays.\n", 228 + "costas_4x5.dat has 4 arrays.\n", 229 + "costas_5x6.dat has 12 arrays.\n", 230 + "costas_6x7.dat has 40 arrays.\n", 231 + "costas_7x8.dat has 116 arrays.\n", 232 + "costas_8x9.dat has 200 arrays.\n", 233 + "costas_9x10.dat has 444 arrays.\n", 234 + "costas_10x11.dat has 760 arrays.\n" 235 + ] 236 + }, 237 + { 238 + "data": { 239 + "text/plain": [ 240 + "760-element Vector{Vector{Int64}}:\n", 241 + " [2, 3, 7, 5, 10, 9, 6, 8, 4]\n", 242 + " [2, 3, 7, 9, 6, 4, 10, 5, 8]\n", 243 + " [2, 3, 7, 9, 6, 5, 10, 8, 4]\n", 244 + " [2, 3, 7, 10, 6, 4, 9, 8, 5]\n", 245 + " [2, 3, 8, 6, 10, 7, 9, 5, 4]\n", 246 + " [2, 3, 8, 7, 10, 5, 9, 6, 4]\n", 247 + " [2, 3, 9, 5, 10, 8, 7, 4, 6]\n", 248 + " [2, 3, 10, 5, 8, 4, 9, 7, 6]\n", 249 + " [2, 3, 10, 7, 6, 4, 9, 5, 8]\n", 250 + " [2, 3, 10, 7, 9, 5, 4, 8, 6]\n", 251 + " [2, 3, 10, 9, 5, 7, 4, 8, 6]\n", 252 + " [2, 4, 8, 5, 10, 9, 7, 3, 6]\n", 253 + " [2, 4, 9, 8, 3, 10, 6, 7, 5]\n", 254 + " ⋮\n", 255 + " [10, 8, 4, 7, 2, 3, 5, 9, 6]\n", 256 + " [10, 9, 2, 3, 7, 5, 8, 4, 6]\n", 257 + " [10, 9, 2, 5, 3, 7, 8, 4, 6]\n", 258 + " [10, 9, 2, 5, 6, 8, 3, 7, 4]\n", 259 + " [10, 9, 2, 7, 4, 8, 3, 5, 6]\n", 260 + " [10, 9, 3, 7, 2, 4, 5, 8, 6]\n", 261 + " [10, 9, 4, 5, 2, 7, 3, 6, 8]\n", 262 + " [10, 9, 4, 6, 2, 5, 3, 7, 8]\n", 263 + " [10, 9, 5, 2, 6, 8, 3, 4, 7]\n", 264 + " [10, 9, 5, 3, 6, 7, 2, 4, 8]\n", 265 + " [10, 9, 5, 3, 6, 8, 2, 7, 4]\n", 266 + " [10, 9, 5, 7, 2, 3, 6, 4, 8]" 267 + ] 268 + }, 269 + "execution_count": 7, 270 + "metadata": {}, 271 + "output_type": "execute_result" 272 + } 273 + ], 274 + "source": [ 275 + "for n in 1:10\n", 276 + " out = 2:n |> permutations |> Filter(Base.Fix2(iscostas, asterisk_predicate)) |> tcollect\n", 277 + " file_path = \"costas_$(n)x$(n + 1).dat\"\n", 278 + " #savevar(file_path, out)\n", 279 + " println(\"$(file_path) has $(size(out, 1)) arrays.\")\n", 280 + "end\n", 281 + "\n", 282 + "costas_1x2 = loadvar(\"costas_1x2.dat\")\n", 283 + "costas_2x3 = loadvar(\"costas_2x3.dat\")\n", 284 + "costas_3x4 = loadvar(\"costas_3x4.dat\")\n", 285 + "costas_4x5 = loadvar(\"costas_4x5.dat\")\n", 286 + "costas_5x6 = loadvar(\"costas_5x6.dat\")\n", 287 + "costas_6x7 = loadvar(\"costas_6x7.dat\")\n", 288 + "costas_7x8 = loadvar(\"costas_7x8.dat\")\n", 289 + "costas_8x9 = loadvar(\"costas_8x9.dat\")\n", 290 + "costas_9x10 = loadvar(\"costas_9x10.dat\")\n", 291 + "costas_10x11 = loadvar(\"costas_10x11.dat\")" 292 + ] 293 + }, 294 + { 295 + "cell_type": "code", 296 + "execution_count": 12, 297 + "id": "230e7196-78a9-4119-8a03-d61997345038", 298 + "metadata": {}, 299 + "outputs": [ 300 + { 301 + "name": "stdout", 302 + "output_type": "stream", 303 + "text": [ 304 + "12684\n" 305 + ] 306 + }, 307 + { 308 + "data": { 309 + "text/plain": [ 310 + "12684-element Vector{Any}:\n", 311 + " Any[]\n", 312 + " Any[(11, 7, 5)]\n", 313 + " Any[(3, 12, 6)]\n", 314 + " Any[(5, 11, 3)]\n", 315 + " Any[(11, 3, 6)]\n", 316 + " Any[(12, 6, 11)]\n", 317 + " Any[(3, 10, 9)]\n", 318 + " Any[(4, 11, 3)]\n", 319 + " Any[(13, 4, 3)]\n", 320 + " Any[(3, 10, 9)]\n", 321 + " Any[(4, 10, 13)]\n", 322 + " Any[(12, 11, 3)]\n", 323 + " Any[(5, 13, 4)]\n", 324 + " ⋮\n", 325 + " Any[(9, 10, 2)]\n", 326 + " Any[(9, 1, 10)]\n", 327 + " Any[(2, 3, 11)]\n", 328 + " Any[(10, 4, 1)]\n", 329 + " Any[(11, 4, 5)]\n", 330 + " Any[(1, 10, 11)]\n", 331 + " Any[(10, 3, 11)]\n", 332 + " Any[(11, 4, 5)]\n", 333 + " Any[(2, 8, 3)]\n", 334 + " Any[(3, 11, 8)]\n", 335 + " Any[(9, 3, 11)]\n", 336 + " Any[(11, 2, 8)]" 337 + ] 338 + }, 339 + "execution_count": 12, 340 + "metadata": {}, 341 + "output_type": "execute_result" 342 + } 343 + ], 344 + "source": [ 345 + "size = 10\n", 346 + "last = costas_10x10[1][1:size - 3]\n", 347 + "inputs = []\n", 348 + "arr = []\n", 349 + "for l in costas_13x13\n", 350 + " if last != l[1:size - 3]\n", 351 + " push!(inputs, arr)\n", 352 + " last = l[1:size - 3]\n", 353 + " arr = []\n", 354 + " end\n", 355 + " push!(arr, (l[size - 2], l[size - 1], l[size]))\n", 356 + "end\n", 357 + "println(length(inputs))\n", 358 + "inputs" 359 + ] 360 + }, 361 + { 362 + "cell_type": "code", 363 + "execution_count": null, 364 + "id": "f2a63de1-5fb5-45ed-9113-240ccc6fb22f", 365 + "metadata": {}, 366 + "outputs": [], 367 + "source": [ 368 + "kw = (proj_type = :ortho, legend = false, aspect_ratio = :equal, xlimits = (0,10), ylimits = (0,10), zlimits = (0,10))\n", 369 + "limit = length(inputs)\n", 370 + "colors = palette([:orange, :blue], limit + 2)\n", 371 + "@gif for i in 45:135\n", 372 + " idx = 1\n", 373 + " for pts in inputs\n", 374 + " x = pts .|> a -> a[1]\n", 375 + " y = pts .|> a -> a[2]\n", 376 + " z = pts .|> a -> a[3]\n", 377 + " idx += 1\n", 378 + " scatter!(x, y, z; markercolor = colors[idx], camera = (i, round(atand(1 / √2); digits = 3)), kw...)\n", 379 + " end\n", 380 + "end" 381 + ] 382 + }, 383 + { 384 + "cell_type": "code", 385 + "execution_count": 15, 386 + "id": "88a92f2b-1325-4742-90b0-407dbed6a93a", 387 + "metadata": {}, 388 + "outputs": [ 389 + { 390 + "name": "stdout", 391 + "output_type": "stream", 392 + "text": [ 393 + "From costas_1x2:\n", 394 + "Any[1, '*']\n", 395 + "Any['*', 1]\n", 396 + "From costas_3x4:\n", 397 + "Any[1, 2, '*', 3]\n", 398 + "Any[1, 3, 2, '*']\n", 399 + "Any[2, 1, 3, '*']\n", 400 + "Any[2, '*', 1, 3]\n", 401 + "Any[3, 1, '*', 2]\n", 402 + "Any[3, '*', 2, 1]\n", 403 + "Any['*', 2, 3, 1]\n", 404 + "Any['*', 3, 1, 2]\n", 405 + "From costas_5x6:\n", 406 + "Any[2, 3, 5, '*', 1, 4]\n", 407 + "Any[3, 1, '*', 5, 2, 4]\n", 408 + "Any[4, 1, '*', 5, 3, 2]\n", 409 + "Any[4, 2, 5, '*', 1, 3]\n", 410 + "Any[5, 2, 4, 3, 1, '*']\n", 411 + "Any[5, 3, 2, 4, 1, '*']\n", 412 + "Any['*', 1, 3, 4, 2, 5]\n", 413 + "Any['*', 1, 4, 2, 3, 5]\n", 414 + "From costas_9x10:\n", 415 + "Any[1, 4, 6, 2, 9, 3, 8, 7, 5, '*']\n", 416 + "Any[1, 7, 2, 3, 5, '*', 9, 6, 4, 8]\n", 417 + "Any[2, 1, 5, 8, 3, 9, 7, 4, 6, '*']\n", 418 + "Any[2, 5, 9, 8, '*', 4, 6, 3, 1, 7]\n", 419 + "Any[3, 8, 5, 1, 2, '*', 6, 4, 7, 9]\n", 420 + "Any[3, 8, 7, 5, '*', 1, 4, 6, 2, 9]\n", 421 + "Any[4, 6, 3, 1, 7, 2, 5, 9, 8, '*']\n", 422 + "Any[5, 3, 2, 7, 1, 8, 4, 6, 9, '*']\n", 423 + "Any[7, 1, 3, 6, 4, '*', 8, 9, 5, 2]\n", 424 + "Any[8, 4, 6, 9, '*', 5, 3, 2, 7, 1]\n", 425 + "Any[9, 2, 6, 4, 1, '*', 5, 7, 8, 3]\n", 426 + "Any[9, 7, 4, 6, '*', 2, 1, 5, 8, 3]\n", 427 + "Any['*', 5, 7, 8, 3, 9, 2, 6, 4, 1]\n", 428 + "Any['*', 6, 4, 7, 9, 3, 8, 5, 1, 2]\n", 429 + "Any['*', 8, 9, 5, 2, 7, 1, 3, 6, 4]\n", 430 + "Any['*', 9, 6, 4, 8, 1, 7, 2, 3, 5]\n" 431 + ] 432 + } 433 + ], 434 + "source": [ 435 + "println(\"From costas_1x2:\")\n", 436 + "checklempel(costas_1x2,3)\n", 437 + "println(\"From costas_3x4:\")\n", 438 + "checklempel(costas_3x4,5)\n", 439 + "println(\"From costas_5x6:\")\n", 440 + "checklempel(costas_5x6,7)\n", 441 + "println(\"From costas_9x10:\")\n", 442 + "checklempel(costas_9x10,11)" 443 + ] 444 + }, 445 + { 446 + "cell_type": "code", 447 + "execution_count": 16, 448 + "id": "e3cf4111-f655-4075-9b90-3cc7faf77320", 449 + "metadata": {}, 450 + "outputs": [ 451 + { 452 + "data": { 453 + "text/plain": [ 454 + "checkwelch (generic function with 1 method)" 455 + ] 456 + }, 457 + "execution_count": 16, 458 + "metadata": {}, 459 + "output_type": "execute_result" 460 + } 461 + ], 462 + "source": [ 463 + "function checkwelch(costas::Vector{Vector{Integer}}, prime::Integer)\n", 464 + " all(all(w == lst || isrotated(w, lst) || isrotated(w, reverse(lst)) for w in welch(prime)) for lst in costas)\n", 465 + "end" 466 + ] 467 + }, 468 + { 469 + "cell_type": "code", 470 + "execution_count": 17, 471 + "id": "d4e6119c-a191-4be4-8d07-14506117c7a5", 472 + "metadata": {}, 473 + "outputs": [ 474 + { 475 + "ename": "LoadError", 476 + "evalue": "MethodError: no method matching checkwelch(::Vector{Vector{Int64}}, ::Int64)\n\n\u001b[0mClosest candidates are:\n\u001b[0m checkwelch(\u001b[91m::Vector{Vector{Integer}}\u001b[39m, ::Integer)\n\u001b[0m\u001b[90m @\u001b[39m \u001b[35mMain\u001b[39m \u001b[90m\u001b[4mIn[16]:1\u001b[24m\u001b[39m\n", 477 + "output_type": "error", 478 + "traceback": [ 479 + "MethodError: no method matching checkwelch(::Vector{Vector{Int64}}, ::Int64)\n\n\u001b[0mClosest candidates are:\n\u001b[0m checkwelch(\u001b[91m::Vector{Vector{Integer}}\u001b[39m, ::Integer)\n\u001b[0m\u001b[90m @\u001b[39m \u001b[35mMain\u001b[39m \u001b[90m\u001b[4mIn[16]:1\u001b[24m\u001b[39m\n", 480 + "", 481 + "Stacktrace:", 482 + " [1] top-level scope", 483 + " @ In[17]:1" 484 + ] 485 + } 486 + ], 487 + "source": [ 488 + "println(\"From costas_2x2:\", checkwelch(costas_2x2,3))\n", 489 + "println(\"From costas_4x4:\", checkwelch(costas_4x4,5))\n", 490 + "println(\"From costas_6x6:\", checkwelch(costas_6x6,7))\n", 491 + "println(\"From costas_10x10:\", checkwelch(costas_10x10,11))" 492 + ] 493 + }, 494 + { 495 + "cell_type": "code", 496 + "execution_count": 59, 497 + "id": "ae2a139b-caeb-4d29-b1d2-c4e2009f118c", 498 + "metadata": {}, 499 + "outputs": [ 500 + { 501 + "data": { 502 + "text/plain": [ 503 + "4-element Vector{Vector{Int64}}:\n", 504 + " [1, 4, 2, 3]\n", 505 + " [2, 3, 1, 4]\n", 506 + " [3, 2, 4, 1]\n", 507 + " [4, 1, 3, 2]" 508 + ] 509 + }, 510 + "execution_count": 59, 511 + "metadata": {}, 512 + "output_type": "execute_result" 513 + } 514 + ], 515 + "source": [ 516 + "function filterwelchs(costas, prime)\n", 517 + " filter(lst -> all(!isrotated(lst, w) && !isrotated(lst, reverse(w)) for w in welch(prime)), costas)\n", 518 + "end\n", 519 + "filterwelchs(costas_4x4, 5)" 520 + ] 521 + }, 522 + { 523 + "cell_type": "code", 524 + "execution_count": 61, 525 + "id": "5431bf61-e169-48aa-90c7-e15d669cf625", 526 + "metadata": {}, 527 + "outputs": [ 528 + { 529 + "data": { 530 + "text/plain": [ 531 + "issubarray (generic function with 2 methods)" 532 + ] 533 + }, 534 + "execution_count": 61, 535 + "metadata": {}, 536 + "output_type": "execute_result" 537 + } 538 + ], 539 + "source": [ 540 + "function issubarray(lhs::Vector, rhs::Vector)::Bool\n", 541 + " lhs .|> Base.Fix1(findindex, rhs) |> issorted\n", 542 + "end" 543 + ] 544 + }, 545 + { 546 + "cell_type": "code", 547 + "execution_count": 64, 548 + "id": "cee27363-a468-4a91-b379-5515b0bf9d21", 549 + "metadata": {}, 550 + "outputs": [ 551 + { 552 + "name": "stdout", 553 + "output_type": "stream", 554 + "text": [ 555 + "Integer[1, 4, 6, 2, 9, 3, 8, 7, 5] [10, 1, 4, 6, 2, 9, 3, 8, 7, 5]\n", 556 + "Integer[2, 1, 5, 8, 3, 9, 7, 4, 6] [10, 2, 1, 5, 8, 3, 9, 7, 4, 6]\n", 557 + "Integer[4, 6, 3, 1, 7, 2, 5, 9, 8] [10, 4, 6, 3, 1, 7, 2, 5, 9, 8]\n", 558 + "Integer[5, 3, 2, 7, 1, 8, 4, 6, 9] [10, 5, 3, 2, 7, 1, 8, 4, 6, 9]\n" 559 + ] 560 + } 561 + ], 562 + "source": [ 563 + "for arr in filterwelchs(costas_10x10, 11)\n", 564 + " for l in lempel(11)\n", 565 + " if issubarray(l, arr)\n", 566 + " println(\"$l $arr\")\n", 567 + " end\n", 568 + " end\n", 569 + "end" 570 + ] 571 + }, 572 + { 573 + "cell_type": "code", 574 + "execution_count": 65, 575 + "id": "db8b3c90-2dd1-45d1-9739-ee3ee0bdf74c", 576 + "metadata": {}, 577 + "outputs": [ 578 + { 579 + "data": { 580 + "text/plain": [ 581 + "2144" 582 + ] 583 + }, 584 + "execution_count": 65, 585 + "metadata": {}, 586 + "output_type": "execute_result" 587 + } 588 + ], 589 + "source": [ 590 + "length(filterwelchs(costas_10x10, 11))" 591 + ] 592 + }, 593 + { 594 + "cell_type": "code", 595 + "execution_count": 25, 596 + "id": "0753c6e2-8dd3-4bd9-8233-4b090eaaac68", 597 + "metadata": {}, 598 + "outputs": [ 599 + { 600 + "data": { 601 + "text/plain": [ 602 + "buildallnaive (generic function with 1 method)" 603 + ] 604 + }, 605 + "execution_count": 25, 606 + "metadata": {}, 607 + "output_type": "execute_result" 608 + } 609 + ], 610 + "source": [ 611 + "# /*\n", 612 + "# * Complexity: O(n^3)\n", 613 + "# */\n", 614 + "# template <class T> fn build_all_naive(Vec<T> const& vec, T x) -> Vec<Vec<T>> {\n", 615 + "# var out = Vec<Vec<T>>();\n", 616 + "# for (Size i = 0; i < vec.size(); ++i) {\n", 617 + "# var lst2 = vec;\n", 618 + "# lst2.insert(lst2.begin() + i, x);\n", 619 + "# if (is_costas(lst2))\n", 620 + "# out.push_back(lst2);\n", 621 + "# }\n", 622 + "# return out;\n", 623 + "# }\n", 624 + "\n", 625 + "function buildallnaive(vec::Vector{T}, x::T)::Vector{Vector{T}} where T\n", 626 + " out = []\n", 627 + " for i in 1:length(vec)\n", 628 + " lst2 = copy(vec)\n", 629 + " insert!(lst2, i, x)\n", 630 + " if iscostas(lst2)\n", 631 + " push!(out,lst2)\n", 632 + " end\n", 633 + " end\n", 634 + " out\n", 635 + "end" 636 + ] 637 + }, 638 + { 639 + "cell_type": "code", 640 + "execution_count": 63, 641 + "id": "31fcaf99-c20b-4cf6-850f-a117ea166376", 642 + "metadata": {}, 643 + "outputs": [ 644 + { 645 + "name": "stdout", 646 + "output_type": "stream", 647 + "text": [ 648 + "Vector{Integer}[]\n", 649 + "Vector{Integer}[]\n", 650 + "Vector{Integer}[]\n", 651 + "Vector{Integer}[]\n", 652 + "Vector{Integer}[]\n", 653 + "Vector{Integer}[]\n", 654 + "Vector{Integer}[]\n", 655 + "Vector{Integer}[]\n" 656 + ] 657 + } 658 + ], 659 + "source": [ 660 + "for v in welch(17)\n", 661 + " println(buildallnaive(v,17))\n", 662 + "end" 663 + ] 664 + }, 665 + { 666 + "cell_type": "code", 667 + "execution_count": 57, 668 + "id": "fb16e912-f3a8-467f-99f1-b5ab331efacc", 669 + "metadata": {}, 670 + "outputs": [ 671 + { 672 + "data": { 673 + "text/plain": [ 674 + "12-element Vector{Int64}:\n", 675 + " 2\n", 676 + " 3\n", 677 + " 5\n", 678 + " 7\n", 679 + " 11\n", 680 + " 13\n", 681 + " 17\n", 682 + " 19\n", 683 + " 23\n", 684 + " 29\n", 685 + " 31\n", 686 + " 37" 687 + ] 688 + }, 689 + "execution_count": 57, 690 + "metadata": {}, 691 + "output_type": "execute_result" 692 + } 693 + ], 694 + "source": [ 695 + "primes(40)" 696 + ] 697 + }, 698 + { 699 + "cell_type": "code", 700 + "execution_count": 34, 701 + "id": "a42393e3-afc5-49a5-8abc-9c52b39f4326", 702 + "metadata": {}, 703 + "outputs": [ 704 + { 705 + "name": "stdout", 706 + "output_type": "stream", 707 + "text": [ 708 + "[3, 1, 2]\n", 709 + "[1, 3, 2]\n", 710 + "[2, 3, 1]\n", 711 + "[[3, 1, 2, 1, 3, 2], [2, 3, 1]]\n", 712 + "[2, 4, 3, 1]\n", 713 + "[Int64[], [2, 4, 3, 1]]\n", 714 + "[5, 2, 4, 3, 1]\n", 715 + "[Int64[], [5, 2, 4, 3, 1]]\n", 716 + "[5, 2, 4, 3, 6, 1]\n", 717 + "[Int64[], [5, 2, 4, 3, 6, 1]]\n", 718 + "[Int64[], Int64[]]\n", 719 + "[Int64[], Int64[]]\n", 720 + "[Int64[], Int64[]]\n", 721 + "[Int64[], Int64[]]\n", 722 + "[Int64[], Int64[]]\n", 723 + "[Int64[], Int64[]]\n", 724 + "[Int64[], Int64[]]\n", 725 + "[Int64[], Int64[]]\n", 726 + "[Int64[], Int64[]]\n", 727 + "[Int64[], Int64[]]\n", 728 + "[Int64[], Int64[]]\n", 729 + "[Int64[], Int64[]]\n", 730 + "[Int64[], Int64[]]\n", 731 + "[Int64[], Int64[]]\n" 732 + ] 733 + } 734 + ], 735 + "source": [ 736 + "out = [[1,2],[2,1]]\n", 737 + "for i ∈ 3:20\n", 738 + " out = [buildallnaive(vec,i) |> flatten for vec in out]\n", 739 + " println(out)\n", 740 + "end" 741 + ] 742 + }, 743 + { 744 + "cell_type": "code", 745 + "execution_count": 31, 746 + "id": "0dc1ee17-2b26-49f5-841f-aee998ee3dc6", 747 + "metadata": {}, 748 + "outputs": [ 749 + { 750 + "data": { 751 + "text/plain": [ 752 + "flatten (generic function with 1 method)" 753 + ] 754 + }, 755 + "execution_count": 31, 756 + "metadata": {}, 757 + "output_type": "execute_result" 758 + } 759 + ], 760 + "source": [ 761 + "function flatten(vec::Vector{Vector{T}})::Vector{T} where T\n", 762 + " out = []\n", 763 + " for v in vec\n", 764 + " println(v)\n", 765 + " out = vcat(out,v)\n", 766 + " end\n", 767 + " out\n", 768 + "end" 769 + ] 770 + }, 771 + { 772 + "cell_type": "code", 773 + "execution_count": 32, 774 + "id": "13065e83-3e9b-4df9-b96e-b6459cb3b460", 775 + "metadata": {}, 776 + "outputs": [ 777 + { 778 + "name": "stdout", 779 + "output_type": "stream", 780 + "text": [ 781 + "[1, 2]\n", 782 + "[2, 3]\n" 783 + ] 784 + }, 785 + { 786 + "data": { 787 + "text/plain": [ 788 + "4-element Vector{Int64}:\n", 789 + " 1\n", 790 + " 2\n", 791 + " 2\n", 792 + " 3" 793 + ] 794 + }, 795 + "execution_count": 32, 796 + "metadata": {}, 797 + "output_type": "execute_result" 798 + } 799 + ], 800 + "source": [ 801 + "flatten([[1,2],[2,3]])" 802 + ] 803 + }, 804 + { 805 + "cell_type": "code", 806 + "execution_count": 89, 807 + "id": "3d7728a1-c5f8-4abe-a99f-c1effcd4bd75", 808 + "metadata": {}, 809 + "outputs": [ 810 + { 811 + "name": "stdout", 812 + "output_type": "stream", 813 + "text": [ 814 + " 12.701 ms (369811 allocations: 34.37 MiB)\n", 815 + " 13.263 ms (369822 allocations: 35.17 MiB)\n" 816 + ] 817 + }, 818 + { 819 + "data": { 820 + "text/plain": [ 821 + "444-element Vector{Vector{Int64}}:\n", 822 + " [1, 2, 5, 7, 6, 4, 8, 3]\n", 823 + " [1, 2, 8, 6, 3, 5, 4, 7]\n", 824 + " [1, 3, 6, 2, 7, 8, 5, 4]\n", 825 + " [1, 3, 6, 7, 5, 2, 8, 4]\n", 826 + " [1, 3, 6, 7, 5, 4, 8, 2]\n", 827 + " [1, 3, 8, 6, 7, 2, 5, 4]\n", 828 + " [1, 4, 2, 8, 7, 3, 5, 6]\n", 829 + " [1, 4, 5, 3, 7, 6, 8, 2]\n", 830 + " [1, 4, 5, 7, 6, 3, 8, 2]\n", 831 + " [1, 5, 3, 8, 7, 4, 6, 2]\n", 832 + " [1, 5, 4, 7, 2, 8, 6, 3]\n", 833 + " [1, 5, 6, 3, 8, 7, 2, 4]\n", 834 + " [1, 5, 6, 8, 3, 2, 7, 4]\n", 835 + " ⋮\n", 836 + " [8, 4, 3, 6, 1, 2, 7, 5]\n", 837 + " [8, 4, 5, 2, 7, 1, 3, 6]\n", 838 + " [8, 4, 6, 1, 2, 5, 3, 7]\n", 839 + " [8, 5, 4, 2, 3, 6, 1, 7]\n", 840 + " [8, 5, 4, 6, 2, 3, 1, 7]\n", 841 + " [8, 5, 7, 1, 2, 6, 4, 3]\n", 842 + " [8, 6, 1, 3, 2, 7, 4, 5]\n", 843 + " [8, 6, 3, 2, 4, 5, 1, 7]\n", 844 + " [8, 6, 3, 2, 4, 7, 1, 5]\n", 845 + " [8, 6, 3, 7, 2, 1, 4, 5]\n", 846 + " [8, 7, 1, 3, 6, 4, 5, 2]\n", 847 + " [8, 7, 4, 2, 3, 5, 1, 6]" 848 + ] 849 + }, 850 + "execution_count": 89, 851 + "metadata": {}, 852 + "output_type": "execute_result" 853 + } 854 + ], 855 + "source": [ 856 + "@btime 1:8 |> permutations |> Filter(iscostas) |> tcollect\n", 857 + "@btime 1:8 |> permutations |> tcollect |> Filter(iscostas) |> tcollect" 858 + ] 859 + }, 860 + { 861 + "cell_type": "code", 862 + "execution_count": 12, 863 + "id": "b8d572c5-71c5-4157-8f00-b28b6f6a5c86", 864 + "metadata": {}, 865 + "outputs": [ 866 + { 867 + "data": { 868 + "text/plain": [ 869 + "push! (generic function with 27 methods)" 870 + ] 871 + }, 872 + "execution_count": 12, 873 + "metadata": {}, 874 + "output_type": "execute_result" 875 + } 876 + ], 877 + "source": [ 878 + "push!" 879 + ] 880 + }, 881 + { 882 + "cell_type": "code", 883 + "execution_count": 74, 884 + "id": "bc84dea7-abbf-4391-b7ca-bc3ef042b5f6", 885 + "metadata": {}, 886 + "outputs": [ 887 + { 888 + "data": { 889 + "text/plain": [ 890 + "iscostashelper2 (generic function with 1 method)" 891 + ] 892 + }, 893 + "execution_count": 74, 894 + "metadata": {}, 895 + "output_type": "execute_result" 896 + } 897 + ], 898 + "source": [ 899 + "function iscostashelper2(lst::Vector{T}, f::Function, n::Integer)::Bool where T\n", 900 + " all(begin\n", 901 + " seen::Vector{Bool} = zeros(Bool, 2 * n)\n", 902 + " all(begin\n", 903 + " result = f(lst[i+k],lst[i],n)\n", 904 + " prev = seen[result]\n", 905 + " seen[result] = true\n", 906 + " !prev\n", 907 + " end for i ∈ 1:(n - k))\n", 908 + " end for k ∈ 1:n)\n", 909 + "end" 910 + ] 911 + }, 912 + { 913 + "cell_type": "code", 914 + "execution_count": 76, 915 + "id": "f23c7781-a45e-4eb8-b826-75195d85f4a2", 916 + "metadata": {}, 917 + "outputs": [ 918 + { 919 + "data": { 920 + "text/plain": [ 921 + "false" 922 + ] 923 + }, 924 + "execution_count": 76, 925 + "metadata": {}, 926 + "output_type": "execute_result" 927 + } 928 + ], 929 + "source": [ 930 + "iscostashelper2([1,2,3], (x,y,n) -> x - y + n, 3)" 931 + ] 932 + }, 933 + { 934 + "cell_type": "code", 935 + "execution_count": 87, 936 + "id": "6b4fc3f1-add6-4062-88f4-40e2aeb365e7", 937 + "metadata": {}, 938 + "outputs": [ 939 + { 940 + "data": { 941 + "text/plain": [ 942 + "8-element Vector{Int64}:\n", 943 + " 1\n", 944 + " 2\n", 945 + " 3\n", 946 + " 4\n", 947 + " 5\n", 948 + " 6\n", 949 + " 7\n", 950 + " 8" 951 + ] 952 + }, 953 + "execution_count": 87, 954 + "metadata": {}, 955 + "output_type": "execute_result" 956 + } 957 + ], 958 + "source": [ 959 + "1:8 |> collect" 960 + ] 961 + }, 962 + { 963 + "cell_type": "code", 964 + "execution_count": 85, 965 + "id": "a4342391-7c28-4871-b69f-7f5d746e7f87", 966 + "metadata": {}, 967 + "outputs": [ 968 + { 969 + "data": { 970 + "text/plain": [ 971 + "6-element Vector{Vector{Any}}:\n", 972 + " [1, 2, '*']\n", 973 + " [1, '*', 2]\n", 974 + " [2, 1, '*']\n", 975 + " [2, '*', 1]\n", 976 + " ['*', 1, 2]\n", 977 + " ['*', 2, 1]" 978 + ] 979 + }, 980 + "execution_count": 85, 981 + "metadata": {}, 982 + "output_type": "execute_result" 983 + } 984 + ], 985 + "source": [ 986 + "costas_2x3" 987 + ] 988 + }, 989 + { 990 + "cell_type": "code", 991 + "execution_count": 4, 992 + "id": "a23e4d3d-1e0f-4956-a7ae-fe60b4296675", 993 + "metadata": {}, 994 + "outputs": [ 995 + { 996 + "data": { 997 + "text/plain": [ 998 + "12-element Vector{Vector{Int64}}:\n", 999 + " [1, 2, 4, 3]\n", 1000 + " [1, 3, 4, 2]\n", 1001 + " [1, 4, 2, 3]\n", 1002 + " [2, 1, 3, 4]\n", 1003 + " [2, 3, 1, 4]\n", 1004 + " [2, 4, 3, 1]\n", 1005 + " [3, 1, 2, 4]\n", 1006 + " [3, 2, 4, 1]\n", 1007 + " [3, 4, 2, 1]\n", 1008 + " [4, 1, 3, 2]\n", 1009 + " [4, 2, 1, 3]\n", 1010 + " [4, 3, 1, 2]" 1011 + ] 1012 + }, 1013 + "execution_count": 4, 1014 + "metadata": {}, 1015 + "output_type": "execute_result" 1016 + } 1017 + ], 1018 + "source": [ 1019 + "costas_4x4" 1020 + ] 1021 + }, 1022 + { 1023 + "cell_type": "code", 1024 + "execution_count": 6, 1025 + "id": "85b4de41-4ba6-49a6-9bc8-4e52b68c760b", 1026 + "metadata": {}, 1027 + "outputs": [ 1028 + { 1029 + "data": { 1030 + "text/plain": [ 1031 + "12-element Vector{Vector{Int64}}:\n", 1032 + " [1, 2, 4, 3]\n", 1033 + " [1, 3, 4, 2]\n", 1034 + " [1, 4, 2, 3]\n", 1035 + " [2, 1, 3, 4]\n", 1036 + " [2, 3, 1, 4]\n", 1037 + " [2, 4, 3, 1]\n", 1038 + " [3, 1, 2, 4]\n", 1039 + " [3, 2, 4, 1]\n", 1040 + " [3, 4, 2, 1]\n", 1041 + " [4, 1, 3, 2]\n", 1042 + " [4, 2, 1, 3]\n", 1043 + " [4, 3, 1, 2]" 1044 + ] 1045 + }, 1046 + "execution_count": 6, 1047 + "metadata": {}, 1048 + "output_type": "execute_result" 1049 + } 1050 + ], 1051 + "source": [ 1052 + "lst = copy(costas_4x4)" 1053 + ] 1054 + }, 1055 + { 1056 + "cell_type": "code", 1057 + "execution_count": 8, 1058 + "id": "024f14ce-bbad-4b3c-a038-56e9e7e0b801", 1059 + "metadata": {}, 1060 + "outputs": [ 1061 + { 1062 + "data": { 1063 + "text/plain": [ 1064 + "13-element Vector{Vector{Int64}}:\n", 1065 + " [1, 2, 4, 3]\n", 1066 + " [1, 3, 4, 2]\n", 1067 + " [1, 4, 2, 3]\n", 1068 + " [2, 1, 3, 4]\n", 1069 + " [2, 3, 1, 4]\n", 1070 + " [2, 4, 3, 1]\n", 1071 + " [3, 1, 2, 4]\n", 1072 + " [3, 2, 4, 1]\n", 1073 + " [3, 4, 2, 1]\n", 1074 + " [4, 1, 3, 2]\n", 1075 + " [4, 2, 1, 3]\n", 1076 + " [4, 3, 1, 2]\n", 1077 + " [3]" 1078 + ] 1079 + }, 1080 + "execution_count": 8, 1081 + "metadata": {}, 1082 + "output_type": "execute_result" 1083 + } 1084 + ], 1085 + "source": [ 1086 + "push!(lst,[3])" 1087 + ] 1088 + }, 1089 + { 1090 + "cell_type": "code", 1091 + "execution_count": 9, 1092 + "id": "b6984319-851e-41aa-a023-4fb222c248bc", 1093 + "metadata": {}, 1094 + "outputs": [ 1095 + { 1096 + "data": { 1097 + "text/plain": [ 1098 + "12-element Vector{Vector{Int64}}:\n", 1099 + " [1, 2, 4, 3]\n", 1100 + " [1, 3, 4, 2]\n", 1101 + " [1, 4, 2, 3]\n", 1102 + " [2, 1, 3, 4]\n", 1103 + " [2, 3, 1, 4]\n", 1104 + " [2, 4, 3, 1]\n", 1105 + " [3, 1, 2, 4]\n", 1106 + " [3, 2, 4, 1]\n", 1107 + " [3, 4, 2, 1]\n", 1108 + " [4, 1, 3, 2]\n", 1109 + " [4, 2, 1, 3]\n", 1110 + " [4, 3, 1, 2]" 1111 + ] 1112 + }, 1113 + "execution_count": 9, 1114 + "metadata": {}, 1115 + "output_type": "execute_result" 1116 + } 1117 + ], 1118 + "source": [ 1119 + "costas_4x4" 1120 + ] 1121 + }, 1122 + { 1123 + "cell_type": "code", 1124 + "execution_count": 27, 1125 + "id": "ea43d891-12c2-48df-9187-d7a72d84e31f", 1126 + "metadata": {}, 1127 + "outputs": [ 1128 + { 1129 + "data": { 1130 + "text/plain": [ 1131 + "29-element Vector{Integer}:\n", 1132 + " 9\n", 1133 + " 27\n", 1134 + " 20\n", 1135 + " 11\n", 1136 + " 25\n", 1137 + " 6\n", 1138 + " 21\n", 1139 + " 19\n", 1140 + " 1\n", 1141 + " 28\n", 1142 + " 4\n", 1143 + " 13\n", 1144 + " 12\n", 1145 + " ⋮\n", 1146 + " 16\n", 1147 + " 8\n", 1148 + " 3\n", 1149 + " 7\n", 1150 + " 26\n", 1151 + " 29\n", 1152 + " 15\n", 1153 + " 5\n", 1154 + " 22\n", 1155 + " 2\n", 1156 + " 10\n", 1157 + " 23" 1158 + ] 1159 + }, 1160 + "execution_count": 27, 1161 + "metadata": {}, 1162 + "output_type": "execute_result" 1163 + } 1164 + ], 1165 + "source": [ 1166 + "lst = lempel(31)[1]" 1167 + ] 1168 + }, 1169 + { 1170 + "cell_type": "code", 1171 + "execution_count": 28, 1172 + "id": "d5168b88-2176-48c7-a9c9-11fe3237767e", 1173 + "metadata": {}, 1174 + "outputs": [ 1175 + { 1176 + "name": "stdout", 1177 + "output_type": "stream", 1178 + "text": [ 1179 + "6 6\n" 1180 + ] 1181 + } 1182 + ], 1183 + "source": [ 1184 + "for i in 1:length(lst)\n", 1185 + " if lst[i] == i\n", 1186 + " println(lst[i], ' ', i)\n", 1187 + " end\n", 1188 + "end" 1189 + ] 1190 + }, 1191 + { 1192 + "cell_type": "code", 1193 + "execution_count": 25, 1194 + "id": "5840c9f4-ff21-4c25-b142-e27d0a01dc20", 1195 + "metadata": {}, 1196 + "outputs": [ 1197 + { 1198 + "data": { 1199 + "text/plain": [ 1200 + "30-element Vector{Integer}:\n", 1201 + " 9\n", 1202 + " 27\n", 1203 + " 20\n", 1204 + " 11\n", 1205 + " 25\n", 1206 + " 6\n", 1207 + " 21\n", 1208 + " 19\n", 1209 + " 1\n", 1210 + " 28\n", 1211 + " 4\n", 1212 + " 13\n", 1213 + " 12\n", 1214 + " ⋮\n", 1215 + " 8\n", 1216 + " 3\n", 1217 + " 7\n", 1218 + " 26\n", 1219 + " 29\n", 1220 + " 15\n", 1221 + " 5\n", 1222 + " 22\n", 1223 + " 2\n", 1224 + " 10\n", 1225 + " 23\n", 1226 + " 30" 1227 + ] 1228 + }, 1229 + "execution_count": 25, 1230 + "metadata": {}, 1231 + "output_type": "execute_result" 1232 + } 1233 + ], 1234 + "source": [ 1235 + "\n", 1236 + "push!(lst, 30)" 1237 + ] 1238 + }, 1239 + { 1240 + "cell_type": "code", 1241 + "execution_count": 30, 1242 + "id": "9887c630-5b65-4105-b39f-80daf59d8fe6", 1243 + "metadata": {}, 1244 + "outputs": [ 1245 + { 1246 + "data": { 1247 + "text/plain": [ 1248 + "false" 1249 + ] 1250 + }, 1251 + "execution_count": 30, 1252 + "metadata": {}, 1253 + "output_type": "execute_result" 1254 + } 1255 + ], 1256 + "source": [ 1257 + "iscostas([4,5,3,1,2])" 1258 + ] 1259 + }, 1260 + { 1261 + "cell_type": "code", 1262 + "execution_count": 32, 1263 + "id": "60afa128-2bd5-4d24-b324-847db1c86426", 1264 + "metadata": {}, 1265 + "outputs": [ 1266 + { 1267 + "data": { 1268 + "text/plain": [ 1269 + "12-element Vector{Int64}:\n", 1270 + " 2\n", 1271 + " 3\n", 1272 + " 5\n", 1273 + " 7\n", 1274 + " 11\n", 1275 + " 13\n", 1276 + " 17\n", 1277 + " 19\n", 1278 + " 23\n", 1279 + " 29\n", 1280 + " 31\n", 1281 + " 37" 1282 + ] 1283 + }, 1284 + "execution_count": 32, 1285 + "metadata": {}, 1286 + "output_type": "execute_result" 1287 + } 1288 + ], 1289 + "source": [ 1290 + "primes(40)" 1291 + ] 1292 + }, 1293 + { 1294 + "cell_type": "code", 1295 + "execution_count": 36, 1296 + "id": "7ba9a47b-889f-47db-81cd-59f4cf0ffc33", 1297 + "metadata": {}, 1298 + "outputs": [ 1299 + { 1300 + "data": { 1301 + "text/plain": [ 1302 + "35-element Vector{Integer}:\n", 1303 + " 18\n", 1304 + " 8\n", 1305 + " 14\n", 1306 + " 31\n", 1307 + " 27\n", 1308 + " 30\n", 1309 + " 22\n", 1310 + " 2\n", 1311 + " 32\n", 1312 + " 11\n", 1313 + " 10\n", 1314 + " 28\n", 1315 + " 15\n", 1316 + " ⋮\n", 1317 + " 34\n", 1318 + " 17\n", 1319 + " 19\n", 1320 + " 5\n", 1321 + " 12\n", 1322 + " 33\n", 1323 + " 6\n", 1324 + " 4\n", 1325 + " 9\n", 1326 + " 29\n", 1327 + " 24\n", 1328 + " 35" 1329 + ] 1330 + }, 1331 + "execution_count": 36, 1332 + "metadata": {}, 1333 + "output_type": "execute_result" 1334 + } 1335 + ], 1336 + "source": [ 1337 + "lst = lempel(37)[1]" 1338 + ] 1339 + }, 1340 + { 1341 + "cell_type": "code", 1342 + "execution_count": 44, 1343 + "id": "1ba968f1-e5fe-44a0-bea5-8631e9594024", 1344 + "metadata": {}, 1345 + "outputs": [ 1346 + { 1347 + "data": { 1348 + "text/plain": [ 1349 + "false" 1350 + ] 1351 + }, 1352 + "execution_count": 44, 1353 + "metadata": {}, 1354 + "output_type": "execute_result" 1355 + } 1356 + ], 1357 + "source": [ 1358 + "lst = lempel(37)[1]\n", 1359 + "lst = [lst[i] for i in 1:(length(lst) - 1)]\n", 1360 + "lst[24] = lst[34]\n", 1361 + "lst = [lst[i] for i in 1:(length(lst) - 1)]\n", 1362 + "lst[29] = lst[33]\n", 1363 + "lst = [lst[i] for i in 1:(length(lst) - 1)]\n", 1364 + "iscostas(lst)" 1365 + ] 1366 + }, 1367 + { 1368 + "cell_type": "code", 1369 + "execution_count": 46, 1370 + "id": "a137ecde-01da-434c-81b1-d9609acc37ef", 1371 + "metadata": {}, 1372 + "outputs": [ 1373 + { 1374 + "name": "stdout", 1375 + "output_type": "stream", 1376 + "text": [ 1377 + "2: 1\n", 1378 + "3: 1\n", 1379 + "5: 2\n", 1380 + "7: 2\n", 1381 + "11: 4\n", 1382 + "13: 4\n", 1383 + "17: 8\n", 1384 + "19: 6\n", 1385 + "23: 10\n", 1386 + "29: 12\n", 1387 + "31: 8\n", 1388 + "37: 12\n", 1389 + "41: 16\n", 1390 + "43: 12\n", 1391 + "47: 22\n", 1392 + "53: 24\n", 1393 + "59: 28\n", 1394 + "61: 16\n", 1395 + "67: 20\n" 1396 + ] 1397 + } 1398 + ], 1399 + "source": [ 1400 + "for p in primes(70)\n", 1401 + " println(\"$p: $(length(lempel(p)))\")\n", 1402 + "end" 1403 + ] 1404 + }, 1405 + { 1406 + "cell_type": "code", 1407 + "execution_count": 2, 1408 + "id": "f1185f41-b5db-4d0c-b278-f069c8755df6", 1409 + "metadata": {}, 1410 + "outputs": [ 1411 + { 1412 + "data": { 1413 + "text/plain": [ 1414 + "telephone (generic function with 1 method)" 1415 + ] 1416 + }, 1417 + "execution_count": 2, 1418 + "metadata": {}, 1419 + "output_type": "execute_result" 1420 + } 1421 + ], 1422 + "source": [ 1423 + "function telephone(n)\n", 1424 + " n <= 1 ? 1 : telephone(n-1) + (n - 1) * telephone(n - 2)\n", 1425 + "end" 1426 + ] 1427 + }, 1428 + { 1429 + "cell_type": "code", 1430 + "execution_count": 48, 1431 + "id": "e1163acd-0287-4b86-b4ff-0aa56c87aa89", 1432 + "metadata": {}, 1433 + "outputs": [ 1434 + { 1435 + "data": { 1436 + "text/plain": [ 1437 + "4034315351021199616" 1438 + ] 1439 + }, 1440 + "execution_count": 48, 1441 + "metadata": {}, 1442 + "output_type": "execute_result" 1443 + } 1444 + ], 1445 + "source": [ 1446 + "telephone(32)" 1447 + ] 1448 + }, 1449 + { 1450 + "cell_type": "code", 1451 + "execution_count": 4, 1452 + "id": "fed2bc43-df75-421b-8a41-5b4519183103", 1453 + "metadata": {}, 1454 + "outputs": [ 1455 + { 1456 + "name": "stdout", 1457 + "output_type": "stream", 1458 + "text": [ 1459 + "1\n", 1460 + "2\n", 1461 + "4\n", 1462 + "10\n", 1463 + "26\n", 1464 + "76\n", 1465 + "232\n", 1466 + "764\n", 1467 + "2620\n", 1468 + "9496\n" 1469 + ] 1470 + } 1471 + ], 1472 + "source": [ 1473 + "for i ∈ 1:10\n", 1474 + " println(telephone(i))\n", 1475 + "end" 1476 + ] 1477 + }, 1478 + { 1479 + "cell_type": "code", 1480 + "execution_count": 8, 1481 + "id": "add0d34d-16c7-464b-9827-0b0deb904541", 1482 + "metadata": {}, 1483 + "outputs": [ 1484 + { 1485 + "data": { 1486 + "text/plain": [ 1487 + "12-element Vector{Vector{Integer}}:\n", 1488 + " [2, 4, 8, 16, 32, 27, 17, 34, 31, 25 … 6, 12, 24, 11, 22, 7, 14, 28, 19, 1]\n", 1489 + " [5, 25, 14, 33, 17, 11, 18, 16, 6, 30 … 31, 7, 35, 27, 24, 9, 8, 3, 15, 1]\n", 1490 + " [13, 21, 14, 34, 35, 11, 32, 9, 6, 4 … 31, 33, 22, 27, 18, 12, 8, 30, 20, 1]\n", 1491 + " [15, 3, 8, 9, 24, 27, 35, 7, 31, 21 … 6, 16, 18, 11, 17, 33, 14, 25, 5, 1]\n", 1492 + " [17, 30, 29, 12, 19, 27, 15, 33, 6, 28 … 31, 9, 5, 11, 2, 34, 23, 21, 24, 1]\n", 1493 + " [18, 28, 23, 7, 15, 11, 13, 12, 31, 3 … 6, 34, 20, 27, 5, 16, 29, 4, 35, 1]\n", 1494 + " [19, 28, 14, 7, 22, 11, 24, 12, 6, 3 … 31, 34, 17, 27, 32, 16, 8, 4, 2, 1]\n", 1495 + " [20, 30, 8, 12, 18, 27, 22, 33, 31, 28 … 6, 9, 32, 11, 35, 34, 14, 21, 13, 1]\n", 1496 + " [22, 3, 29, 9, 13, 27, 2, 7, 6, 21 … 31, 16, 19, 11, 20, 33, 23, 25, 32, 1]\n", 1497 + " [24, 21, 23, 34, 2, 11, 5, 9, 31, 4 … 6, 33, 15, 27, 19, 12, 29, 30, 17, 1]\n", 1498 + " [32, 25, 23, 33, 20, 11, 19, 16, 31, 30 … 6, 7, 2, 27, 13, 9, 29, 3, 22, 1]\n", 1499 + " [35, 4, 29, 16, 5, 27, 20, 34, 6, 25 … 31, 12, 13, 11, 15, 7, 23, 28, 18, 1]" 1500 + ] 1501 + }, 1502 + "execution_count": 8, 1503 + "metadata": {}, 1504 + "output_type": "execute_result" 1505 + } 1506 + ], 1507 + "source": [ 1508 + "welch(37)" 1509 + ] 1510 + }, 1511 + { 1512 + "cell_type": "code", 1513 + "execution_count": 9, 1514 + "id": "e20cf1f6-44ae-4117-802e-31480d09752e", 1515 + "metadata": {}, 1516 + "outputs": [ 1517 + { 1518 + "data": { 1519 + "text/plain": [ 1520 + "true" 1521 + ] 1522 + }, 1523 + "execution_count": 9, 1524 + "metadata": {}, 1525 + "output_type": "execute_result" 1526 + } 1527 + ], 1528 + "source": [ 1529 + "iscostas([4,6,7,2,8,1,5,3])" 1530 + ] 1531 + }, 1532 + { 1533 + "cell_type": "code", 1534 + "execution_count": 46, 1535 + "id": "75a8b103-a13b-4ad1-a1fd-48fd509aad79", 1536 + "metadata": {}, 1537 + "outputs": [ 1538 + { 1539 + "data": { 1540 + "text/plain": [ 1541 + "ts (generic function with 1 method)" 1542 + ] 1543 + }, 1544 + "execution_count": 46, 1545 + "metadata": {}, 1546 + "output_type": "execute_result" 1547 + } 1548 + ], 1549 + "source": [ 1550 + "function ts(n::Integer)::Vector{Vector{Integer}}\n", 1551 + " out = [[1]]\n", 1552 + " for i ∈ 1:n\n", 1553 + " new_out = []\n", 1554 + " for vec ∈ out\n", 1555 + " println(vec)\n", 1556 + " verts = findverts(vec)\n", 1557 + " println(verts)\n", 1558 + " for vert ∈ verts\n", 1559 + " c = swapidx([copy(vec);[i+1]], vert, i)\n", 1560 + " push!(new_out, c)\n", 1561 + " println(\"$new_out, $i\")\n", 1562 + " end\n", 1563 + " push!(new_out, [copy(vec);[i+1]])\n", 1564 + " end\n", 1565 + " new_out\n", 1566 + " out = new_out\n", 1567 + " end\n", 1568 + " out\n", 1569 + "end" 1570 + ] 1571 + }, 1572 + { 1573 + "cell_type": "code", 1574 + "execution_count": 47, 1575 + "id": "8c7d4ef8-5a4b-455a-b434-7bb4c58d629d", 1576 + "metadata": {}, 1577 + "outputs": [ 1578 + { 1579 + "name": "stdout", 1580 + "output_type": "stream", 1581 + "text": [ 1582 + "[1]\n", 1583 + "Any[1]\n", 1584 + "Any[[1, 2]], 1\n", 1585 + "[1, 2]\n", 1586 + "Any[1, 2]\n", 1587 + "Any[[2, 1, 3]], 2\n", 1588 + "Any[[2, 1, 3], [1, 2, 3]], 2\n", 1589 + "[1, 2]\n", 1590 + "Any[1, 2]\n", 1591 + "Any[[2, 1, 3], [1, 2, 3], [1, 2, 3], [2, 1, 3]], 2\n", 1592 + "Any[[2, 1, 3], [1, 2, 3], [1, 2, 3], [2, 1, 3], [1, 2, 3]], 2\n" 1593 + ] 1594 + }, 1595 + { 1596 + "data": { 1597 + "text/plain": [ 1598 + "6-element Vector{Vector{Integer}}:\n", 1599 + " [2, 1, 3]\n", 1600 + " [1, 2, 3]\n", 1601 + " [1, 2, 3]\n", 1602 + " [2, 1, 3]\n", 1603 + " [1, 2, 3]\n", 1604 + " [1, 2, 3]" 1605 + ] 1606 + }, 1607 + "execution_count": 47, 1608 + "metadata": {}, 1609 + "output_type": "execute_result" 1610 + } 1611 + ], 1612 + "source": [ 1613 + "ts(2)" 1614 + ] 1615 + }, 1616 + { 1617 + "cell_type": "code", 1618 + "execution_count": 38, 1619 + "id": "e2708920-52cd-4189-a1ea-ed60d6b0c82d", 1620 + "metadata": {}, 1621 + "outputs": [ 1622 + { 1623 + "data": { 1624 + "text/plain": [ 1625 + "4-element Vector{Int64}:\n", 1626 + " 2\n", 1627 + " 1\n", 1628 + " 3\n", 1629 + " 4" 1630 + ] 1631 + }, 1632 + "execution_count": 38, 1633 + "metadata": {}, 1634 + "output_type": "execute_result" 1635 + } 1636 + ], 1637 + "source": [ 1638 + "[1]\n", 1639 + "\n", 1640 + "[1,2]\n", 1641 + "[2,1]\n", 1642 + "\n", 1643 + "[1,2,3]\n", 1644 + "[3,2,1]\n", 1645 + "[1,3,2]\n", 1646 + "[2,1,3]\n", 1647 + "\n", 1648 + "[4,2,3,1]\n", 1649 + "[1,4,3,2]\n", 1650 + "[1,2,4,3]\n", 1651 + "[1,2,3,4]\n", 1652 + "[3,4,1,2]\n", 1653 + "[3,2,1,4]\n", 1654 + "[4,3,2,1]\n", 1655 + "[1,3,2,4]\n", 1656 + "[2,1,4,3]\n", 1657 + "[2,1,3,4]" 1658 + ] 1659 + }, 1660 + { 1661 + "cell_type": "code", 1662 + "execution_count": 18, 1663 + "id": "b82ed301-bf08-4d21-8d01-f9861de83fca", 1664 + "metadata": {}, 1665 + "outputs": [ 1666 + { 1667 + "data": { 1668 + "text/plain": [ 1669 + "findverts (generic function with 2 methods)" 1670 + ] 1671 + }, 1672 + "execution_count": 18, 1673 + "metadata": {}, 1674 + "output_type": "execute_result" 1675 + } 1676 + ], 1677 + "source": [ 1678 + "function findverts(vec::Vector)::Vector\n", 1679 + " out = []\n", 1680 + " for i in 1:length(vec)\n", 1681 + " if vec[i] == i\n", 1682 + " push!(out, i)\n", 1683 + " end\n", 1684 + " end\n", 1685 + " out\n", 1686 + "end" 1687 + ] 1688 + }, 1689 + { 1690 + "cell_type": "code", 1691 + "execution_count": 12, 1692 + "id": "b224b927-2c2b-4734-9899-e2ffc5ec868f", 1693 + "metadata": {}, 1694 + "outputs": [ 1695 + { 1696 + "data": { 1697 + "text/plain": [ 1698 + "swapidx (generic function with 1 method)" 1699 + ] 1700 + }, 1701 + "execution_count": 12, 1702 + "metadata": {}, 1703 + "output_type": "execute_result" 1704 + } 1705 + ], 1706 + "source": [ 1707 + "function swapidx(vec::Vector{T}, i::Integer, j::Integer)::Vector{T} where T\n", 1708 + " tmp = vec[i]\n", 1709 + " vec[i] = vec[j]\n", 1710 + " vec[j] = tmp\n", 1711 + " vec\n", 1712 + "end" 1713 + ] 1714 + }, 1715 + { 1716 + "cell_type": "code", 1717 + "execution_count": 32, 1718 + "id": "f7473e8c-2e80-420f-95f6-8ea32640bb3a", 1719 + "metadata": {}, 1720 + "outputs": [ 1721 + { 1722 + "data": { 1723 + "text/plain": [ 1724 + "3-element Vector{Int64}:\n", 1725 + " 2\n", 1726 + " 1\n", 1727 + " 3" 1728 + ] 1729 + }, 1730 + "execution_count": 32, 1731 + "metadata": {}, 1732 + "output_type": "execute_result" 1733 + } 1734 + ], 1735 + "source": [ 1736 + "swapidx([1,2,3],1,2)" 1737 + ] 1738 + }, 1739 + { 1740 + "cell_type": "code", 1741 + "execution_count": 33, 1742 + "id": "6c3f104f-2ff0-489d-84ea-1602e7adf9f2", 1743 + "metadata": {}, 1744 + "outputs": [ 1745 + { 1746 + "data": { 1747 + "text/plain": [ 1748 + "6-element Vector{Int64}:\n", 1749 + " 1\n", 1750 + " 2\n", 1751 + " 3\n", 1752 + " 4\n", 1753 + " 5\n", 1754 + " 6" 1755 + ] 1756 + }, 1757 + "execution_count": 33, 1758 + "metadata": {}, 1759 + "output_type": "execute_result" 1760 + } 1761 + ], 1762 + "source": [ 1763 + "a = [1,2,3]\n", 1764 + "b = [4,5,6]\n", 1765 + "[a;b]" 1766 + ] 1767 + }, 1768 + { 1769 + "cell_type": "code", 1770 + "execution_count": 49, 1771 + "id": "5067937c-7e15-4991-b1db-47ccab9864ee", 1772 + "metadata": {}, 1773 + "outputs": [ 1774 + { 1775 + "data": { 1776 + "text/plain": [ 1777 + "4-element Vector{Vector{Integer}}:\n", 1778 + " [2, 4, 8, 5, 10, 9, 7, 3, 6, 1]\n", 1779 + " [6, 3, 7, 9, 10, 5, 8, 4, 2, 1]\n", 1780 + " [7, 5, 2, 3, 10, 4, 6, 9, 8, 1]\n", 1781 + " [8, 9, 6, 4, 10, 3, 2, 5, 7, 1]" 1782 + ] 1783 + }, 1784 + "execution_count": 49, 1785 + "metadata": {}, 1786 + "output_type": "execute_result" 1787 + } 1788 + ], 1789 + "source": [ 1790 + "welch(11)" 1791 + ] 1792 + }, 1793 + { 1794 + "cell_type": "code", 1795 + "execution_count": 22, 1796 + "id": "bce5e8c4-a9ae-43ce-8a39-47d8531ff169", 1797 + "metadata": {}, 1798 + "outputs": [ 1799 + { 1800 + "data": { 1801 + "text/plain": [ 1802 + "2-element Vector{Vector{Integer}}:\n", 1803 + " [3, 2, 6, 4, 5, 1]\n", 1804 + " [5, 4, 6, 2, 3, 1]" 1805 + ] 1806 + }, 1807 + "execution_count": 22, 1808 + "metadata": {}, 1809 + "output_type": "execute_result" 1810 + } 1811 + ], 1812 + "source": [ 1813 + "welch(7)" 1814 + ] 1815 + }, 1816 + { 1817 + "cell_type": "code", 1818 + "execution_count": 7, 1819 + "id": "f95381ee-d182-4ae7-a96c-457502509933", 1820 + "metadata": {}, 1821 + "outputs": [ 1822 + { 1823 + "data": { 1824 + "text/plain": [ 1825 + "true" 1826 + ] 1827 + }, 1828 + "execution_count": 7, 1829 + "metadata": {}, 1830 + "output_type": "execute_result" 1831 + } 1832 + ], 1833 + "source": [ 1834 + "iscostas([6,2,1,4,5,3])" 1835 + ] 1836 + }, 1837 + { 1838 + "cell_type": "code", 1839 + "execution_count": 8, 1840 + "id": "9f08cdc1-d944-4037-b13f-0e77893aa9dd", 1841 + "metadata": {}, 1842 + "outputs": [ 1843 + { 1844 + "data": { 1845 + "text/plain": [ 1846 + "4-element Vector{Vector{Integer}}:\n", 1847 + " [5, 3, 2, 7, 1, 8, 4, 6, 9]\n", 1848 + " [1, 4, 6, 2, 9, 3, 8, 7, 5]\n", 1849 + " [2, 1, 5, 8, 3, 9, 7, 4, 6]\n", 1850 + " [4, 6, 3, 1, 7, 2, 5, 9, 8]" 1851 + ] 1852 + }, 1853 + "execution_count": 8, 1854 + "metadata": {}, 1855 + "output_type": "execute_result" 1856 + } 1857 + ], 1858 + "source": [ 1859 + "lempel(11)" 1860 + ] 1861 + }, 1862 + { 1863 + "cell_type": "code", 1864 + "execution_count": 15, 1865 + "id": "3a764240-e578-42f4-bd3f-ffb0d08e6f37", 1866 + "metadata": {}, 1867 + "outputs": [ 1868 + { 1869 + "data": { 1870 + "text/plain": [ 1871 + "false" 1872 + ] 1873 + }, 1874 + "execution_count": 15, 1875 + "metadata": {}, 1876 + "output_type": "execute_result" 1877 + } 1878 + ], 1879 + "source": [ 1880 + "iscostas([10,3,4,6,2,7,1,9,8,5,10,3,4,6,2,7,1,9,8,5])" 1881 + ] 1882 + }, 1883 + { 1884 + "cell_type": "code", 1885 + "execution_count": 19, 1886 + "id": "4eef15ae-22e6-4924-8fbb-a519f8a98a22", 1887 + "metadata": {}, 1888 + "outputs": [ 1889 + { 1890 + "data": { 1891 + "text/plain": [ 1892 + "false" 1893 + ] 1894 + }, 1895 + "execution_count": 19, 1896 + "metadata": {}, 1897 + "output_type": "execute_result" 1898 + } 1899 + ], 1900 + "source": [ 1901 + "iscostas([5, 3, 2, 7, 1, 8, 4, 6, 9, '*', 5, 3, 2, 7, 1, 8, 4, 6, 9], asterisk_predicate)" 1902 + ] 1903 + }, 1904 + { 1905 + "cell_type": "code", 1906 + "execution_count": 21, 1907 + "id": "c19f8e0d-b80f-4e70-ba6c-6be69f082872", 1908 + "metadata": {}, 1909 + "outputs": [ 1910 + { 1911 + "data": { 1912 + "text/plain": [ 1913 + "false" 1914 + ] 1915 + }, 1916 + "execution_count": 21, 1917 + "metadata": {}, 1918 + "output_type": "execute_result" 1919 + } 1920 + ], 1921 + "source": [ 1922 + "iscostas([2,4,3,5])" 1923 + ] 1924 + }, 1925 + { 1926 + "cell_type": "code", 1927 + "execution_count": 25, 1928 + "id": "9dcb0b72-9f2d-4d4a-b9d0-8a25beeb8f9b", 1929 + "metadata": {}, 1930 + "outputs": [ 1931 + { 1932 + "name": "stdout", 1933 + "output_type": "stream", 1934 + "text": [ 1935 + "1 1 1 1 1 1 1 1 1 1 \n", 1936 + "2 4 8 5 10 9 7 3 6 1 \n", 1937 + "3 9 5 4 1 3 9 5 4 1 \n", 1938 + "4 5 9 3 1 4 5 9 3 1 \n", 1939 + "5 3 4 9 1 5 3 4 9 1 \n", 1940 + "6 3 7 9 10 5 8 4 2 1 \n", 1941 + "7 5 2 3 10 4 6 9 8 1 \n", 1942 + "8 9 6 4 10 3 2 5 7 1 \n", 1943 + "9 4 3 5 1 9 4 3 5 1 \n", 1944 + "10 1 10 1 10 1 10 1 10 1 \n", 1945 + "0 0 0 0 0 0 0 0 0 0 \n" 1946 + ] 1947 + } 1948 + ], 1949 + "source": [ 1950 + "for i in 1:11\n", 1951 + " pow = i\n", 1952 + " for _ in 1:10\n", 1953 + " print(pow % 11, ' ')\n", 1954 + " pow *= i\n", 1955 + " end\n", 1956 + " println()\n", 1957 + "end" 1958 + ] 1959 + }, 1960 + { 1961 + "cell_type": "code", 1962 + "execution_count": 3, 1963 + "id": "f8dfb3a2-d636-4ef3-89c9-82c24b18d282", 1964 + "metadata": {}, 1965 + "outputs": [ 1966 + { 1967 + "data": { 1968 + "text/plain": [ 1969 + "4-element Vector{Vector{Integer}}:\n", 1970 + " [2, 4, 8, 5, 10, 9, 7, 3, 6, 1]\n", 1971 + " [6, 3, 7, 9, 10, 5, 8, 4, 2, 1]\n", 1972 + " [7, 5, 2, 3, 10, 4, 6, 9, 8, 1]\n", 1973 + " [8, 9, 6, 4, 10, 3, 2, 5, 7, 1]" 1974 + ] 1975 + }, 1976 + "execution_count": 3, 1977 + "metadata": {}, 1978 + "output_type": "execute_result" 1979 + } 1980 + ], 1981 + "source": [ 1982 + "welch(11)" 1983 + ] 1984 + }, 1985 + { 1986 + "cell_type": "code", 1987 + "execution_count": 2, 1988 + "id": "12fc9576-c665-4db5-8742-613337dd0657", 1989 + "metadata": {}, 1990 + "outputs": [ 1991 + { 1992 + "data": { 1993 + "text/plain": [ 1994 + "2-element Vector{Vector{Integer}}:\n", 1995 + " [5, 3, 2, 4, 1]\n", 1996 + " [5, 2, 4, 3, 1]" 1997 + ] 1998 + }, 1999 + "execution_count": 2, 2000 + "metadata": {}, 2001 + "output_type": "execute_result" 2002 + } 2003 + ], 2004 + "source": [ 2005 + "lempel(7)" 2006 + ] 2007 + }, 2008 + { 2009 + "cell_type": "code", 2010 + "execution_count": 31, 2011 + "id": "31389c6e-17b6-41a6-ba3e-d7be1891ffe0", 2012 + "metadata": {}, 2013 + "outputs": [ 2014 + { 2015 + "data": { 2016 + "text/plain": [ 2017 + "2-element Vector{Vector{Integer}}:\n", 2018 + " [5, 3, 2, 4, 1]\n", 2019 + " [5, 2, 4, 3, 1]" 2020 + ] 2021 + }, 2022 + "execution_count": 31, 2023 + "metadata": {}, 2024 + "output_type": "execute_result" 2025 + } 2026 + ], 2027 + "source": [ 2028 + "lempel(7)" 2029 + ] 2030 + }, 2031 + { 2032 + "cell_type": "code", 2033 + "execution_count": 30, 2034 + "id": "c7e406e5-b73a-4152-b435-1a7e847071b7", 2035 + "metadata": {}, 2036 + "outputs": [ 2037 + { 2038 + "data": { 2039 + "text/plain": [ 2040 + "true" 2041 + ] 2042 + }, 2043 + "execution_count": 30, 2044 + "metadata": {}, 2045 + "output_type": "execute_result" 2046 + } 2047 + ], 2048 + "source": [ 2049 + "iscostas([[6, 10, 5, 7, 3, 1, 4, 9, 8, 2, 11]; '*'], asterisk_predicate)" 2050 + ] 2051 + }, 2052 + { 2053 + "cell_type": "code", 2054 + "execution_count": 22, 2055 + "id": "64d4f5be-05da-47d5-9bef-ef0408ceb632", 2056 + "metadata": {}, 2057 + "outputs": [ 2058 + { 2059 + "data": { 2060 + "text/plain": [ 2061 + "4-element Vector{Vector{Integer}}:\n", 2062 + " [5, 3, 2, 7, 1, 8, 4, 6, 9]\n", 2063 + " [1, 4, 6, 2, 9, 3, 8, 7, 5]\n", 2064 + " [2, 1, 5, 8, 3, 9, 7, 4, 6]\n", 2065 + " [4, 6, 3, 1, 7, 2, 5, 9, 8]" 2066 + ] 2067 + }, 2068 + "execution_count": 22, 2069 + "metadata": {}, 2070 + "output_type": "execute_result" 2071 + } 2072 + ], 2073 + "source": [ 2074 + "lempel(11)" 2075 + ] 2076 + }, 2077 + { 2078 + "cell_type": "code", 2079 + "execution_count": 32, 2080 + "id": "52989e6a-f04a-421c-8447-f49c652fab37", 2081 + "metadata": {}, 2082 + "outputs": [ 2083 + { 2084 + "data": { 2085 + "text/plain": [ 2086 + "4-element Vector{Vector{Integer}}:\n", 2087 + " [5, 3, 2, 7, 1, 8, 4, 6, 9]\n", 2088 + " [1, 4, 6, 2, 9, 3, 8, 7, 5]\n", 2089 + " [2, 1, 5, 8, 3, 9, 7, 4, 6]\n", 2090 + " [4, 6, 3, 1, 7, 2, 5, 9, 8]" 2091 + ] 2092 + }, 2093 + "execution_count": 32, 2094 + "metadata": {}, 2095 + "output_type": "execute_result" 2096 + } 2097 + ], 2098 + "source": [ 2099 + "lempel(11)" 2100 + ] 2101 + }, 2102 + { 2103 + "cell_type": "code", 2104 + "execution_count": 33, 2105 + "id": "328b4c5b-d862-49cb-9d6b-dfb14aeb2a02", 2106 + "metadata": {}, 2107 + "outputs": [ 2108 + { 2109 + "data": { 2110 + "text/plain": [ 2111 + "4-element Vector{Vector{Integer}}:\n", 2112 + " [2, 4, 8, 5, 10, 9, 7, 3, 6, 1]\n", 2113 + " [6, 3, 7, 9, 10, 5, 8, 4, 2, 1]\n", 2114 + " [7, 5, 2, 3, 10, 4, 6, 9, 8, 1]\n", 2115 + " [8, 9, 6, 4, 10, 3, 2, 5, 7, 1]" 2116 + ] 2117 + }, 2118 + "execution_count": 33, 2119 + "metadata": {}, 2120 + "output_type": "execute_result" 2121 + } 2122 + ], 2123 + "source": [ 2124 + "welch(11)" 2125 + ] 2126 + }, 2127 + { 2128 + "cell_type": "code", 2129 + "execution_count": 35, 2130 + "id": "c4b1a2ad-4968-46d8-a08d-fcbf4abfbd27", 2131 + "metadata": {}, 2132 + "outputs": [ 2133 + { 2134 + "data": { 2135 + "text/plain": [ 2136 + "Vector{Integer}[]" 2137 + ] 2138 + }, 2139 + "execution_count": 35, 2140 + "metadata": {}, 2141 + "output_type": "execute_result" 2142 + } 2143 + ], 2144 + "source": [ 2145 + "welch(9)" 2146 + ] 2147 + }, 2148 + { 2149 + "cell_type": "code", 2150 + "execution_count": 38, 2151 + "id": "618899d2-09b8-49dd-8087-dd73b42adf41", 2152 + "metadata": {}, 2153 + "outputs": [ 2154 + { 2155 + "name": "stderr", 2156 + "output_type": "stream", 2157 + "text": [ 2158 + "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", 2159 + "\u001b[32m\u001b[1m Installed\u001b[22m\u001b[39m CEnum ──────────────── v0.5.0\n", 2160 + "\u001b[32m\u001b[1m Installed\u001b[22m\u001b[39m libcxxwrap_julia_jll ─ v0.13.2+0\n", 2161 + "\u001b[32m\u001b[1m Installed\u001b[22m\u001b[39m z3_jll ─────────────── v4.13.3+0\n", 2162 + "\u001b[32m\u001b[1m Installed\u001b[22m\u001b[39m Z3 ─────────────────── v1.0.3\n", 2163 + "\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m `~/.julia/environments/v1.10/Project.toml`\n", 2164 + " \u001b[90m[06b161dc] \u001b[39m\u001b[92m+ Z3 v1.0.3\u001b[39m\n", 2165 + "\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m `~/.julia/environments/v1.10/Manifest.toml`\n", 2166 + " \u001b[90m[fa961155] \u001b[39m\u001b[92m+ CEnum v0.5.0\u001b[39m\n", 2167 + " \u001b[90m[06b161dc] \u001b[39m\u001b[92m+ Z3 v1.0.3\u001b[39m\n", 2168 + " \u001b[90m[3eaa8342] \u001b[39m\u001b[92m+ libcxxwrap_julia_jll v0.13.2+0\u001b[39m\n", 2169 + " \u001b[90m[1bc4e1ec] \u001b[39m\u001b[92m+ z3_jll v4.13.3+0\u001b[39m\n", 2170 + " \u001b[90m[781609d7] \u001b[39m\u001b[92m+ GMP_jll v6.2.1+6\u001b[39m\n", 2171 + "\u001b[32m\u001b[1mPrecompiling\u001b[22m\u001b[39m project...\n", 2172 + "\u001b[32m ✓ \u001b[39m\u001b[90mGMP_jll\u001b[39m\n", 2173 + "\u001b[32m ✓ \u001b[39m\u001b[90mCEnum\u001b[39m\n", 2174 + "\u001b[32m ✓ \u001b[39m\u001b[90mlibcxxwrap_julia_jll\u001b[39m\n", 2175 + "\u001b[32m ✓ \u001b[39m\u001b[90mz3_jll\u001b[39m\n", 2176 + "\u001b[32m ✓ \u001b[39mZ3\n", 2177 + " 5 dependencies successfully precompiled in 2 seconds. 54 already precompiled.\n" 2178 + ] 2179 + } 2180 + ], 2181 + "source": [ 2182 + "Pkg.add(\"Z3\")" 2183 + ] 2184 + }, 2185 + { 2186 + "cell_type": "code", 2187 + "execution_count": 50, 2188 + "id": "4c9adcfb-1bfe-4891-923f-3d34130e124f", 2189 + "metadata": {}, 2190 + "outputs": [ 2191 + { 2192 + "ename": "LoadError", 2193 + "evalue": "MethodError: no method matching FuncDecl()\n\n\u001b[0mClosest candidates are:\n\u001b[0m FuncDecl(\u001b[91m::Context\u001b[39m, \u001b[91m::Ptr{Z3.Libz3._Z3_func_decl}\u001b[39m)\n\u001b[0m\u001b[90m @\u001b[39m \u001b[33mZ3\u001b[39m \u001b[90m~/.julia/packages/Z3/L6TVj/src/\u001b[39m\u001b[90m\u001b[4mZ3.jl:150\u001b[24m\u001b[39m\n\u001b[0m FuncDecl(\u001b[91m::String\u001b[39m, \u001b[91m::Vector{Sort}\u001b[39m, \u001b[91m::Sort\u001b[39m)\n\u001b[0m\u001b[90m @\u001b[39m \u001b[33mZ3\u001b[39m \u001b[90m~/.julia/packages/Z3/L6TVj/src/\u001b[39m\u001b[90m\u001b[4mZ3.jl:174\u001b[24m\u001b[39m\n\u001b[0m FuncDecl(\u001b[91m::String\u001b[39m, \u001b[91m::Vector{Sort}\u001b[39m, \u001b[91m::Sort\u001b[39m, \u001b[91m::Any\u001b[39m)\n\u001b[0m\u001b[90m @\u001b[39m \u001b[33mZ3\u001b[39m \u001b[90m~/.julia/packages/Z3/L6TVj/src/\u001b[39m\u001b[90m\u001b[4mZ3.jl:174\u001b[24m\u001b[39m\n", 2194 + "output_type": "error", 2195 + "traceback": [ 2196 + "MethodError: no method matching FuncDecl()\n\n\u001b[0mClosest candidates are:\n\u001b[0m FuncDecl(\u001b[91m::Context\u001b[39m, \u001b[91m::Ptr{Z3.Libz3._Z3_func_decl}\u001b[39m)\n\u001b[0m\u001b[90m @\u001b[39m \u001b[33mZ3\u001b[39m \u001b[90m~/.julia/packages/Z3/L6TVj/src/\u001b[39m\u001b[90m\u001b[4mZ3.jl:150\u001b[24m\u001b[39m\n\u001b[0m FuncDecl(\u001b[91m::String\u001b[39m, \u001b[91m::Vector{Sort}\u001b[39m, \u001b[91m::Sort\u001b[39m)\n\u001b[0m\u001b[90m @\u001b[39m \u001b[33mZ3\u001b[39m \u001b[90m~/.julia/packages/Z3/L6TVj/src/\u001b[39m\u001b[90m\u001b[4mZ3.jl:174\u001b[24m\u001b[39m\n\u001b[0m FuncDecl(\u001b[91m::String\u001b[39m, \u001b[91m::Vector{Sort}\u001b[39m, \u001b[91m::Sort\u001b[39m, \u001b[91m::Any\u001b[39m)\n\u001b[0m\u001b[90m @\u001b[39m \u001b[33mZ3\u001b[39m \u001b[90m~/.julia/packages/Z3/L6TVj/src/\u001b[39m\u001b[90m\u001b[4mZ3.jl:174\u001b[24m\u001b[39m\n", 2197 + "", 2198 + "Stacktrace:", 2199 + " [1] top-level scope", 2200 + " @ In[50]:1" 2201 + ] 2202 + } 2203 + ], 2204 + "source": [ 2205 + "Z3.FuncDecl()" 2206 + ] 2207 + }, 2208 + { 2209 + "cell_type": "code", 2210 + "execution_count": 12, 2211 + "id": "49d55ff1-4346-4682-b41b-8fd6fde14ee0", 2212 + "metadata": {}, 2213 + "outputs": [ 2214 + { 2215 + "data": { 2216 + "text/plain": [ 2217 + "#9 (generic function with 1 method)" 2218 + ] 2219 + }, 2220 + "execution_count": 12, 2221 + "metadata": {}, 2222 + "output_type": "execute_result" 2223 + } 2224 + ], 2225 + "source": [ 2226 + "f1 = Base.Fix1\n", 2227 + "f2 = Base.Fix2\n", 2228 + "p2 = x -> y -> (x, y)" 2229 + ] 2230 + }, 2231 + { 2232 + "cell_type": "code", 2233 + "execution_count": 13, 2234 + "id": "06a91f55-853e-45e6-8492-1856d37f48e1", 2235 + "metadata": {}, 2236 + "outputs": [ 2237 + { 2238 + "data": { 2239 + "text/plain": [ 2240 + "isprimitiveroot (generic function with 1 method)" 2241 + ] 2242 + }, 2243 + "execution_count": 13, 2244 + "metadata": {}, 2245 + "output_type": "execute_result" 2246 + } 2247 + ], 2248 + "source": [ 2249 + "function isprimitiveroot(prime::Integer, alpha::Integer)::Bool \n", 2250 + " not_one::Bool = all(powermod(alpha, i, prime) != prime - 1 for i in 1:((prime - 1) ÷ 2 - 1))\n", 2251 + " last_one::Bool = powermod(alpha, (prime - 1) ÷ 2, prime) == prime - 1\n", 2252 + " not_one && last_one\n", 2253 + "end" 2254 + ] 2255 + }, 2256 + { 2257 + "cell_type": "code", 2258 + "execution_count": 6, 2259 + "id": "5fd3614c-db37-44e2-8dbb-aa0393113100", 2260 + "metadata": {}, 2261 + "outputs": [ 2262 + { 2263 + "data": { 2264 + "text/plain": [ 2265 + "4-element Vector{Int64}:\n", 2266 + " 2\n", 2267 + " 6\n", 2268 + " 7\n", 2269 + " 11" 2270 + ] 2271 + }, 2272 + "execution_count": 6, 2273 + "metadata": {}, 2274 + "output_type": "execute_result" 2275 + } 2276 + ], 2277 + "source": [ 2278 + "filter(alpha -> isprimitiveroot(13, alpha), 2:13)" 2279 + ] 2280 + }, 2281 + { 2282 + "cell_type": "code", 2283 + "execution_count": 2, 2284 + "id": "95e22df0-0d20-4dac-aca3-cc8305702a58", 2285 + "metadata": {}, 2286 + "outputs": [ 2287 + { 2288 + "data": { 2289 + "text/plain": [ 2290 + "iscostasdbg (generic function with 2 methods)" 2291 + ] 2292 + }, 2293 + "execution_count": 2, 2294 + "metadata": {}, 2295 + "output_type": "execute_result" 2296 + } 2297 + ], 2298 + "source": [ 2299 + "struct Unit\n", 2300 + "end\n", 2301 + "\n", 2302 + "struct Pair{T, S}\n", 2303 + " l::T\n", 2304 + " r::S\n", 2305 + " function fst()::T\n", 2306 + " l\n", 2307 + " end\n", 2308 + " function snd()::S\n", 2309 + " r\n", 2310 + " end\n", 2311 + "end\n", 2312 + "\n", 2313 + "# Check if a sequence is a Costas sequence with debug information\n", 2314 + "function iscostasdbg(lst::Vector, f::Function = normal_predicate) #::Union{Unit, Tuple{Int64, Int64}}\n", 2315 + " n::Integer = length(lst)\n", 2316 + " for k in 1:n\n", 2317 + " diffs = [(false, (-1,-1)) for _ in 1:2 * n]\n", 2318 + " for i in 1:(n - k)\n", 2319 + " a = lst[i + k]\n", 2320 + " b = lst[i]\n", 2321 + " result = f(a, b, n)\n", 2322 + " if diffs[result][1]\n", 2323 + " return ((i, i + k), diffs[result][2])\n", 2324 + " elseif result != n\n", 2325 + " diffs[result] = (true, (i, i + k))\n", 2326 + " end\n", 2327 + " end\n", 2328 + " end\n", 2329 + " return Unit()\n", 2330 + "end" 2331 + ] 2332 + }, 2333 + { 2334 + "cell_type": "code", 2335 + "execution_count": 5, 2336 + "id": "365866e4-e7bf-4d63-8005-f9d2b7044434", 2337 + "metadata": {}, 2338 + "outputs": [ 2339 + { 2340 + "data": { 2341 + "text/plain": [ 2342 + "searchdbg (generic function with 1 method)" 2343 + ] 2344 + }, 2345 + "execution_count": 5, 2346 + "metadata": {}, 2347 + "output_type": "execute_result" 2348 + } 2349 + ], 2350 + "source": [ 2351 + "using Base.Threads\n", 2352 + "function searchdbg(n::Integer)::Vector{Vector{Integer}}\n", 2353 + " p1 = 0\n", 2354 + " p2 = 0\n", 2355 + " p3 = 0\n", 2356 + " p4 = 0\n", 2357 + " i1 = 0\n", 2358 + " i2 = 0\n", 2359 + " i3 = 0\n", 2360 + " i4 = 0\n", 2361 + " acc::Vector{Vector{Vector{Integer}}} = [[] for _ in 1:nthreads()]\n", 2362 + " \n", 2363 + " @threads :static for i in 1:factorial(n)\n", 2364 + " tid = threadid()\n", 2365 + " lst = nthperm(1:n, i)\n", 2366 + " if (i1 != 0 && p1 == lst[i1]) && (i2 != 0 && p2 == lst[i2]) && (i3 != 0 && p3 == lst[i3]) && (i4 != 0 && p4 == lst[i4])\n", 2367 + " #println(\"miss: \", lst)\n", 2368 + " continue\n", 2369 + " end\n", 2370 + " result = iscostasdbg(lst)\n", 2371 + " if result isa Unit\n", 2372 + " push!(acc[tid], lst)\n", 2373 + " else\n", 2374 + " #println(\"fail: \", lst, \"; \", result)\n", 2375 + " (i1, i2), (i3, i4) = result\n", 2376 + " p1, p2, p3, p4 = lst[i1], lst[i2], lst[i3], lst[i4]\n", 2377 + " end\n", 2378 + " end\n", 2379 + " reduce(vcat, acc)\n", 2380 + "end" 2381 + ] 2382 + }, 2383 + { 2384 + "cell_type": "code", 2385 + "execution_count": 13, 2386 + "id": "417662cf-6ccc-488b-95f3-bc42fd988f64", 2387 + "metadata": {}, 2388 + "outputs": [ 2389 + { 2390 + "name": "stderr", 2391 + "output_type": "stream", 2392 + "text": [ 2393 + "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", 2394 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Project.toml`\n", 2395 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Manifest.toml`\n" 2396 + ] 2397 + } 2398 + ], 2399 + "source": [ 2400 + "import Pkg; Pkg.add(\"StaticArrays\")\n", 2401 + "using StaticArrays" 2402 + ] 2403 + }, 2404 + { 2405 + "cell_type": "code", 2406 + "execution_count": 74, 2407 + "id": "54cc4c58-ba59-47cc-865f-49c20cd27bfa", 2408 + "metadata": {}, 2409 + "outputs": [ 2410 + { 2411 + "data": { 2412 + "text/plain": [ 2413 + "iscostas (generic function with 6 methods)" 2414 + ] 2415 + }, 2416 + "execution_count": 74, 2417 + "metadata": {}, 2418 + "output_type": "execute_result" 2419 + } 2420 + ], 2421 + "source": [ 2422 + "# Check if a sequence is a Costas sequence with debug information\n", 2423 + "function iscostas(lst::SVector, f::Function = normal_predicate)::Union{Unit, Tuple{Tuple{Int64, Int64}, Tuple{Int64, Int64}}}\n", 2424 + " n::Int64 = length(lst)\n", 2425 + " for k in 1:n\n", 2426 + " diffs::Vector{Tuple{Bool, Tuple{Int64, Int64}}} = [(false, (-1,-1)) for _ in 1:2 * n]\n", 2427 + " for i in 1:(n - k)\n", 2428 + " a = lst[i + k]\n", 2429 + " b = lst[i]\n", 2430 + " result = f(a, b, n)\n", 2431 + " if diffs[result][1]\n", 2432 + " return ((i, i + k), diffs[result][2])\n", 2433 + " elseif result != n\n", 2434 + " diffs[result] = (true, (i, i + k))\n", 2435 + " end\n", 2436 + " end\n", 2437 + " end\n", 2438 + " return Unit()\n", 2439 + "end" 2440 + ] 2441 + }, 2442 + { 2443 + "cell_type": "code", 2444 + "execution_count": 75, 2445 + "id": "da9e3d3d-7bf7-48b3-9d3d-370590f06355", 2446 + "metadata": {}, 2447 + "outputs": [ 2448 + { 2449 + "data": { 2450 + "text/plain": [ 2451 + "((2, 3), (1, 2))" 2452 + ] 2453 + }, 2454 + "execution_count": 75, 2455 + "metadata": {}, 2456 + "output_type": "execute_result" 2457 + } 2458 + ], 2459 + "source": [ 2460 + "iscostas(SA[1,2,3])" 2461 + ] 2462 + }, 2463 + { 2464 + "cell_type": "code", 2465 + "execution_count": 78, 2466 + "id": "db5561bb-56ee-4806-897d-b58d1ed37323", 2467 + "metadata": {}, 2468 + "outputs": [ 2469 + { 2470 + "data": { 2471 + "text/plain": [ 2472 + "searchallt (generic function with 2 methods)" 2473 + ] 2474 + }, 2475 + "execution_count": 78, 2476 + "metadata": {}, 2477 + "output_type": "execute_result" 2478 + } 2479 + ], 2480 + "source": [ 2481 + "using Base.Threads\n", 2482 + "function searchallt(n::Int64)::Vector{SVector{n, Int64}}\n", 2483 + " p1::Int64 = 0\n", 2484 + " p2::Int64 = 0\n", 2485 + " p3::Int64 = 0\n", 2486 + " p4::Int64 = 0\n", 2487 + " i1::Int64 = 0\n", 2488 + " i2::Int64 = 0\n", 2489 + " i3::Int64 = 0\n", 2490 + " i4::Int64 = 0\n", 2491 + " acc::Vector{Vector{SVector{n, Integer}}} = [[] for _ in 1:nthreads()]\n", 2492 + "\n", 2493 + " @threads :static for i in 1:factorial(n)\n", 2494 + " tid::Int64 = threadid()\n", 2495 + " lst::SVector{n, Int64} = nthperm(1:n, i)\n", 2496 + " if (i1 != 0 && p1 == lst[i1]) && (i2 != 0 && p2 == lst[i2]) && (i3 != 0 && p3 == lst[i3]) && (i4 != 0 && p4 == lst[i4])\n", 2497 + " continue\n", 2498 + " end\n", 2499 + " result = iscostas(lst)\n", 2500 + " if result isa Unit\n", 2501 + " push!(acc[tid], lst)\n", 2502 + " else\n", 2503 + " (i1, i2), (i3, i4) = result\n", 2504 + " p1, p2, p3, p4 = lst[i1], lst[i2], lst[i3], lst[i4]\n", 2505 + " end\n", 2506 + " end\n", 2507 + " reduce(vcat, acc)\n", 2508 + "end" 2509 + ] 2510 + }, 2511 + { 2512 + "cell_type": "code", 2513 + "execution_count": 101, 2514 + "id": "0cc33333-0bfe-49ef-af4b-15419d43a290", 2515 + "metadata": {}, 2516 + "outputs": [ 2517 + { 2518 + "name": "stdout", 2519 + "output_type": "stream", 2520 + "text": [ 2521 + "[1, 2, 3]\n", 2522 + "[1, 3, 2]\n", 2523 + "[2, 1, 3]\n", 2524 + "[2, 3, 1]\n", 2525 + "[3, 1, 2]\n", 2526 + "[3, 2, 1]\n" 2527 + ] 2528 + } 2529 + ], 2530 + "source": [ 2531 + "for i in 1:6\n", 2532 + " println(nthperm(1:3, i))\n", 2533 + "end" 2534 + ] 2535 + }, 2536 + { 2537 + "cell_type": "code", 2538 + "execution_count": 99, 2539 + "id": "b9d236a0-28d7-4ad5-9385-a3fb2dbe13c6", 2540 + "metadata": {}, 2541 + "outputs": [ 2542 + { 2543 + "data": { 2544 + "text/plain": [ 2545 + "searchall (generic function with 2 methods)" 2546 + ] 2547 + }, 2548 + "execution_count": 99, 2549 + "metadata": {}, 2550 + "output_type": "execute_result" 2551 + } 2552 + ], 2553 + "source": [ 2554 + "function searchall(n::Int64)::Set{Vector{Int64}}\n", 2555 + " p1::Int64 = 0\n", 2556 + " p2::Int64 = 0\n", 2557 + " p3::Int64 = 0\n", 2558 + " p4::Int64 = 0\n", 2559 + " i1::Int64 = 0\n", 2560 + " i2::Int64 = 0\n", 2561 + " i3::Int64 = 0\n", 2562 + " i4::Int64 = 0\n", 2563 + " acc::Set{Vector{Int64}} = Set()\n", 2564 + "\n", 2565 + " for i in 1:(factorial(n) ÷ 2)\n", 2566 + " lst::Vector{Int64} = nthperm(1:n, i)\n", 2567 + " if (i1 != 0 && p1 == lst[i1]) && (i2 != 0 && p2 == lst[i2]) && (i3 != 0 && p3 == lst[i3]) && (i4 != 0 && p4 == lst[i4])\n", 2568 + " continue\n", 2569 + " end\n", 2570 + " result = iscostas(lst)\n", 2571 + " if result isa Unit\n", 2572 + " push!(acc, lst)\n", 2573 + " push!(acc, lst |> reverse)\n", 2574 + " lst2 = lst .|> x -> (-x % n) + n\n", 2575 + " #push!(acc, lst2)\n", 2576 + " #push!(acc, lst2 |> reverse)\n", 2577 + " else\n", 2578 + " (i1, i2), (i3, i4) = result\n", 2579 + " p1, p2, p3, p4 = lst[i1], lst[i2], lst[i3], lst[i4]\n", 2580 + " end\n", 2581 + " end\n", 2582 + " acc\n", 2583 + "end\n", 2584 + "\n" 2585 + ] 2586 + }, 2587 + { 2588 + "cell_type": "code", 2589 + "execution_count": 100, 2590 + "id": "2552643c-d049-4cfe-b6f0-e57508f9fc46", 2591 + "metadata": {}, 2592 + "outputs": [ 2593 + { 2594 + "data": { 2595 + "text/plain": [ 2596 + "Set{Vector{Int64}} with 32 elements:\n", 2597 + " [1, 4, 5, 3, 2]\n", 2598 + " [2, 3, 5, 4, 1]\n", 2599 + " [2, 5, 4, 1, 3]\n", 2600 + " [3, 1, 4, 5, 2]\n", 2601 + " [4, 1, 5, 3, 2]\n", 2602 + " [2, 4, 1, 5, 3]\n", 2603 + " [2, 4, 3, 1, 5]\n", 2604 + " [4, 3, 1, 5, 2]\n", 2605 + " [1, 5, 4, 2, 3]\n", 2606 + " [2, 3, 5, 1, 4]\n", 2607 + " [5, 1, 3, 4, 2]\n", 2608 + " [3, 5, 4, 1, 2]\n", 2609 + " [5, 2, 4, 3, 1]\n", 2610 + " [2, 5, 3, 4, 1]\n", 2611 + " [3, 2, 4, 5, 1]\n", 2612 + " [3, 1, 2, 5, 4]\n", 2613 + " [4, 2, 5, 1, 3]\n", 2614 + " [1, 3, 4, 2, 5]\n", 2615 + " [1, 4, 3, 5, 2]\n", 2616 + " [4, 3, 5, 1, 2]\n", 2617 + " [1, 4, 2, 3, 5]\n", 2618 + " [5, 3, 2, 4, 1]\n", 2619 + " [1, 5, 3, 2, 4]\n", 2620 + " [4, 5, 2, 1, 3]\n", 2621 + " [3, 1, 5, 2, 4]\n", 2622 + " ⋮ " 2623 + ] 2624 + }, 2625 + "execution_count": 100, 2626 + "metadata": {}, 2627 + "output_type": "execute_result" 2628 + } 2629 + ], 2630 + "source": [ 2631 + "Set(searchall(5))" 2632 + ] 2633 + }, 2634 + { 2635 + "cell_type": "code", 2636 + "execution_count": 77, 2637 + "id": "9d36bd50-373d-47fd-ad75-c9107f146128", 2638 + "metadata": {}, 2639 + "outputs": [ 2640 + { 2641 + "name": "stdout", 2642 + "output_type": "stream", 2643 + "text": [ 2644 + " 4.517 s (57459141 allocations: 4.25 GiB)\n" 2645 + ] 2646 + }, 2647 + { 2648 + "data": { 2649 + "text/plain": [ 2650 + "2160-element Vector{SVector{10, Int64}}:\n", 2651 + " [1, 2, 4, 8, 5, 10, 9, 7, 3, 6]\n", 2652 + " [1, 2, 5, 7, 3, 10, 9, 6, 4, 8]\n", 2653 + " [1, 2, 5, 9, 3, 8, 4, 10, 7, 6]\n", 2654 + " [1, 2, 5, 9, 3, 10, 8, 7, 4, 6]\n", 2655 + " [1, 2, 6, 9, 8, 5, 7, 3, 10, 4]\n", 2656 + " [1, 2, 8, 5, 10, 4, 6, 9, 7, 3]\n", 2657 + " [1, 2, 8, 10, 6, 3, 7, 5, 4, 9]\n", 2658 + " [1, 2, 9, 3, 5, 10, 8, 4, 7, 6]\n", 2659 + " [1, 2, 9, 6, 5, 7, 10, 4, 8, 3]\n", 2660 + " [1, 2, 10, 6, 4, 7, 9, 3, 8, 5]\n", 2661 + " [1, 2, 10, 8, 5, 4, 6, 9, 3, 7]\n", 2662 + " [1, 3, 4, 9, 8, 6, 10, 7, 2, 5]\n", 2663 + " [1, 3, 7, 10, 9, 4, 2, 8, 5, 6]\n", 2664 + " ⋮\n", 2665 + " [10, 8, 7, 2, 3, 5, 1, 4, 9, 6]\n", 2666 + " [10, 9, 1, 3, 6, 7, 5, 2, 8, 4]\n", 2667 + " [10, 9, 1, 5, 7, 4, 2, 8, 3, 6]\n", 2668 + " [10, 9, 2, 5, 6, 4, 1, 7, 3, 8]\n", 2669 + " [10, 9, 2, 8, 6, 1, 3, 7, 4, 5]\n", 2670 + " [10, 9, 3, 1, 5, 8, 4, 6, 7, 2]\n", 2671 + " [10, 9, 3, 6, 1, 7, 5, 2, 4, 8]\n", 2672 + " [10, 9, 5, 2, 3, 6, 4, 8, 1, 7]\n", 2673 + " [10, 9, 6, 2, 8, 1, 3, 4, 7, 5]\n", 2674 + " [10, 9, 6, 2, 8, 3, 7, 1, 4, 5]\n", 2675 + " [10, 9, 6, 4, 8, 1, 2, 5, 7, 3]\n", 2676 + " [10, 9, 7, 3, 6, 1, 2, 4, 8, 5]" 2677 + ] 2678 + }, 2679 + "execution_count": 77, 2680 + "metadata": {}, 2681 + "output_type": "execute_result" 2682 + } 2683 + ], 2684 + "source": [ 2685 + "@btime searchall(10)" 2686 + ] 2687 + }, 2688 + { 2689 + "cell_type": "code", 2690 + "execution_count": 126, 2691 + "id": "27f43b7a-7998-4447-84b2-c2a5477721c7", 2692 + "metadata": {}, 2693 + "outputs": [ 2694 + { 2695 + "name": "stdout", 2696 + "output_type": "stream", 2697 + "text": [ 2698 + "[1, 2, 3]\n", 2699 + "[1, 3, 2]\n", 2700 + "[2, 1, 3]\n", 2701 + "[2, 3, 1]\n", 2702 + "[3, 1, 2]\n", 2703 + "[3, 2, 1]\n" 2704 + ] 2705 + } 2706 + ], 2707 + "source": [ 2708 + "for i in 1:6\n", 2709 + " println(nthperm([1,2,3], i))\n", 2710 + "end" 2711 + ] 2712 + }, 2713 + { 2714 + "cell_type": "code", 2715 + "execution_count": 139, 2716 + "id": "5434992c-6060-4557-b806-8227c0aeaf35", 2717 + "metadata": {}, 2718 + "outputs": [ 2719 + { 2720 + "name": "stdout", 2721 + "output_type": "stream", 2722 + "text": [ 2723 + "[1, 2, 3]\n", 2724 + "[1, 3, 2]\n", 2725 + "[3, 1, 2]\n", 2726 + "[1, 2, 3]\n", 2727 + "[3, 1, 2]\n", 2728 + "[2, 1, 3]\n" 2729 + ] 2730 + } 2731 + ], 2732 + "source": [ 2733 + "lst = [1,2,3]\n", 2734 + "for i in 1:6\n", 2735 + " nthperm!(lst, i)\n", 2736 + " println(lst)\n", 2737 + "end" 2738 + ] 2739 + }, 2740 + { 2741 + "cell_type": "code", 2742 + "execution_count": 114, 2743 + "id": "0785a658-ab45-48f1-b1f1-3f99375f3b1a", 2744 + "metadata": {}, 2745 + "outputs": [ 2746 + { 2747 + "data": { 2748 + "text/plain": [ 2749 + "false" 2750 + ] 2751 + }, 2752 + "execution_count": 114, 2753 + "metadata": {}, 2754 + "output_type": "execute_result" 2755 + } 2756 + ], 2757 + "source": [ 2758 + "[3,2,4,1,5] in costas_5x5" 2759 + ] 2760 + }, 2761 + { 2762 + "cell_type": "code", 2763 + "execution_count": 125, 2764 + "id": "ed4c511e-77d3-463f-bfeb-fb3f1f1e89bc", 2765 + "metadata": {}, 2766 + "outputs": [ 2767 + { 2768 + "name": "stdout", 2769 + "output_type": "stream", 2770 + "text": [ 2771 + "(Integer[0, 0, 0, 1, 4], [3, 4, 2, 1, 5])\n", 2772 + "(Integer[0, 0, 0, 2, 0], [5, 3, 2, 4, 1])\n", 2773 + "(Integer[0, 0, 0, 2, 3], [3, 2, 4, 5, 1])\n", 2774 + "(Integer[0, 0, 0, 3, 1], [3, 5, 2, 1, 4])\n", 2775 + "(Integer[0, 0, 1, 0, 3], [4, 2, 3, 5, 1])\n", 2776 + "(Integer[0, 0, 1, 1, 0], [5, 2, 4, 3, 1])\n", 2777 + "(Integer[0, 0, 1, 1, 4], [2, 4, 3, 1, 5])\n", 2778 + "(Integer[0, 0, 1, 2, 1], [2, 5, 3, 4, 1])\n", 2779 + "(Integer[0, 0, 1, 2, 2], [2, 3, 5, 4, 1])\n", 2780 + "(Integer[0, 0, 1, 3, 0], [5, 2, 3, 1, 4])\n", 2781 + "(Integer[0, 0, 1, 3, 2], [2, 3, 5, 1, 4])\n", 2782 + "(Integer[0, 0, 1, 3, 3], [2, 3, 1, 5, 4])\n", 2783 + "(Integer[0, 0, 2, 0, 1], [4, 5, 2, 1, 3])\n", 2784 + "(Integer[0, 0, 2, 0, 2], [4, 2, 5, 1, 3])\n", 2785 + "(Integer[0, 0, 2, 1, 1], [2, 5, 4, 1, 3])\n", 2786 + "(Integer[0, 0, 2, 1, 3], [2, 4, 1, 5, 3])\n", 2787 + "(Integer[0, 0, 2, 2, 3], [2, 1, 4, 5, 3])\n", 2788 + "(Integer[0, 0, 2, 3, 0], [5, 2, 1, 3, 4])\n", 2789 + "(Integer[0, 0, 2, 3, 1], [2, 5, 1, 3, 4])\n", 2790 + "(Integer[0, 0, 2, 3, 2], [2, 1, 5, 3, 4])\n", 2791 + "(Integer[0, 1, 0, 0, 2], [4, 3, 5, 1, 2])\n", 2792 + "(Integer[0, 1, 0, 0, 3], [4, 3, 1, 5, 2])\n", 2793 + "(Integer[0, 1, 0, 0, 4], [4, 3, 1, 2, 5])\n", 2794 + "(Integer[0, 1, 0, 1, 1], [3, 5, 4, 1, 2])\n", 2795 + "(Integer[0, 1, 0, 2, 1], [3, 5, 1, 4, 2])\n", 2796 + "(Integer[0, 1, 0, 2, 3], [3, 1, 4, 5, 2])\n", 2797 + "(Integer[0, 1, 0, 3, 2], [3, 1, 5, 2, 4])\n", 2798 + "(Integer[0, 1, 0, 3, 3], [3, 1, 2, 5, 4])\n", 2799 + "(Integer[0, 1, 1, 0, 1], [4, 5, 1, 3, 2])\n", 2800 + "(Integer[0, 1, 1, 0, 2], [4, 1, 5, 3, 2])\n", 2801 + "(Integer[0, 1, 1, 0, 4], [4, 1, 3, 2, 5])\n", 2802 + "(Integer[0, 1, 1, 1, 2], [1, 4, 5, 3, 2])\n", 2803 + "(Integer[0, 1, 1, 1, 3], [1, 4, 3, 5, 2])\n", 2804 + "(Integer[0, 1, 1, 2, 0], [5, 1, 3, 4, 2])\n", 2805 + "(Integer[0, 1, 1, 2, 4], [1, 3, 4, 2, 5])\n", 2806 + "(Integer[0, 1, 1, 3, 1], [1, 5, 3, 2, 4])\n", 2807 + "(Integer[0, 1, 2, 0, 3], [4, 1, 2, 5, 3])\n", 2808 + "(Integer[0, 1, 2, 1, 1], [1, 5, 4, 2, 3])\n", 2809 + "(Integer[0, 1, 2, 1, 4], [1, 4, 2, 3, 5])\n", 2810 + "(Integer[0, 1, 2, 2, 0], [5, 1, 2, 4, 3])\n" 2811 + ] 2812 + } 2813 + ], 2814 + "source": [ 2815 + "for lst ∈ costas_5x5 .|> (lst -> (seq(lst), lst)) |> sort\n", 2816 + " println(lst)\n", 2817 + "end" 2818 + ] 2819 + }, 2820 + { 2821 + "cell_type": "code", 2822 + "execution_count": 216, 2823 + "id": "4f0108c1-c4b3-401c-be08-6b6fd23138df", 2824 + "metadata": {}, 2825 + "outputs": [ 2826 + { 2827 + "ename": "LoadError", 2828 + "evalue": "MethodError: no method matching zeros(::Vector{Any}, ::Int64)\n\n\u001b[0mClosest candidates are:\n\u001b[0m zeros(\u001b[91m::Union{Integer, AbstractUnitRange}...\u001b[39m)\n\u001b[0m\u001b[90m @\u001b[39m \u001b[90mBase\u001b[39m \u001b[90m\u001b[4marray.jl:631\u001b[24m\u001b[39m\n\u001b[0m zeros(\u001b[91m::Type{T}\u001b[39m, ::Union{Integer, AbstractUnitRange}...) where T\n\u001b[0m\u001b[90m @\u001b[39m \u001b[90mBase\u001b[39m \u001b[90m\u001b[4marray.jl:632\u001b[24m\u001b[39m\n", 2829 + "output_type": "error", 2830 + "traceback": [ 2831 + "MethodError: no method matching zeros(::Vector{Any}, ::Int64)\n\n\u001b[0mClosest candidates are:\n\u001b[0m zeros(\u001b[91m::Union{Integer, AbstractUnitRange}...\u001b[39m)\n\u001b[0m\u001b[90m @\u001b[39m \u001b[90mBase\u001b[39m \u001b[90m\u001b[4marray.jl:631\u001b[24m\u001b[39m\n\u001b[0m zeros(\u001b[91m::Type{T}\u001b[39m, ::Union{Integer, AbstractUnitRange}...) where T\n\u001b[0m\u001b[90m @\u001b[39m \u001b[90mBase\u001b[39m \u001b[90m\u001b[4marray.jl:632\u001b[24m\u001b[39m\n", 2832 + "", 2833 + "Stacktrace:", 2834 + " [1] top-level scope", 2835 + " @ In[216]:1" 2836 + ] 2837 + } 2838 + ], 2839 + "source": [ 2840 + "zeros([], factorial(4))" 2841 + ] 2842 + }, 2843 + { 2844 + "cell_type": "code", 2845 + "execution_count": 15, 2846 + "id": "ba7df634-88e6-46a2-9167-e0d197c7203e", 2847 + "metadata": {}, 2848 + "outputs": [ 2849 + { 2850 + "data": { 2851 + "text/plain": [ 2852 + "searchone (generic function with 1 method)" 2853 + ] 2854 + }, 2855 + "execution_count": 15, 2856 + "metadata": {}, 2857 + "output_type": "execute_result" 2858 + } 2859 + ], 2860 + "source": [ 2861 + "using Base.Threads\n", 2862 + "function searchone(n::Integer)::Union{Nothing, Vector{Integer}}\n", 2863 + " p1 = 0\n", 2864 + " p2 = 0\n", 2865 + " p3 = 0\n", 2866 + " p4 = 0\n", 2867 + " i1 = 0\n", 2868 + " i2 = 0\n", 2869 + " i3 = 0\n", 2870 + " i4 = 0\n", 2871 + " \n", 2872 + " for i in 1:factorial(n)\n", 2873 + " lst = nthperm(1:n, i)\n", 2874 + " if (i1 != 0 && p1 == lst[i1]) && (i2 != 0 && p2 == lst[i2]) && (i3 != 0 && p3 == lst[i3]) && (i4 != 0 && p4 == lst[i4])\n", 2875 + " continue\n", 2876 + " end\n", 2877 + " result = iscostasdbg(lst)\n", 2878 + " if result isa Unit\n", 2879 + " return lst\n", 2880 + " else\n", 2881 + " (i1, i2), (i3, i4) = result\n", 2882 + " p1, p2, p3, p4 = lst[i1], lst[i2], lst[i3], lst[i4]\n", 2883 + " end\n", 2884 + " end\n", 2885 + " return nothing\n", 2886 + "end" 2887 + ] 2888 + }, 2889 + { 2890 + "cell_type": "code", 2891 + "execution_count": 13, 2892 + "id": "f663071d-bc6d-43d7-a5d4-935c18bd4160", 2893 + "metadata": {}, 2894 + "outputs": [ 2895 + { 2896 + "name": "stdout", 2897 + "output_type": "stream", 2898 + "text": [ 2899 + " 1.959 ms (8464 allocations: 1.27 MiB)\n" 2900 + ] 2901 + } 2902 + ], 2903 + "source": [ 2904 + "@btime searchone(10)" 2905 + ] 2906 + }, 2907 + { 2908 + "cell_type": "code", 2909 + "execution_count": 26, 2910 + "id": "fb4205aa-f425-4e16-a885-07eb10c0d984", 2911 + "metadata": {}, 2912 + "outputs": [ 2913 + { 2914 + "data": { 2915 + "text/plain": [ 2916 + "14-element Vector{Integer}:\n", 2917 + " 1\n", 2918 + " 2\n", 2919 + " 5\n", 2920 + " 7\n", 2921 + " 14\n", 2922 + " 8\n", 2923 + " 12\n", 2924 + " 11\n", 2925 + " 6\n", 2926 + " 4\n", 2927 + " 13\n", 2928 + " 10\n", 2929 + " 3\n", 2930 + " 9" 2931 + ] 2932 + }, 2933 + "execution_count": 26, 2934 + "metadata": {}, 2935 + "output_type": "execute_result" 2936 + } 2937 + ], 2938 + "source": [ 2939 + "v14 = searchone(14)" 2940 + ] 2941 + }, 2942 + { 2943 + "cell_type": "code", 2944 + "execution_count": 27, 2945 + "id": "c3c135d2-9507-42cf-86e0-c273d2655a60", 2946 + "metadata": {}, 2947 + "outputs": [ 2948 + { 2949 + "data": { 2950 + "text/plain": [ 2951 + "Vector{Integer}[]" 2952 + ] 2953 + }, 2954 + "execution_count": 27, 2955 + "metadata": {}, 2956 + "output_type": "execute_result" 2957 + } 2958 + ], 2959 + "source": [ 2960 + "buildallnaive(v14, 15)" 2961 + ] 2962 + }, 2963 + { 2964 + "cell_type": "code", 2965 + "execution_count": 32, 2966 + "id": "7dc7f53a-e84b-433a-9ef8-0c984429e2da", 2967 + "metadata": {}, 2968 + "outputs": [ 2969 + { 2970 + "data": { 2971 + "text/plain": [ 2972 + "true" 2973 + ] 2974 + }, 2975 + "execution_count": 32, 2976 + "metadata": {}, 2977 + "output_type": "execute_result" 2978 + } 2979 + ], 2980 + "source": [ 2981 + "iscostas([5,3,2,4,1,6])" 2982 + ] 2983 + }, 2984 + { 2985 + "cell_type": "code", 2986 + "execution_count": 33, 2987 + "id": "fa3a6a7d-9043-46aa-adfd-fe36e27045b6", 2988 + "metadata": {}, 2989 + "outputs": [ 2990 + { 2991 + "data": { 2992 + "text/plain": [ 2993 + "12-element Vector{Int64}:\n", 2994 + " 2\n", 2995 + " 3\n", 2996 + " 5\n", 2997 + " 7\n", 2998 + " 11\n", 2999 + " 13\n", 3000 + " 17\n", 3001 + " 19\n", 3002 + " 23\n", 3003 + " 29\n", 3004 + " 31\n", 3005 + " 37" 3006 + ] 3007 + }, 3008 + "execution_count": 33, 3009 + "metadata": {}, 3010 + "output_type": "execute_result" 3011 + } 3012 + ], 3013 + "source": [ 3014 + "primes(39)" 3015 + ] 3016 + }, 3017 + { 3018 + "cell_type": "code", 3019 + "execution_count": 38, 3020 + "id": "b3ede472-67c8-4e16-a604-b652d9d0a820", 3021 + "metadata": {}, 3022 + "outputs": [ 3023 + { 3024 + "data": { 3025 + "text/plain": [ 3026 + "lempelc (generic function with 2 methods)" 3027 + ] 3028 + }, 3029 + "execution_count": 38, 3030 + "metadata": {}, 3031 + "output_type": "execute_result" 3032 + } 3033 + ], 3034 + "source": [ 3035 + "function lempelc(prime::Integer, c::Integer = 1)::Vector{Vector{Integer}}\n", 3036 + " welch(prime) .|> lst -> init(lst) .|> n -> findindex(lst, prime + c - n)\n", 3037 + "end" 3038 + ] 3039 + }, 3040 + { 3041 + "cell_type": "markdown", 3042 + "id": "f6b5d41c-8ac6-4802-b0e4-dfe270d0d9b3", 3043 + "metadata": {}, 3044 + "source": [ 3045 + "lempelc(37)" 3046 + ] 3047 + }, 3048 + { 3049 + "cell_type": "code", 3050 + "execution_count": 52, 3051 + "id": "857ac8df-a466-4fd6-b371-fcfce09dbaa7", 3052 + "metadata": {}, 3053 + "outputs": [ 3054 + { 3055 + "name": "stdout", 3056 + "output_type": "stream", 3057 + "text": [ 3058 + "2: true\n", 3059 + "3: true\n", 3060 + "5: true\n", 3061 + "7: true\n", 3062 + "11: false\n", 3063 + "13: false\n", 3064 + "17: true\n", 3065 + "19: true\n", 3066 + "23: false\n", 3067 + "29: false\n", 3068 + "31: false\n", 3069 + "37: false\n" 3070 + ] 3071 + } 3072 + ], 3073 + "source": [ 3074 + "for p in primes(40)\n", 3075 + " flag = false\n", 3076 + " for l in lempel(p)\n", 3077 + " if l |> f2(vcat, p) |> iscostas\n", 3078 + " flag = true\n", 3079 + " end\n", 3080 + " if flag\n", 3081 + " break\n", 3082 + " end\n", 3083 + " end\n", 3084 + " println(\"$(p): $(flag)\")\n", 3085 + "end" 3086 + ] 3087 + }, 3088 + { 3089 + "cell_type": "code", 3090 + "execution_count": 2, 3091 + "id": "c703313d-a2c2-4dc8-a61c-45fb425a4369", 3092 + "metadata": {}, 3093 + "outputs": [ 3094 + { 3095 + "data": { 3096 + "text/plain": [ 3097 + "3" 3098 + ] 3099 + }, 3100 + "execution_count": 2, 3101 + "metadata": {}, 3102 + "output_type": "execute_result" 3103 + } 3104 + ], 3105 + "source": [ 3106 + "n = 20\n", 3107 + "α₁ = 7\n", 3108 + "α = 3" 3109 + ] 3110 + }, 3111 + { 3112 + "cell_type": "code", 3113 + "execution_count": 64, 3114 + "id": "3d185147-705f-4c5b-9ec5-f6ae382acdc9", 3115 + "metadata": {}, 3116 + "outputs": [ 3117 + { 3118 + "data": { 3119 + "text/plain": [ 3120 + "5-element Vector{Integer}:\n", 3121 + " 1\n", 3122 + " 3\n", 3123 + " 4\n", 3124 + " 2\n", 3125 + " 5" 3126 + ] 3127 + }, 3128 + "execution_count": 64, 3129 + "metadata": {}, 3130 + "output_type": "execute_result" 3131 + } 3132 + ], 3133 + "source": [ 3134 + "unseq([0,1,1,2,4])" 3135 + ] 3136 + }, 3137 + { 3138 + "cell_type": "code", 3139 + "execution_count": 3, 3140 + "id": "06dc523f-8eff-40b3-be3c-05b582bf1a5a", 3141 + "metadata": {}, 3142 + "outputs": [ 3143 + { 3144 + "data": { 3145 + "text/plain": [ 3146 + "seq (generic function with 1 method)" 3147 + ] 3148 + }, 3149 + "execution_count": 3, 3150 + "metadata": {}, 3151 + "output_type": "execute_result" 3152 + } 3153 + ], 3154 + "source": [ 3155 + "function seq(lst::Vector{<:Integer})::Vector{Integer}\n", 3156 + " acc = []\n", 3157 + " for i ∈ 1:length(lst)\n", 3158 + " counter = 0\n", 3159 + " for el ∈ lst\n", 3160 + " if el < i\n", 3161 + " counter += 1\n", 3162 + " elseif el == i\n", 3163 + " break\n", 3164 + " end\n", 3165 + " end\n", 3166 + " push!(acc, counter)\n", 3167 + " end\n", 3168 + " acc\n", 3169 + "end" 3170 + ] 3171 + }, 3172 + { 3173 + "cell_type": "code", 3174 + "execution_count": 6, 3175 + "id": "f890870c-4307-4215-b987-c1a560db4964", 3176 + "metadata": {}, 3177 + "outputs": [ 3178 + { 3179 + "ename": "LoadError", 3180 + "evalue": "UndefVarError: `costas_7x7` not defined", 3181 + "output_type": "error", 3182 + "traceback": [ 3183 + "UndefVarError: `costas_7x7` not defined", 3184 + "", 3185 + "Stacktrace:", 3186 + " [1] top-level scope", 3187 + " @ ./In[6]:1" 3188 + ] 3189 + } 3190 + ], 3191 + "source": [ 3192 + "for l ∈ costas_7x7\n", 3193 + " if l |> seq |> iscostas\n", 3194 + " println(l)\n", 3195 + " end\n", 3196 + "end" 3197 + ] 3198 + }, 3199 + { 3200 + "cell_type": "code", 3201 + "execution_count": 8, 3202 + "id": "79b7d083-e78f-4f70-b489-bc80479b769e", 3203 + "metadata": {}, 3204 + "outputs": [ 3205 + { 3206 + "data": { 3207 + "text/plain": [ 3208 + "2-element Vector{Vector{Integer}}:\n", 3209 + " [0, 0, 0, 2, 3, 2]\n", 3210 + " [0, 0, 1, 0, 0, 2]" 3211 + ] 3212 + }, 3213 + "execution_count": 8, 3214 + "metadata": {}, 3215 + "output_type": "execute_result" 3216 + } 3217 + ], 3218 + "source": [ 3219 + "welch(7) .|> seq" 3220 + ] 3221 + }, 3222 + { 3223 + "cell_type": "code", 3224 + "execution_count": 29, 3225 + "id": "25fd1202-b3fe-4cf4-88d9-fb1937f5d03d", 3226 + "metadata": {}, 3227 + "outputs": [ 3228 + { 3229 + "name": "stdout", 3230 + "output_type": "stream", 3231 + "text": [ 3232 + "Integer[5, 3, 2, 4, 1] ↦ Integer[0, 0, 0, 2, 0]\n", 3233 + "Integer[5, 2, 4, 3, 1] ↦ Integer[0, 0, 1, 1, 0]\n" 3234 + ] 3235 + } 3236 + ], 3237 + "source": [ 3238 + "for l ∈ lempel(7)\n", 3239 + " println(l, \" ↦ \", seq(l))\n", 3240 + "end" 3241 + ] 3242 + }, 3243 + { 3244 + "cell_type": "code", 3245 + "execution_count": 39, 3246 + "id": "e6923891-0ddb-4943-8888-dfe733cf0650", 3247 + "metadata": {}, 3248 + "outputs": [ 3249 + { 3250 + "name": "stdout", 3251 + "output_type": "stream", 3252 + "text": [ 3253 + "Integer[3, 2, 6, 4, 5, 1]Integer[3, 2, 6, 4, 5, 1][1] ↦ Integer[0, 0, 0, 2, 3, 2]\n", 3254 + "Integer[5, 4, 6, 2, 3, 1]Integer[5, 4, 6, 2, 3, 1][1] ↦ Integer[0, 0, 1, 0, 0, 2]\n" 3255 + ] 3256 + } 3257 + ], 3258 + "source": [ 3259 + "for l ∈ welch(7)\n", 3260 + " println(l, \"$l[1] ↦ \", seq(l))\n", 3261 + "end" 3262 + ] 3263 + }, 3264 + { 3265 + "cell_type": "code", 3266 + "execution_count": 134, 3267 + "id": "a1ee9bac-aaf4-406f-9c0d-b8da541dd68e", 3268 + "metadata": {}, 3269 + "outputs": [], 3270 + "source": [ 3271 + "for p ∈ primes(50)\n", 3272 + " for l ∈ welch(p)\n", 3273 + " if !issorted(l)\n", 3274 + " #println(\"$l ↦ $(seq(l))\")\n", 3275 + " end\n", 3276 + " end\n", 3277 + "end" 3278 + ] 3279 + }, 3280 + { 3281 + "cell_type": "code", 3282 + "execution_count": 4, 3283 + "id": "1850d8a1-9af0-4162-b43c-d8e3bdd613a2", 3284 + "metadata": {}, 3285 + "outputs": [ 3286 + { 3287 + "data": { 3288 + "text/plain": [ 3289 + "unseq (generic function with 1 method)" 3290 + ] 3291 + }, 3292 + "execution_count": 4, 3293 + "metadata": {}, 3294 + "output_type": "execute_result" 3295 + } 3296 + ], 3297 + "source": [ 3298 + "function unseq(lst::Vector{<:Integer})::Vector{Integer}\n", 3299 + " acc = []\n", 3300 + " for (idx, elem) ∈ enumerate(lst)\n", 3301 + " l, r = splitat(acc, elem)\n", 3302 + " acc = [l;[idx];r]\n", 3303 + " end\n", 3304 + " acc\n", 3305 + "end" 3306 + ] 3307 + }, 3308 + { 3309 + "cell_type": "code", 3310 + "execution_count": 5, 3311 + "id": "07e7a13b-f593-47f1-99e7-158c4f39dfc3", 3312 + "metadata": {}, 3313 + "outputs": [ 3314 + { 3315 + "data": { 3316 + "text/plain": [ 3317 + "splitat (generic function with 1 method)" 3318 + ] 3319 + }, 3320 + "execution_count": 5, 3321 + "metadata": {}, 3322 + "output_type": "execute_result" 3323 + } 3324 + ], 3325 + "source": [ 3326 + "function splitat(v::Vector{T}, i::Integer)::Tuple{Vector{T}, Vector{T}} where T\n", 3327 + " (v |> Take(i), v |> Drop(i)) .|> collect\n", 3328 + "end" 3329 + ] 3330 + }, 3331 + { 3332 + "cell_type": "code", 3333 + "execution_count": 82, 3334 + "id": "b60c2be3-4c88-4178-9909-59a3e7e7228c", 3335 + "metadata": {}, 3336 + "outputs": [ 3337 + { 3338 + "data": { 3339 + "text/plain": [ 3340 + "dfs (generic function with 1 method)" 3341 + ] 3342 + }, 3343 + "execution_count": 82, 3344 + "metadata": {}, 3345 + "output_type": "execute_result" 3346 + } 3347 + ], 3348 + "source": [ 3349 + "function dfs(current::Vector{<:Integer})::Vector{Integer}\n", 3350 + " longest = copy(current)\n", 3351 + " while length(current) != 0\n", 3352 + " if iscostas(unseq(current))\n", 3353 + " if length(current) > length(longest)\n", 3354 + " longest = copy(current)\n", 3355 + " end\n", 3356 + " push!(current, 0)\n", 3357 + " else\n", 3358 + " while length(current) > 0 && last(current) + 1 >= length(current)\n", 3359 + " pop!(current)\n", 3360 + " end\n", 3361 + " if length(current) == 0\n", 3362 + " break\n", 3363 + " end\n", 3364 + " current[length(current)] = last(current) + 1\n", 3365 + " end\n", 3366 + " end\n", 3367 + " longest\n", 3368 + "end" 3369 + ] 3370 + }, 3371 + { 3372 + "cell_type": "code", 3373 + "execution_count": 68, 3374 + "id": "7b2aa6c4-2a54-4eff-92ac-103a791282c3", 3375 + "metadata": {}, 3376 + "outputs": [ 3377 + { 3378 + "data": { 3379 + "text/plain": [ 3380 + "([1, 2], [3, 4, 5, 6, 7, 8, 9, 10])" 3381 + ] 3382 + }, 3383 + "execution_count": 68, 3384 + "metadata": {}, 3385 + "output_type": "execute_result" 3386 + } 3387 + ], 3388 + "source": [ 3389 + "1:10 |> collect |> x -> splitat(x, 2)" 3390 + ] 3391 + }, 3392 + { 3393 + "cell_type": "code", 3394 + "execution_count": 85, 3395 + "id": "9597cace-4837-449a-a679-cc65bfb8b75a", 3396 + "metadata": {}, 3397 + "outputs": [ 3398 + { 3399 + "name": "stdout", 3400 + "output_type": "stream", 3401 + "text": [ 3402 + "1 3 4 2 5 \n", 3403 + "1 4 2 3 5 \n", 3404 + "1 4 3 5 2 \n", 3405 + "1 4 5 3 2 \n", 3406 + "1 5 3 2 4 \n", 3407 + "1 5 4 2 3 \n", 3408 + "2 1 4 5 3 \n", 3409 + "2 1 5 3 4 \n", 3410 + "2 3 1 5 4 \n", 3411 + "2 3 5 1 4 \n", 3412 + "2 3 5 4 1 \n", 3413 + "2 4 1 5 3 \n", 3414 + "2 4 3 1 5 \n", 3415 + "2 5 1 3 4 \n", 3416 + "2 5 3 4 1 \n", 3417 + "2 5 4 1 3 \n", 3418 + "3 1 2 5 4 \n", 3419 + "3 1 4 5 2 \n", 3420 + "3 1 5 2 4 \n", 3421 + "3 2 4 5 1 \n", 3422 + "3 4 2 1 5 \n", 3423 + "3 5 1 4 2 \n", 3424 + "3 5 2 1 4 \n", 3425 + "3 5 4 1 2 \n", 3426 + "4 1 2 5 3 \n", 3427 + "4 1 3 2 5 \n", 3428 + "4 1 5 3 2 \n", 3429 + "4 2 3 5 1 \n", 3430 + "4 2 5 1 3 \n", 3431 + "4 3 1 2 5 \n", 3432 + "4 3 1 5 2 \n", 3433 + "4 3 5 1 2 \n", 3434 + "4 5 1 3 2 \n", 3435 + "4 5 2 1 3 \n", 3436 + "5 1 2 4 3 \n", 3437 + "5 1 3 4 2 \n", 3438 + "5 2 1 3 4 \n", 3439 + "5 2 3 1 4 \n", 3440 + "5 2 4 3 1 \n", 3441 + "5 3 2 4 1 \n" 3442 + ] 3443 + } 3444 + ], 3445 + "source": [ 3446 + "for l in costas_5x5\n", 3447 + " for e in l\n", 3448 + " print(\"$e \")\n", 3449 + " end\n", 3450 + " println()\n", 3451 + "end" 3452 + ] 3453 + }, 3454 + { 3455 + "cell_type": "code", 3456 + "execution_count": 135, 3457 + "id": "55ba2a3c-0930-42c8-b319-f0864dcc3972", 3458 + "metadata": {}, 3459 + "outputs": [ 3460 + { 3461 + "name": "stdout", 3462 + "output_type": "stream", 3463 + "text": [ 3464 + "Any[(4, 11), (6, 11), (10, 11), (10, 12), (12, 12), (12, 14), (16, 16), (16, 18), (18, 18), (22, 22), (28, 28), (30, 30), (36, 36), (40, 40), (42, 42), (46, 46)]\n" 3465 + ] 3466 + } 3467 + ], 3468 + "source": [ 3469 + "counter = 0\n", 3470 + "longest = []\n", 3471 + "s = []\n", 3472 + "for p ∈ primes(50)\n", 3473 + " if counter < 2\n", 3474 + " counter += 1\n", 3475 + " continue\n", 3476 + " end\n", 3477 + " for w ∈ welch(p)\n", 3478 + " c = dfs(seq(w))\n", 3479 + " push!(s, (length(w), length(c)))\n", 3480 + " end\n", 3481 + "end\n", 3482 + "println(s |> sort |> unique)" 3483 + ] 3484 + }, 3485 + { 3486 + "cell_type": "code", 3487 + "execution_count": 136, 3488 + "id": "1ee862d6-97d2-4b0d-bb14-efdbaa969ea8", 3489 + "metadata": {}, 3490 + "outputs": [ 3491 + { 3492 + "name": "stdout", 3493 + "output_type": "stream", 3494 + "text": [ 3495 + "Any[(3, 9), (3, 11), (5, 11), (9, 10), (9, 11), (11, 11), (11, 12), (15, 15), (15, 16), (15, 17), (17, 17), (21, 21), (21, 22), (27, 27), (27, 28), (29, 29), (29, 30), (35, 35), (35, 36), (39, 39), (39, 40), (41, 41), (41, 42), (45, 45), (45, 46)]\n" 3496 + ] 3497 + } 3498 + ], 3499 + "source": [ 3500 + "counter = 0\n", 3501 + "longest = []\n", 3502 + "s = []\n", 3503 + "for p ∈ primes(50)\n", 3504 + " if counter < 2\n", 3505 + " counter += 1\n", 3506 + " continue\n", 3507 + " end\n", 3508 + " for w ∈ lempel(p)\n", 3509 + " c = dfs(seq(w))\n", 3510 + " push!(s, (length(w), length(c)))\n", 3511 + " end\n", 3512 + "end\n", 3513 + "println(s |> sort |> unique)" 3514 + ] 3515 + }, 3516 + { 3517 + "cell_type": "code", 3518 + "execution_count": 112, 3519 + "id": "de864d75-3be6-4ee3-9b02-fa34d74479ac", 3520 + "metadata": {}, 3521 + "outputs": [ 3522 + { 3523 + "data": { 3524 + "text/plain": [ 3525 + "false" 3526 + ] 3527 + }, 3528 + "execution_count": 112, 3529 + "metadata": {}, 3530 + "output_type": "execute_result" 3531 + } 3532 + ], 3533 + "source": [ 3534 + "[0, 0, 1, 3, 3, 4, 3, 0, 8, 2, 2, 8, 5, 1, 5, 9, 11, 0, 13, 12, 9, 3, 12, 23, 11, 13, 3, 8, 27, 4, 3, 8] |> unseq |> iscostas" 3535 + ] 3536 + }, 3537 + { 3538 + "cell_type": "code", 3539 + "execution_count": 27, 3540 + "id": "17e599a4-a91c-49b0-bb55-a169a6c37333", 3541 + "metadata": {}, 3542 + "outputs": [ 3543 + { 3544 + "data": { 3545 + "text/plain": [ 3546 + "40-element Vector{Vector{Int64}}:\n", 3547 + " []\n", 3548 + " []\n", 3549 + " []\n", 3550 + " []\n", 3551 + " []\n", 3552 + " []\n", 3553 + " []\n", 3554 + " []\n", 3555 + " []\n", 3556 + " []\n", 3557 + " []\n", 3558 + " []\n", 3559 + " []\n", 3560 + " ⋮\n", 3561 + " []\n", 3562 + " []\n", 3563 + " []\n", 3564 + " []\n", 3565 + " []\n", 3566 + " []\n", 3567 + " []\n", 3568 + " []\n", 3569 + " []\n", 3570 + " []\n", 3571 + " []\n", 3572 + " []" 3573 + ] 3574 + }, 3575 + "execution_count": 27, 3576 + "metadata": {}, 3577 + "output_type": "execute_result" 3578 + } 3579 + ], 3580 + "source": [ 3581 + "costas_5x5" 3582 + ] 3583 + }, 3584 + { 3585 + "cell_type": "code", 3586 + "execution_count": 29, 3587 + "id": "3b83149d-1693-4086-ac44-0c3f49732223", 3588 + "metadata": {}, 3589 + "outputs": [ 3590 + { 3591 + "name": "stdout", 3592 + "output_type": "stream", 3593 + "text": [ 3594 + "Integer[7, 6, 1, 3, 4, 2, 5]\n", 3595 + "Integer[7, 6, 1, 4, 2, 3, 8, 5]\n", 3596 + "Integer[5, 1, 7, 6, 8, 3, 4, 2]\n", 3597 + "Integer[5, 1, 7, 6, 8, 3, 4, 2]\n", 3598 + "Integer[9, 6, 1, 5, 3, 2, 4, 7, 8]\n", 3599 + "Integer[7, 1, 5, 4, 2, 3, 6, 8]\n", 3600 + "Integer[9, 6, 4, 5, 1, 8, 3, 2, 7]\n", 3601 + "Integer[7, 3, 1, 6, 5, 2, 4, 8, 9]\n", 3602 + "Integer[7, 3, 1, 6, 5, 2, 4, 8, 9]\n", 3603 + "Integer[8, 3, 5, 9, 10, 1, 4, 2, 7, 6]\n", 3604 + "Integer[7, 3, 1, 6, 5, 2, 4, 8, 9]\n", 3605 + "Integer[9, 8, 4, 6, 1, 2, 5, 3, 7]\n", 3606 + "Integer[5, 1, 7, 6, 8, 3, 4, 2]\n", 3607 + "Integer[5, 1, 7, 6, 8, 3, 4, 2]\n", 3608 + "Integer[7, 3, 1, 6, 5, 2, 4, 8, 9]\n", 3609 + "Integer[9, 6, 4, 5, 1, 8, 3, 2, 7]\n", 3610 + "Integer[7, 5, 1, 2, 4, 8, 3, 6]\n", 3611 + "Integer[5, 1, 7, 6, 8, 3, 4, 2]\n" 3612 + ] 3613 + } 3614 + ], 3615 + "source": [ 3616 + "for c in costas_5x5\n", 3617 + " l = c |> seq |> dfs |> unseq\n", 3618 + " if length(l) <= 10\n", 3619 + " println(l)\n", 3620 + " end\n", 3621 + "end" 3622 + ] 3623 + }, 3624 + { 3625 + "cell_type": "code", 3626 + "execution_count": 30, 3627 + "id": "b4f239f6-0a9b-4a35-af34-7a30e4f77d4c", 3628 + "metadata": {}, 3629 + "outputs": [ 3630 + { 3631 + "data": { 3632 + "text/plain": [ 3633 + "2160-element Vector{Vector{Int64}}:\n", 3634 + " [1, 2, 4, 8, 5, 10, 9, 7, 3, 6]\n", 3635 + " [1, 2, 5, 7, 3, 10, 9, 6, 4, 8]\n", 3636 + " [1, 2, 5, 9, 3, 8, 4, 10, 7, 6]\n", 3637 + " [1, 2, 5, 9, 3, 10, 8, 7, 4, 6]\n", 3638 + " [1, 2, 6, 9, 8, 5, 7, 3, 10, 4]\n", 3639 + " [1, 2, 8, 5, 10, 4, 6, 9, 7, 3]\n", 3640 + " [1, 2, 8, 10, 6, 3, 7, 5, 4, 9]\n", 3641 + " [1, 2, 9, 3, 5, 10, 8, 4, 7, 6]\n", 3642 + " [1, 2, 9, 6, 5, 7, 10, 4, 8, 3]\n", 3643 + " [1, 2, 10, 6, 4, 7, 9, 3, 8, 5]\n", 3644 + " [1, 2, 10, 8, 5, 4, 6, 9, 3, 7]\n", 3645 + " [1, 3, 4, 9, 8, 6, 10, 7, 2, 5]\n", 3646 + " [1, 3, 7, 10, 9, 4, 2, 8, 5, 6]\n", 3647 + " ⋮\n", 3648 + " [10, 8, 7, 2, 3, 5, 1, 4, 9, 6]\n", 3649 + " [10, 9, 1, 3, 6, 7, 5, 2, 8, 4]\n", 3650 + " [10, 9, 1, 5, 7, 4, 2, 8, 3, 6]\n", 3651 + " [10, 9, 2, 5, 6, 4, 1, 7, 3, 8]\n", 3652 + " [10, 9, 2, 8, 6, 1, 3, 7, 4, 5]\n", 3653 + " [10, 9, 3, 1, 5, 8, 4, 6, 7, 2]\n", 3654 + " [10, 9, 3, 6, 1, 7, 5, 2, 4, 8]\n", 3655 + " [10, 9, 5, 2, 3, 6, 4, 8, 1, 7]\n", 3656 + " [10, 9, 6, 2, 8, 1, 3, 4, 7, 5]\n", 3657 + " [10, 9, 6, 2, 8, 3, 7, 1, 4, 5]\n", 3658 + " [10, 9, 6, 4, 8, 1, 2, 5, 7, 3]\n", 3659 + " [10, 9, 7, 3, 6, 1, 2, 4, 8, 5]" 3660 + ] 3661 + }, 3662 + "execution_count": 30, 3663 + "metadata": {}, 3664 + "output_type": "execute_result" 3665 + } 3666 + ], 3667 + "source": [ 3668 + "costas_10x10" 3669 + ] 3670 + }, 3671 + { 3672 + "cell_type": "code", 3673 + "execution_count": 39, 3674 + "id": "6cc018cf-347a-4c9f-af3c-d3fcd31b2984", 3675 + "metadata": {}, 3676 + "outputs": [ 3677 + { 3678 + "name": "stdout", 3679 + "output_type": "stream", 3680 + "text": [ 3681 + "1 2 4 8 5 10 9 7 3 6 " 3682 + ] 3683 + } 3684 + ], 3685 + "source": [ 3686 + "l = costas_10x10[1]\n", 3687 + "for e in l\n", 3688 + " print(\"$e \")\n", 3689 + "end" 3690 + ] 3691 + }, 3692 + { 3693 + "cell_type": "code", 3694 + "execution_count": 35, 3695 + "id": "eb7e4533-7c4a-4442-82e5-8f2b0e3d485b", 3696 + "metadata": {}, 3697 + "outputs": [ 3698 + { 3699 + "name": "stdout", 3700 + "output_type": "stream", 3701 + "text": [ 3702 + "29, 23, 22, 19, 27, 17, 21, 16, 18, 24, 25, 28, 20, 30, 26, 31, " 3703 + ] 3704 + } 3705 + ], 3706 + "source": [ 3707 + "for e in [3, 9, 10, 13, 5, 15, 11, 16, 14, 8, 7, 4, 12, 2, 6, 1]\n", 3708 + " print(\"$(-e % 32 + 32), \")\n", 3709 + "end" 3710 + ] 3711 + }, 3712 + { 3713 + "cell_type": "code", 3714 + "execution_count": 38, 3715 + "id": "0ada109c-c642-4fb7-a0eb-15a58e836140", 3716 + "metadata": {}, 3717 + "outputs": [ 3718 + { 3719 + "data": { 3720 + "text/plain": [ 3721 + "false" 3722 + ] 3723 + }, 3724 + "execution_count": 38, 3725 + "metadata": {}, 3726 + "output_type": "execute_result" 3727 + } 3728 + ], 3729 + "source": [ 3730 + "[3, 9, 10, 13, 5, 15, 11, 16, 14, 8, 7, 4, 12, 2, 6, 1, 29, 23, 22, 19, 27, 17, 21, 16, 18, 24, 25, 28, 20, 30, 26, 31] |> iscostas" 3731 + ] 3732 + }, 3733 + { 3734 + "cell_type": "code", 3735 + "execution_count": 72, 3736 + "id": "8074cb68-e0b0-4a50-a97c-59165de15d99", 3737 + "metadata": {}, 3738 + "outputs": [ 3739 + { 3740 + "name": "stdout", 3741 + "output_type": "stream", 3742 + "text": [ 3743 + "Integer[0, 1, 1, 2, 4, 0, 0]: 7\n", 3744 + "Integer[0, 1, 2, 1, 4, 0, 0, 6]: 8\n", 3745 + "Integer[0, 1, 1, 2, 0, 2, 2, 4]: 8\n", 3746 + "Integer[0, 1, 1, 2, 0, 2, 2, 4]: 8\n", 3747 + "Integer[0, 1, 1, 3, 1, 0, 6, 7, 0]: 9\n", 3748 + "Integer[0, 1, 2, 1, 1, 5, 0, 7]: 8\n", 3749 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3750 + "Integer[0, 1, 0, 0, 3, 2, 3, 7, 0, 9, 0]: 11\n", 3751 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3752 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3753 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3754 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3755 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3756 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3757 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3758 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3759 + "Integer[0, 1, 1, 0, 1, 0, 6, 4, 0]: 9\n", 3760 + "Integer[0, 1, 0, 3, 2, 2, 0, 7, 8]: 9\n", 3761 + "Integer[0, 1, 0, 3, 2, 2, 0, 7, 8]: 9\n", 3762 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3763 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3764 + "Integer[0, 1, 0, 2, 1, 5, 5, 0, 3, 4]: 10\n", 3765 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3766 + "Integer[0, 1, 0, 3, 2, 2, 0, 7, 8]: 9\n", 3767 + "Integer[0, 1, 2, 0, 3, 1, 6, 0, 0]: 9\n", 3768 + "Integer[0, 1, 1, 2, 0, 2, 2, 4]: 8\n", 3769 + "Integer[0, 1, 1, 2, 0, 2, 2, 4]: 8\n", 3770 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3771 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3772 + "Integer[0, 1, 0, 3, 2, 2, 0, 7, 8]: 9\n", 3773 + "Integer[0, 1, 0, 0, 3, 2, 3, 7, 0, 9, 0]: 11\n", 3774 + "Integer[0, 1, 0, 0, 3, 2, 3, 7, 0, 9, 0]: 11\n", 3775 + "Integer[0, 1, 1, 0, 1, 0, 6, 4, 0]: 9\n", 3776 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3777 + "Integer[0, 1, 2, 2, 0, 5, 0, 5]: 8\n", 3778 + "Integer[0, 1, 1, 2, 0, 2, 2, 4]: 8\n", 3779 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3780 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3781 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n", 3782 + "Integer[0, 0, 2, 3, 1, 3, 3, 0, 8, 0, 10]: 11\n" 3783 + ] 3784 + } 3785 + ], 3786 + "source": [ 3787 + "for lst in costas_5x5\n", 3788 + " dfs(seq(lst)) |> l -> println(\"$l: $(length(l))\")\n", 3789 + "end" 3790 + ] 3791 + }, 3792 + { 3793 + "cell_type": "code", 3794 + "execution_count": 17, 3795 + "id": "70c019a2-b9f2-4b1c-83de-54ef7424bad0", 3796 + "metadata": {}, 3797 + "outputs": [ 3798 + { 3799 + "data": { 3800 + "text/plain": [ 3801 + "590105" 3802 + ] 3803 + }, 3804 + "execution_count": 17, 3805 + "metadata": {}, 3806 + "output_type": "execute_result" 3807 + } 3808 + ], 3809 + "source": [ 3810 + "a = \"#!/usr/bin/env sh\"\n", 3811 + "fname = \"foobar.jmd\"\n", 3812 + "dirpath = \"/tmp\"\n", 3813 + "fpath = joinpath(dirpath, fname)\n", 3814 + "\n", 3815 + "for lst in costas_13x13\n", 3816 + " a *= \"echo \\\"\"\n", 3817 + " for e in lst[1:12]\n", 3818 + " a *= \"$e \"\n", 3819 + " end\n", 3820 + " a *= \"$(last(lst))\\\" | ./main\\n\"\n", 3821 + "end\n", 3822 + "\n", 3823 + "\n", 3824 + "open(fpath, \"w\") do file\n", 3825 + " write(file, a)\n", 3826 + "end\n" 3827 + ] 3828 + }, 3829 + { 3830 + "cell_type": "code", 3831 + "execution_count": 12, 3832 + "id": "84fca448-b604-4c5a-9690-f2f1db5cb2e1", 3833 + "metadata": {}, 3834 + "outputs": [ 3835 + { 3836 + "data": { 3837 + "text/plain": [ 3838 + "3-element Vector{Int64}:\n", 3839 + " 2\n", 3840 + " 3\n", 3841 + " 4" 3842 + ] 3843 + }, 3844 + "execution_count": 12, 3845 + "metadata": {}, 3846 + "output_type": "execute_result" 3847 + } 3848 + ], 3849 + "source": [ 3850 + "lst = [1,2,3,4,5]\n", 3851 + "lst[2:4]" 3852 + ] 3853 + }, 3854 + { 3855 + "cell_type": "code", 3856 + "execution_count": 1, 3857 + "id": "5f460720-57f0-4673-909e-fdcc4840c6bc", 3858 + "metadata": {}, 3859 + "outputs": [ 3860 + { 3861 + "name": "stderr", 3862 + "output_type": "stream", 3863 + "text": [ 3864 + "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", 3865 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Project.toml`\n", 3866 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Manifest.toml`\n", 3867 + "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", 3868 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Project.toml`\n", 3869 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Manifest.toml`\n", 3870 + "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", 3871 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Project.toml`\n", 3872 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Manifest.toml`\n", 3873 + "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", 3874 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Project.toml`\n", 3875 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Manifest.toml`\n", 3876 + "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n", 3877 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Project.toml`\n", 3878 + "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.10/Manifest.toml`\n" 3879 + ] 3880 + }, 3881 + { 3882 + "name": "stdout", 3883 + "output_type": "stream", 3884 + "text": [ 3885 + "inputs has 17 many elements\n", 3886 + "Any[Any[(4, 2, 5)], Any[(2, 3, 5), (3, 5, 2), (5, 3, 2)], Any[(3, 2, 4), (4, 2, 3)], Any[(4, 5, 3), (5, 3, 4)], Any[(1, 5, 4), (5, 1, 4), (5, 4, 1)], Any[(1, 5, 3), (3, 1, 5)], Any[(1, 3, 4), (3, 4, 1), (4, 1, 3)], Any[(2, 5, 4), (4, 5, 2), (5, 2, 4)], Any[(4, 5, 1)], Any[(2, 1, 5)], Any[(1, 4, 2), (2, 1, 4), (4, 1, 2)], Any[(2, 5, 3), (3, 2, 5), (5, 3, 2)], Any[(3, 5, 1), (5, 1, 3)], Any[(1, 2, 5), (1, 5, 2), (5, 1, 2)], Any[(1, 3, 2), (2, 1, 3)], Any[(2, 4, 3), (3, 4, 2)], Any[(1, 3, 4), (3, 1, 4), (4, 3, 1)]]\n" 3887 + ] 3888 + }, 3889 + { 3890 + "data": { 3891 + "image/svg+xml": [ 3892 + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", 3893 + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n", 3894 + " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n", 3895 + "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n", 3896 + " width=\"180mm\" height=\"25mm\"\n", 3897 + " viewBox=\"0 0 19 1\" preserveAspectRatio=\"none\"\n", 3898 + " shape-rendering=\"crispEdges\" stroke=\"none\">\n", 3899 + "<rect width=\".89\" height=\".96\" x=\"0\" y=\"0\" fill=\"#FFA500\" />\n", 3900 + "<rect width=\".89\" height=\".96\" x=\"1\" y=\"0\" fill=\"#F19C0E\" />\n", 3901 + "<rect width=\".89\" height=\".96\" x=\"2\" y=\"0\" fill=\"#E3931C\" />\n", 3902 + "<rect width=\".89\" height=\".96\" x=\"3\" y=\"0\" fill=\"#D48A2B\" />\n", 3903 + "<rect width=\".89\" height=\".96\" x=\"4\" y=\"0\" fill=\"#C68039\" />\n", 3904 + "<rect width=\".89\" height=\".96\" x=\"5\" y=\"0\" fill=\"#B87747\" />\n", 3905 + "<rect width=\".89\" height=\".96\" x=\"6\" y=\"0\" fill=\"#AA6E55\" />\n", 3906 + "<rect width=\".89\" height=\".96\" x=\"7\" y=\"0\" fill=\"#9C6563\" />\n", 3907 + "<rect width=\".89\" height=\".96\" x=\"8\" y=\"0\" fill=\"#8E5C71\" />\n", 3908 + "<rect width=\".89\" height=\".96\" x=\"9\" y=\"0\" fill=\"#805280\" />\n", 3909 + "<rect width=\".89\" height=\".96\" x=\"10\" y=\"0\" fill=\"#71498E\" />\n", 3910 + "<rect width=\".89\" height=\".96\" x=\"11\" y=\"0\" fill=\"#63409C\" />\n", 3911 + "<rect width=\".89\" height=\".96\" x=\"12\" y=\"0\" fill=\"#5537AA\" />\n", 3912 + "<rect width=\".89\" height=\".96\" x=\"13\" y=\"0\" fill=\"#472EB8\" />\n", 3913 + "<rect width=\".89\" height=\".96\" x=\"14\" y=\"0\" fill=\"#3925C6\" />\n", 3914 + "<rect width=\".89\" height=\".96\" x=\"15\" y=\"0\" fill=\"#2A1BD5\" />\n", 3915 + "<rect width=\".89\" height=\".96\" x=\"16\" y=\"0\" fill=\"#1C12E3\" />\n", 3916 + "<rect width=\".89\" height=\".96\" x=\"17\" y=\"0\" fill=\"#0E09F1\" />\n", 3917 + "<rect width=\".89\" height=\".96\" x=\"18\" y=\"0\" fill=\"#0000FF\" />\n", 3918 + "</svg>" 3919 + ], 3920 + "text/plain": [ 3921 + "ColorPalette(ColorSchemes.ColorScheme{Vector{RGB{Float64}}, String, String}(RGB{Float64}[RGB(1.0, 0.6470588235294118, 0.0), RGB(0.9444444444444444, 0.6111111111111112, 0.05555555555555558), RGB(0.8888888888888888, 0.5751633986928104, 0.11111111111111116), RGB(0.8333333333333333, 0.5392156862745098, 0.16666666666666674), RGB(0.7777777777777777, 0.5032679738562091, 0.22222222222222232), RGB(0.7222222222222223, 0.46732026143790856, 0.2777777777777777), RGB(0.6666666666666667, 0.4313725490196079, 0.33333333333333326), RGB(0.6111111111111112, 0.39542483660130723, 0.38888888888888884), RGB(0.5555555555555556, 0.3594771241830066, 0.4444444444444444), RGB(0.5, 0.3235294117647059, 0.5), RGB(0.4444444444444444, 0.2875816993464052, 0.5555555555555556), RGB(0.38888888888888884, 0.25163398692810457, 0.6111111111111112), RGB(0.3333333333333335, 0.21568627450980402, 0.6666666666666665), RGB(0.2777777777777777, 0.1797385620915032, 0.7222222222222223), RGB(0.22222222222222232, 0.1437908496732027, 0.7777777777777777), RGB(0.16666666666666652, 0.10784313725490187, 0.8333333333333335), RGB(0.11111111111111116, 0.07189542483660134, 0.8888888888888888), RGB(0.05555555555555558, 0.03594771241830067, 0.9444444444444444), RGB(0.0, 0.0, 1.0)], \"\", \"\"))" 3922 + ] 3923 + }, 3924 + "execution_count": 1, 3925 + "metadata": {}, 3926 + "output_type": "execute_result" 3927 + } 3928 + ], 3929 + "source": [ 3930 + "import Pkg\n", 3931 + "import Serialization\n", 3932 + "Pkg.add(\"Combinatorics\")\n", 3933 + "Pkg.add(\"Primes\")\n", 3934 + "Pkg.add(\"BenchmarkTools\")\n", 3935 + "Pkg.add(\"Transducers\")\n", 3936 + "Pkg.add(\"Plots\")\n", 3937 + "using Combinatorics\n", 3938 + "using Primes\n", 3939 + "using BenchmarkTools\n", 3940 + "using Transducers\n", 3941 + "using Plots\n", 3942 + "\n", 3943 + "include(\"header.jl\")\n", 3944 + "\n", 3945 + "import Base.Iterators\n", 3946 + "\n", 3947 + "loadvar(file_path::String) = Serialization.deserialize(file_path)\n", 3948 + "\n", 3949 + "costas_10x10 = loadvar(\"costas_10x10.dat\")\n", 3950 + "costas_5x5 = loadvar(\"costas_5x5.dat\")\n", 3951 + "\n", 3952 + "kw = (proj_type = :ortho, legend = false, aspect_ratio = :equal, xlimits = (0,10), ylimits = (0,10), zlimits = (0,10))\n" 3953 + ] 3954 + }, 3955 + { 3956 + "cell_type": "code", 3957 + "execution_count": 19, 3958 + "id": "2c6ce2ce-e746-4629-a5d8-d0c78cd6b7b5", 3959 + "metadata": {}, 3960 + "outputs": [ 3961 + { 3962 + "data": { 3963 + "text/plain": [ 3964 + "116-element Vector{Vector{Int64}}:\n", 3965 + " [1, 2, 5, 4, 6, 3]\n", 3966 + " [1, 2, 6, 4, 3, 5]\n", 3967 + " [1, 3, 2, 5, 6, 4]\n", 3968 + " [1, 3, 2, 6, 4, 5]\n", 3969 + " [1, 3, 6, 4, 5, 2]\n", 3970 + " [1, 4, 3, 5, 6, 2]\n", 3971 + " [1, 4, 5, 3, 2, 6]\n", 3972 + " [1, 4, 6, 5, 2, 3]\n", 3973 + " [1, 5, 3, 4, 6, 2]\n", 3974 + " [1, 5, 3, 6, 2, 4]\n", 3975 + " [1, 5, 4, 2, 3, 6]\n", 3976 + " [1, 5, 4, 6, 2, 3]\n", 3977 + " [1, 5, 6, 2, 4, 3]\n", 3978 + " ⋮\n", 3979 + " [6, 2, 3, 1, 5, 4]\n", 3980 + " [6, 2, 3, 5, 4, 1]\n", 3981 + " [6, 2, 4, 1, 5, 3]\n", 3982 + " [6, 2, 4, 3, 1, 5]\n", 3983 + " [6, 3, 1, 2, 5, 4]\n", 3984 + " [6, 3, 2, 4, 5, 1]\n", 3985 + " [6, 3, 4, 2, 1, 5]\n", 3986 + " [6, 4, 1, 3, 2, 5]\n", 3987 + " [6, 4, 5, 1, 3, 2]\n", 3988 + " [6, 4, 5, 2, 1, 3]\n", 3989 + " [6, 5, 1, 3, 4, 2]\n", 3990 + " [6, 5, 2, 3, 1, 4]" 3991 + ] 3992 + }, 3993 + "execution_count": 19, 3994 + "metadata": {}, 3995 + "output_type": "execute_result" 3996 + } 3997 + ], 3998 + "source": [ 3999 + "costas_6x6 |> sort" 4000 + ] 4001 + }, 4002 + { 4003 + "cell_type": "code", 4004 + "execution_count": 34, 4005 + "id": "c2b846d7-b93a-4e34-82bc-c42511a7536e", 4006 + "metadata": {}, 4007 + "outputs": [ 4008 + { 4009 + "name": "stdout", 4010 + "output_type": "stream", 4011 + "text": [ 4012 + "inputs has 0 many elements\n", 4013 + "Any[]\n" 4014 + ] 4015 + }, 4016 + { 4017 + "data": { 4018 + "image/svg+xml": [ 4019 + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", 4020 + "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n", 4021 + " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n", 4022 + "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"\n", 4023 + " width=\"25mm\" height=\"25mm\"\n", 4024 + " viewBox=\"0 0 1 1\" preserveAspectRatio=\"none\"\n", 4025 + " shape-rendering=\"crispEdges\" stroke=\"none\">\n", 4026 + "<rect width=\".96\" height=\".96\" x=\"0\" y=\"0\" fill=\"#FF0000\" />\n", 4027 + "</svg>" 4028 + ], 4029 + "text/plain": [ 4030 + "ColorPalette(ColorSchemes.ColorScheme{Vector{RGB{Float64}}, String, String}(RGB{Float64}[RGB(1.0, 0.0, 0.0)], \"\", \"\"))" 4031 + ] 4032 + }, 4033 + "execution_count": 34, 4034 + "metadata": {}, 4035 + "output_type": "execute_result" 4036 + } 4037 + ], 4038 + "source": [ 4039 + "\n", 4040 + "size = 4\n", 4041 + "lists = costas_4x4\n", 4042 + "last = lists[1][1:size - 3]\n", 4043 + "inputs = []\n", 4044 + "arr = []\n", 4045 + "for l in lists\n", 4046 + " if last != l[1:size - 3]\n", 4047 + " push!(inputs, arr)\n", 4048 + " global last = l[1:size - 3]\n", 4049 + " global arr = []\n", 4050 + " end\n", 4051 + " push!(arr, (l[size - 2], l[size - 1], l[size]))\n", 4052 + "end\n", 4053 + "\n", 4054 + "println(\"inputs has $(length(inputs)) many elements\")\n", 4055 + "println(inputs)\n", 4056 + "\n", 4057 + "limit = length(inputs)\n", 4058 + "colors = palette([:red, :orange, :yellow, :green, :blue, :indigo, :violet], limit)" 4059 + ] 4060 + }, 4061 + { 4062 + "cell_type": "code", 4063 + "execution_count": 30, 4064 + "id": "a4b94713-6485-4bfb-800d-a42368b608a7", 4065 + "metadata": {}, 4066 + "outputs": [ 4067 + { 4068 + "data": { 4069 + "text/plain": [ 4070 + "Tuple{Any, Any}[]" 4071 + ] 4072 + }, 4073 + "execution_count": 30, 4074 + "metadata": {}, 4075 + "output_type": "execute_result" 4076 + } 4077 + ], 4078 + "source": [ 4079 + "idx = 0\n", 4080 + "inputs = inputs .|> l -> begin\n", 4081 + " global idx += 1\n", 4082 + " (l, idx)\n", 4083 + "end" 4084 + ] 4085 + }, 4086 + { 4087 + "cell_type": "code", 4088 + "execution_count": null, 4089 + "id": "ed8f9984-89a0-4368-851a-f4749b2a657b", 4090 + "metadata": {}, 4091 + "outputs": [], 4092 + "source": [ 4093 + "@gif for i in 0:360\n", 4094 + " for pt in costas_3x3\n", 4095 + " x = pt[1]\n", 4096 + " y = pt[2]\n", 4097 + " z = pt[3]\n", 4098 + " scatter!(x, y, z; markercolor = colors[1], camera = (i, round(atand(1 / √2); digits = 3)), kw...)\n", 4099 + " end\n", 4100 + "end" 4101 + ] 4102 + }, 4103 + { 4104 + "cell_type": "code", 4105 + "execution_count": 32, 4106 + "id": "8508e758-0f4b-4271-a6de-6b75d06b0f48", 4107 + "metadata": {}, 4108 + "outputs": [ 4109 + { 4110 + "data": { 4111 + "text/plain": [ 4112 + "4-element Vector{Vector{Int64}}:\n", 4113 + " [1, 3, 2]\n", 4114 + " [2, 1, 3]\n", 4115 + " [2, 3, 1]\n", 4116 + " [3, 1, 2]" 4117 + ] 4118 + }, 4119 + "execution_count": 32, 4120 + "metadata": {}, 4121 + "output_type": "execute_result" 4122 + } 4123 + ], 4124 + "source": [ 4125 + "costas_3x3" 4126 + ] 4127 + }, 4128 + { 4129 + "cell_type": "code", 4130 + "execution_count": null, 4131 + "id": "e950515a-a3c4-4108-9ad2-b92ed7714cc0", 4132 + "metadata": {}, 4133 + "outputs": [], 4134 + "source": [] 4135 + } 4136 + ], 4137 + "metadata": { 4138 + "kernelspec": { 4139 + "display_name": "Julia 1.10.4", 4140 + "language": "julia", 4141 + "name": "julia-1.10" 4142 + }, 4143 + "language_info": { 4144 + "file_extension": ".jl", 4145 + "mimetype": "application/julia", 4146 + "name": "julia", 4147 + "version": "1.10.4" 4148 + } 4149 + }, 4150 + "nbformat": 4, 4151 + "nbformat_minor": 5 4152 + }
+399
src/jupyter/.ipynb_checkpoints/processing-checkpoint.ipynb
··· 1 + { 2 + "cells": [ 3 + { 4 + "cell_type": "code", 5 + "execution_count": 1, 6 + "id": "078f9d4f-ee7f-46b1-be3b-7f2bb1197d00", 7 + "metadata": {}, 8 + "outputs": [], 9 + "source": [ 10 + "from header import *\n", 11 + "from algs import *" 12 + ] 13 + }, 14 + { 15 + "cell_type": "code", 16 + "execution_count": 5, 17 + "id": "2ed6be02-3a12-4517-b7e5-176e70fc8fdc", 18 + "metadata": {}, 19 + "outputs": [], 20 + "source": [ 21 + "c_2x2 = load_file(\"results/costas_2x2.txt\")\n", 22 + "c_3x3 = load_file(\"results/costas_3x3.txt\")\n", 23 + "c_4x4 = load_file(\"results/costas_4x4.txt\")\n", 24 + "c_5x5 = load_file(\"results/costas_5x5.txt\")\n", 25 + "c_6x6 = load_file(\"results/costas_6x6.txt\")\n", 26 + "c_7x7 = load_file(\"results/costas_7x7.txt\")\n", 27 + "# c_8x8 = load_file(\"results/costas_8x8.txt\")\n", 28 + "# c_9x9 = load_file(\"results/costas_9x9.txt\")\n", 29 + "# c_10x10 = load_file(\"results/min/costas_10x10.min.txt\")\n", 30 + "# c_11x11 = load_file(\"results/min/costas_11x11.min.txt\")\n", 31 + "# c_12x12 = load_file(\"results/min/costas_12x12.min.txt\")\n", 32 + "c_nxns = [c_2x2,c_3x3,c_4x4,c_5x5,c_6x6,c_7x7]" 33 + ] 34 + }, 35 + { 36 + "cell_type": "code", 37 + "execution_count": 23, 38 + "id": "0584959d-1b91-4037-a599-48622b9f97ee", 39 + "metadata": {}, 40 + "outputs": [ 41 + { 42 + "name": "stdout", 43 + "output_type": "stream", 44 + "text": [ 45 + "2\n", 46 + "4\n", 47 + "12\n", 48 + "44\n", 49 + "176\n", 50 + "788\n" 51 + ] 52 + } 53 + ], 54 + "source": [ 55 + "for c in c_nxns:\n", 56 + " print(len(c))" 57 + ] 58 + }, 59 + { 60 + "cell_type": "code", 61 + "execution_count": 4, 62 + "id": "e7b26414-fcb6-48d3-a32b-56038dd54616", 63 + "metadata": {}, 64 + "outputs": [ 65 + { 66 + "name": "stdout", 67 + "output_type": "stream", 68 + "text": [ 69 + "2 2\n", 70 + "3 4\n", 71 + "4 8\n", 72 + "5 20\n", 73 + "6 50\n", 74 + "7 130\n", 75 + "8 362\n", 76 + "9 1104\n", 77 + "10 3614\n" 78 + ] 79 + } 80 + ], 81 + "source": [ 82 + "prev = set([(1,2), (2,1)])\n", 83 + "counts2 = []\n", 84 + "for i in range(2, 11):\n", 85 + " print(i, len(prev))\n", 86 + " counts2.append(prev)\n", 87 + " nxt = [build_all_naive(lst, i + 1) for lst in prev]\n", 88 + " prev = set()\n", 89 + " for lsts in nxt:\n", 90 + " for lst in lsts:\n", 91 + " prev.add(tuple(lst))\n" 92 + ] 93 + }, 94 + { 95 + "cell_type": "code", 96 + "execution_count": 11, 97 + "id": "4aba47ce-3bab-4d7e-bcf0-160ad1fc49d0", 98 + "metadata": {}, 99 + "outputs": [ 100 + { 101 + "name": "stdout", 102 + "output_type": "stream", 103 + "text": [ 104 + "0 set()\n", 105 + "0 set()\n", 106 + "4 {(3, 4, 2, 1), (1, 4, 2, 3), (1, 2, 4, 3), (3, 2, 4, 1)}\n", 107 + "24 {(1, 5, 4, 2, 3), (3, 1, 4, 5, 2), (3, 4, 2, 1, 5), (5, 1, 2, 4, 3), (1, 4, 3, 5, 2), (2, 5, 3, 4, 1), (5, 3, 2, 4, 1), (1, 5, 3, 2, 4), (2, 3, 5, 4, 1), (3, 5, 2, 1, 4), (3, 2, 4, 5, 1), (3, 5, 1, 4, 2), (4, 1, 2, 5, 3), (2, 5, 4, 1, 3), (4, 2, 3, 5, 1), (5, 1, 4, 2, 3), (1, 4, 5, 3, 2), (3, 5, 4, 1, 2), (2, 4, 1, 5, 3), (3, 4, 2, 5, 1), (3, 2, 4, 1, 5), (1, 4, 2, 3, 5), (1, 5, 2, 4, 3), (2, 1, 4, 5, 3)}\n" 108 + ] 109 + } 110 + ], 111 + "source": [ 112 + "for calc, built in list(zip(c_nxns, counts2))[:4]:\n", 113 + " diffs = calc - built\n", 114 + " print(len(diffs), diffs)" 115 + ] 116 + }, 117 + { 118 + "cell_type": "code", 119 + "execution_count": 15, 120 + "id": "b7fe429a-d95b-457f-9f74-f2bf547e00a5", 121 + "metadata": {}, 122 + "outputs": [ 123 + { 124 + "data": { 125 + "text/plain": [ 126 + "[[1, 4, 2, 3], [1, 2, 4, 3]]" 127 + ] 128 + }, 129 + "execution_count": 15, 130 + "metadata": {}, 131 + "output_type": "execute_result" 132 + } 133 + ], 134 + "source": [ 135 + "build_all_naive([1,2,3], 4)" 136 + ] 137 + }, 138 + { 139 + "cell_type": "code", 140 + "execution_count": 14, 141 + "id": "7be18ac1-4eda-4e8a-b719-d92ac551c2bb", 142 + "metadata": {}, 143 + "outputs": [], 144 + "source": [ 145 + "fours = counts2[2]" 146 + ] 147 + }, 148 + { 149 + "cell_type": "code", 150 + "execution_count": 16, 151 + "id": "8fc81260-b4be-417b-ad6d-2f3ff452f41d", 152 + "metadata": {}, 153 + "outputs": [], 154 + "source": [ 155 + "fours |= {(3,4,2,1),(3,2,4,1),(1,4,2,3),(1,2,4,3)}" 156 + ] 157 + }, 158 + { 159 + "cell_type": "code", 160 + "execution_count": 17, 161 + "id": "6ec26162-7d61-4adb-9468-c68285469943", 162 + "metadata": {}, 163 + "outputs": [ 164 + { 165 + "data": { 166 + "text/plain": [ 167 + "{(1, 2, 4, 3),\n", 168 + " (1, 3, 4, 2),\n", 169 + " (1, 4, 2, 3),\n", 170 + " (2, 1, 3, 4),\n", 171 + " (2, 3, 1, 4),\n", 172 + " (2, 4, 3, 1),\n", 173 + " (3, 1, 2, 4),\n", 174 + " (3, 2, 4, 1),\n", 175 + " (3, 4, 2, 1),\n", 176 + " (4, 1, 3, 2),\n", 177 + " (4, 2, 1, 3),\n", 178 + " (4, 3, 1, 2)}" 179 + ] 180 + }, 181 + "execution_count": 17, 182 + "metadata": {}, 183 + "output_type": "execute_result" 184 + } 185 + ], 186 + "source": [ 187 + "fours" 188 + ] 189 + }, 190 + { 191 + "cell_type": "code", 192 + "execution_count": 18, 193 + "id": "379d075a-e20b-47ca-9302-ebe09e465927", 194 + "metadata": {}, 195 + "outputs": [], 196 + "source": [ 197 + "nxt = [build_all_naive(lst, 5) for lst in fours]" 198 + ] 199 + }, 200 + { 201 + "cell_type": "code", 202 + "execution_count": 21, 203 + "id": "b60186ac-3842-49c9-bb21-dfb668a57781", 204 + "metadata": {}, 205 + "outputs": [], 206 + "source": [ 207 + "fives = set()\n", 208 + "for lsts in nxt:\n", 209 + " for lst in lsts:\n", 210 + " fives.add(tuple(lst))" 211 + ] 212 + }, 213 + { 214 + "cell_type": "code", 215 + "execution_count": 22, 216 + "id": "797a0c23-2df7-44b1-aa74-8fbd2b9ccb3c", 217 + "metadata": {}, 218 + "outputs": [ 219 + { 220 + "data": { 221 + "text/plain": [ 222 + "30" 223 + ] 224 + }, 225 + "execution_count": 22, 226 + "metadata": {}, 227 + "output_type": "execute_result" 228 + } 229 + ], 230 + "source": [ 231 + "len(fives)" 232 + ] 233 + }, 234 + { 235 + "cell_type": "code", 236 + "execution_count": 27, 237 + "id": "378e0d4a-1000-4e56-b2f4-856e05690917", 238 + "metadata": {}, 239 + "outputs": [], 240 + "source": [ 241 + "leftovers = c_nxns[3] - fives" 242 + ] 243 + }, 244 + { 245 + "cell_type": "code", 246 + "execution_count": 37, 247 + "id": "0ea7a681-5d44-4cb5-a91b-e4d20ffd6095", 248 + "metadata": {}, 249 + "outputs": [ 250 + { 251 + "name": "stdout", 252 + "output_type": "stream", 253 + "text": [ 254 + "14\n" 255 + ] 256 + }, 257 + { 258 + "data": { 259 + "text/plain": [ 260 + "{(1, 4, 3, 5, 2),\n", 261 + " (1, 4, 5, 3, 2),\n", 262 + " (1, 5, 3, 2, 4),\n", 263 + " (2, 1, 4, 5, 3),\n", 264 + " (2, 3, 5, 4, 1),\n", 265 + " (2, 4, 1, 5, 3),\n", 266 + " (2, 5, 3, 4, 1),\n", 267 + " (2, 5, 4, 1, 3),\n", 268 + " (3, 1, 4, 5, 2),\n", 269 + " (3, 5, 1, 4, 2),\n", 270 + " (3, 5, 2, 1, 4),\n", 271 + " (3, 5, 4, 1, 2),\n", 272 + " (4, 1, 2, 5, 3),\n", 273 + " (4, 2, 3, 5, 1)}" 274 + ] 275 + }, 276 + "execution_count": 37, 277 + "metadata": {}, 278 + "output_type": "execute_result" 279 + } 280 + ], 281 + "source": [ 282 + "print(len(leftovers))\n", 283 + "leftovers" 284 + ] 285 + }, 286 + { 287 + "cell_type": "code", 288 + "execution_count": 35, 289 + "id": "6b618d96-7e6c-4ba1-ab59-c008b0266683", 290 + "metadata": {}, 291 + "outputs": [], 292 + "source": [ 293 + "leftovers_four = set()\n", 294 + "for lst in leftovers:\n", 295 + " lst = list(filter(lambda x: x != 5, list(lst)))\n", 296 + " leftovers_four.add(tuple(lst))" 297 + ] 298 + }, 299 + { 300 + "cell_type": "code", 301 + "execution_count": 38, 302 + "id": "f53549d3-56e1-4ae8-ae17-2c8ea4cea3e8", 303 + "metadata": {}, 304 + "outputs": [ 305 + { 306 + "name": "stdout", 307 + "output_type": "stream", 308 + "text": [ 309 + "10\n" 310 + ] 311 + }, 312 + { 313 + "data": { 314 + "text/plain": [ 315 + "{(1, 3, 2, 4),\n", 316 + " (1, 4, 3, 2),\n", 317 + " (2, 1, 4, 3),\n", 318 + " (2, 3, 4, 1),\n", 319 + " (2, 4, 1, 3),\n", 320 + " (3, 1, 4, 2),\n", 321 + " (3, 2, 1, 4),\n", 322 + " (3, 4, 1, 2),\n", 323 + " (4, 1, 2, 3),\n", 324 + " (4, 2, 3, 1)}" 325 + ] 326 + }, 327 + "execution_count": 38, 328 + "metadata": {}, 329 + "output_type": "execute_result" 330 + } 331 + ], 332 + "source": [ 333 + "print(len(leftovers_four))\n", 334 + "leftovers_four" 335 + ] 336 + }, 337 + { 338 + "cell_type": "code", 339 + "execution_count": 1, 340 + "id": "e725f79c-10f4-454a-bf19-7fc6128f6991", 341 + "metadata": {}, 342 + "outputs": [ 343 + { 344 + "ename": "NameError", 345 + "evalue": "name 'dataclass' is not defined", 346 + "output_type": "error", 347 + "traceback": [ 348 + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 349 + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", 350 + "Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;129m@dataclass\u001b[39m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mclass\u001b[39;00m \u001b[38;5;21;01mMaybe\u001b[39;00m:\n\u001b[1;32m 3\u001b[0m x: \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mtyping.Any\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 4\u001b[0m empty: \u001b[38;5;28mbool\u001b[39m\n", 351 + "\u001b[0;31mNameError\u001b[0m: name 'dataclass' is not defined" 352 + ] 353 + } 354 + ], 355 + "source": [ 356 + "class Maybe:\n", 357 + " empty = True\n", 358 + " def __init__(self, x) -> Maybe:\n", 359 + " \n", 360 + " def __sub__(self, other: Maybe) -> Maybe:\n", 361 + " if self.empty:\n", 362 + " return None\n", 363 + " elif other.empty:\n", 364 + " return None\n", 365 + " else:\n", 366 + " return self.x - other.x" 367 + ] 368 + }, 369 + { 370 + "cell_type": "code", 371 + "execution_count": null, 372 + "id": "e4ecb1bc-bf3e-4637-920b-eb5bd16d4dbb", 373 + "metadata": {}, 374 + "outputs": [], 375 + "source": [] 376 + } 377 + ], 378 + "metadata": { 379 + "kernelspec": { 380 + "display_name": "Python 3 (ipykernel)", 381 + "language": "python", 382 + "name": "python3" 383 + }, 384 + "language_info": { 385 + "codemirror_mode": { 386 + "name": "ipython", 387 + "version": 3 388 + }, 389 + "file_extension": ".py", 390 + "mimetype": "text/x-python", 391 + "name": "python", 392 + "nbconvert_exporter": "python", 393 + "pygments_lexer": "ipython3", 394 + "version": "3.12.4" 395 + } 396 + }, 397 + "nbformat": 4, 398 + "nbformat_minor": 5 399 + }
+6
src/jupyter/.ipynb_checkpoints/sat-checkpoint.ipynb
··· 1 + { 2 + "cells": [], 3 + "metadata": {}, 4 + "nbformat": 4, 5 + "nbformat_minor": 5 6 + }
+42
src/jupyter/.ipynb_checkpoints/search-checkpoint.jl
··· 1 + import Pkg; 2 + using Serialization 3 + Pkg.add("Transducers") 4 + using Transducers 5 + Pkg.add("Primes") 6 + using Primes 7 + Pkg.add("Combinatorics") 8 + using Combinatorics 9 + 10 + function iscostashelper2(lst::Vector{T}, n::Integer)::Bool where T 11 + all(begin 12 + seen::Vector{Bool} = zeros(Bool, 2 * n) 13 + all(begin 14 + result = lst[i+k] - lst[i] + n 15 + prev = seen[result] 16 + seen[result] = true 17 + !prev 18 + end for i ∈ 1:(n - k)) 19 + end for k ∈ 1:n) 20 + end 21 + 22 + # Check if a sequence is a Costas sequence 23 + function iscostas(lst::Vector{T})::Bool where T 24 + length(unique(lst)) == length(lst) && iscostashelper2(lst, length(lst)) 25 + end 26 + 27 + const START = 14 28 + const LIMIT = 16 29 + 30 + Threads.@threads for n in (START + 1):LIMIT 31 + out = 1:n |> permutations |> Filter(iscostas) |> tcollect 32 + file_path = "costas_$(n)x$n.dat" 33 + serialize(file_path, out) 34 + println("$file_path has $(length(out)) arrays.") 35 + end 36 + 37 + Threads.@threads for n in START:LIMIT 38 + out = 2:n |> permutations |> Filter(iscostas) |> tcollect 39 + file_path = "costas_$(n)x$(n + 1).dat" 40 + serialize(file_path, out) 41 + println("$file_path has $(length(out)) arrays.") 42 + end